Skip to content
Snippets Groups Projects

ENH: F remove value or property

Merged Florian Spreckelsen requested to merge f-remove-value-or-property into dev
All threads resolved!
Files
2
@@ -458,10 +458,10 @@ class Entity:
Do nothing if this entity does not have a property of this
``property_name`` or if the property value is different of the given
``value``. By default, the property is removed form this entity if it is
empty (i.e., value=None) after removal of the value. This behavior can
be changed by setting ``remove_if_empty_afterwards`` to ``False`` in which
case the property remains.
``value``. By default, the property is removed from this entity if it
becomes empty (i.e., value=None) through removal of the value. This
behavior can be changed by setting ``remove_if_empty_afterwards`` to
``False`` in which case the property remains.
Notes
-----
@@ -469,29 +469,34 @@ class Entity:
than once in this list, only its first occurrance is deleted (similar
to the behavior of Python's ``list.remove()``.)
If the property is already empty and a value != None is to be removed,
the property is not removed afterwards even if
``remove_if_empty_afterwards`` is set to ``True`` (the property being
empty is not an effect of calling this function).
If the property was empty (prop.value == None) before, the property is
not removed afterwards even if ``remove_if_empty_afterwards`` is set to
``True``. Rationale: the property being empty is not an effect of
calling this function.
Parameters
----------
property_name : str
Name of the property from which the ``value`` will be removed.
value
Value that is to be removed.
remove_if_empty_afterwards : bool, optional
Whether the property is to be removed from this entity if it is
Whether the property shall be removed from this entity if it is
emptied by removing the ``value``. Default is ``True``.
Returns
-------
self
This entity.
"""
if self.get_property(property_name) is None:
return self
if self.get_property(property_name).value is None:
remove_if_empty_afterwards = False
empty_afterwards = False
if isinstance(self.get_property(property_name).value, list):
if value in self.get_property(property_name).value:
Loading