From a22923dbe457ae1d37ee2080b0341bde59a2ecca Mon Sep 17 00:00:00 2001 From: Ziga Luksic Date: Fri, 20 Jan 2023 09:18:47 +0100 Subject: [PATCH 1/2] add delete instructions for bbox and timestamps --- core/eolearn/core/eodata.py | 2 ++ core/eolearn/tests/test_eodata.py | 1 + 2 files changed, 3 insertions(+) diff --git a/core/eolearn/core/eodata.py b/core/eolearn/core/eodata.py index a1ce4d697..8f132c6a3 100644 --- a/core/eolearn/core/eodata.py +++ b/core/eolearn/core/eodata.py @@ -359,6 +359,8 @@ def __delitem__(self, feature: Tuple[FeatureType, str]) -> None: """ self._check_tuple_key(feature) feature_type, feature_name = feature + if feature_type in [FeatureType.BBOX, FeatureType.TIMESTAMP]: + self.reset_feature_type(feature_type) del self[feature_type][feature_name] @staticmethod diff --git a/core/eolearn/tests/test_eodata.py b/core/eolearn/tests/test_eodata.py index fd95f37ea..74b64df70 100644 --- a/core/eolearn/tests/test_eodata.py +++ b/core/eolearn/tests/test_eodata.py @@ -163,6 +163,7 @@ def test_simplified_feature_operations() -> None: (FeatureType.MASK, "ones"), (FeatureType.MASK_TIMELESS, "threes"), (FeatureType.META_INFO, "beep"), + (FeatureType.BBOX), ], ) def test_delete_existing_feature(feature: Tuple[FeatureType, str], mini_eopatch: EOPatch) -> None: From 670c63024d9e586e147a5dd9f1f0d5576906b962 Mon Sep 17 00:00:00 2001 From: Ziga Luksic Date: Fri, 20 Jan 2023 09:31:14 +0100 Subject: [PATCH 2/2] fix code-flow issues and update types --- core/eolearn/core/eodata.py | 7 ++++--- core/eolearn/tests/test_eodata.py | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/core/eolearn/core/eodata.py b/core/eolearn/core/eodata.py index 8f132c6a3..19dd64ea5 100644 --- a/core/eolearn/core/eodata.py +++ b/core/eolearn/core/eodata.py @@ -352,7 +352,7 @@ def __setitem__( return self.__setattr__(FeatureType(feature_type).value, value, feature_name=feature_name) - def __delitem__(self, feature: Tuple[FeatureType, str]) -> None: + def __delitem__(self, feature: FeatureSpec) -> None: """Deletes the selected feature. :param feature: EOPatch feature @@ -361,12 +361,13 @@ def __delitem__(self, feature: Tuple[FeatureType, str]) -> None: feature_type, feature_name = feature if feature_type in [FeatureType.BBOX, FeatureType.TIMESTAMP]: self.reset_feature_type(feature_type) - del self[feature_type][feature_name] + else: + del self[feature_type][feature_name] @staticmethod def _check_tuple_key(key: tuple) -> None: """A helper function that checks a tuple, which should hold (feature_type, feature_name).""" - if len(key) != 2: + if not isinstance(key, (tuple, list)) or len(key) != 2: raise ValueError(f"Given element should be a tuple of (feature_type, feature_name), but {key} found.") def __eq__(self, other: object) -> bool: diff --git a/core/eolearn/tests/test_eodata.py b/core/eolearn/tests/test_eodata.py index 74b64df70..042efa902 100644 --- a/core/eolearn/tests/test_eodata.py +++ b/core/eolearn/tests/test_eodata.py @@ -163,10 +163,10 @@ def test_simplified_feature_operations() -> None: (FeatureType.MASK, "ones"), (FeatureType.MASK_TIMELESS, "threes"), (FeatureType.META_INFO, "beep"), - (FeatureType.BBOX), + (FeatureType.BBOX, None), ], ) -def test_delete_existing_feature(feature: Tuple[FeatureType, str], mini_eopatch: EOPatch) -> None: +def test_delete_existing_feature(feature: FeatureSpec, mini_eopatch: EOPatch) -> None: old = mini_eopatch.copy(deep=True) del mini_eopatch[feature] @@ -174,6 +174,7 @@ def test_delete_existing_feature(feature: Tuple[FeatureType, str], mini_eopatch: for old_feature in old.get_features(): if old_feature != feature: + # this also works for BBox :D assert_array_equal(old[old_feature], mini_eopatch[old_feature])