Skip to content

Commit dfada66

Browse files
authored
Add delete instructions for bbox and timestamps (#545)
* add delete instructions for bbox and timestamps * fix code-flow issues and update types
1 parent d288629 commit dfada66

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

core/eolearn/core/eodata.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,19 +352,22 @@ def __setitem__(
352352

353353
return self.__setattr__(FeatureType(feature_type).value, value, feature_name=feature_name)
354354

355-
def __delitem__(self, feature: Tuple[FeatureType, str]) -> None:
355+
def __delitem__(self, feature: FeatureSpec) -> None:
356356
"""Deletes the selected feature.
357357
358358
:param feature: EOPatch feature
359359
"""
360360
self._check_tuple_key(feature)
361361
feature_type, feature_name = feature
362-
del self[feature_type][feature_name]
362+
if feature_type in [FeatureType.BBOX, FeatureType.TIMESTAMP]:
363+
self.reset_feature_type(feature_type)
364+
else:
365+
del self[feature_type][feature_name]
363366

364367
@staticmethod
365368
def _check_tuple_key(key: tuple) -> None:
366369
"""A helper function that checks a tuple, which should hold (feature_type, feature_name)."""
367-
if len(key) != 2:
370+
if not isinstance(key, (tuple, list)) or len(key) != 2:
368371
raise ValueError(f"Given element should be a tuple of (feature_type, feature_name), but {key} found.")
369372

370373
def __eq__(self, other: object) -> bool:

core/eolearn/tests/test_eodata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,18 @@ def test_simplified_feature_operations() -> None:
163163
(FeatureType.MASK, "ones"),
164164
(FeatureType.MASK_TIMELESS, "threes"),
165165
(FeatureType.META_INFO, "beep"),
166+
(FeatureType.BBOX, None),
166167
],
167168
)
168-
def test_delete_existing_feature(feature: Tuple[FeatureType, str], mini_eopatch: EOPatch) -> None:
169+
def test_delete_existing_feature(feature: FeatureSpec, mini_eopatch: EOPatch) -> None:
169170
old = mini_eopatch.copy(deep=True)
170171

171172
del mini_eopatch[feature]
172173
assert feature not in mini_eopatch
173174

174175
for old_feature in old.get_features():
175176
if old_feature != feature:
177+
# this also works for BBox :D
176178
assert_array_equal(old[old_feature], mini_eopatch[old_feature])
177179

178180

0 commit comments

Comments
 (0)