Skip to content

Commit

Permalink
Issue ecmwf#470, allowing NumPy types in the sel() method.
Browse files Browse the repository at this point in the history
- Added support for NumPy scalars by checking if the item has an 'item' method and calling it when applicable.
- Converted non-scalar NumPy arrays to lists to ensure consistent handling in the selection process.
  • Loading branch information
alioacar committed Oct 3, 2024
1 parent 03952fa commit e07af4f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/earthkit/data/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ def __call__(self, x):
self.actions[k] = InSlice(v)
continue

if hasattr(v, 'item') and callable(v.item):
if not hasattr(v, 'shape') or not v.shape:
v = v.item()
else:
v = v.tolist()

if not isinstance(v, (list, tuple, set)):
v = [v]

v = set(v)


v = [item.item() if hasattr(item, 'item') and
callable(item.item) and (not hasattr(item, 'shape')
or not item.shape) else item for item in v]

v = set(v)
self.actions[k] = InList(v)

def match_element(self, element):
metadata = self.remapping(element.metadata)
return all(v(metadata(k, default=None)) for k, v in self.actions.items())
Expand Down

0 comments on commit e07af4f

Please sign in to comment.