diff --git a/xarray/namedarray/core.py b/xarray/namedarray/core.py index 1bfc6fc8460..8d3ea506605 100644 --- a/xarray/namedarray/core.py +++ b/xarray/namedarray/core.py @@ -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]