Skip to content

Commit

Permalink
handle scalars
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan committed Aug 21, 2024
1 parent 5178661 commit 2e6f3da
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions xarray/namedarray/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,10 @@ def __pos__(self, /):

return positive(self)

def __add__(self, other, /):
from xarray.namedarray._array_api import add
def __add__(self, other: int | float | NamedArray, /) -> NamedArray:
from xarray.namedarray._array_api import add, asarray

return add(self, other)
return add(self, asarray(other))

def __sub__(self, other, /):
from xarray.namedarray._array_api import subtract
Expand Down Expand Up @@ -743,11 +743,10 @@ def __rshift__(self, other, /):
return bitwise_right_shift(self)

# Comparison Operators
def __eq__(self, other: int | float | bool | NamedArray, /) -> NamedArray:
from xarray.namedarray._array_api import equal, asarray

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

return equal(self, other)
return equal(self, asarray(other))

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

0 comments on commit 2e6f3da

Please sign in to comment.