Skip to content

Commit

Permalink
Add comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan committed Aug 18, 2024
1 parent d41e6b0 commit 6c04ca6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions xarray/namedarray/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,40 @@ def __len__(self) -> _IntOrUnknown:
def __bool__(self, /) -> bool:
return self._data.__bool__()

# Comparison Operators

def __eq__(self, other, /):
from xarray.namedarray._array_api import equal

return equal(self, other)

def __ge__(self, other, /):
from xarray.namedarray._array_api import greater_equal

return greater_equal(self, other)

def __gt__(self, other, /):
from xarray.namedarray._array_api import greater

return greater(self, other)

def __le__(self, other, /):
from xarray.namedarray._array_api import less_equal

return less_equal(self, other)

def __lt__(self, other, /):
from xarray.namedarray._array_api import less

return less(self, other)

def __ne__(self, other, /):
from xarray.namedarray._array_api import not_equal

return not_equal(self, other)

# Something

def __getitem__(self, key: _IndexKeyLike | NamedArray):
if isinstance(key, (int, slice, tuple)):
_data = self._data[key]
Expand Down

0 comments on commit 6c04ca6

Please sign in to comment.