Check if new_feature_name different from feature_name
I took into account the comments and implemented a check to see if new_feature_name is the same as feature_name. The check for whether the feature_name provided corresponds to an existing FeatureType remains.
@@ -256,22 +256,26 @@ class EOPatch:
self._check_if_dict(feature_type)
self[feature_type][feature_name] = value
- def rename_feature(self,feature_type,feature_name,new_feature_name):
+ def rename_feature(self, feature):
"""Renames the feature ``feature_name`` to ``new_feature_name`` from dictionary of ``feature_type``.
- :param feature_type: Enum of the attribute we're about to modify
+ :param feature_type: Enum of the attribute we're about to rename
:type feature_type: FeatureType
:param feature_name: Name of the feature of the attribute
:type feature_name: str
:param new_feature_name : New Name of the feature of the attribute
:type feature_name: str
"""
- LOGGER.debug("Renaming feature '%s' from attribute '%s'", feature_name, feature_type.value)
+ feature_type, feature_name, new_feature_name = self._parse_features(feature, new_names=True)
self._check_if_dict(feature_type)
+ if feature_name != new_feature_name:
if feature_name in self[feature_type]:
+ LOGGER.debug("Renaming feature '%s' from attribute '%s'", feature_name, feature_type.value)
self[feature_type][new_feature_name] = self[feature_type][feature_name]
del self[feature_type][feature_name]
+ else:
+ LOGGER.debug("Feature '%s' was not renamed because new name is identical.", feature_name, feature_type.value)
@staticmethod
def _check_if_dict(feature_type):
