@@ -1753,33 +1753,31 @@ def __radd__(self, other: "DataArray" | float) -> "DataArray":
1753
1753
return self .__add__ (other )
1754
1754
1755
1755
def __add__ (self , other : "DataArray" | float ) -> "DataArray" :
1756
- return self ._apply_math_operation (other , np .add , txt = "+" )
1756
+ return self ._apply_math_operation (other , np .add )
1757
1757
1758
1758
def __rsub__ (self , other : "DataArray" | float ) -> "DataArray" :
1759
1759
return other + self .__neg__ ()
1760
1760
1761
1761
def __sub__ (self , other : "DataArray" | float ) -> "DataArray" :
1762
- return self ._apply_math_operation (other , np .subtract , txt = "-" )
1762
+ return self ._apply_math_operation (other , np .subtract )
1763
1763
1764
1764
def __rmul__ (self , other : "DataArray" | float ) -> "DataArray" :
1765
1765
return self .__mul__ (other )
1766
1766
1767
1767
def __mul__ (self , other : "DataArray" | float ) -> "DataArray" :
1768
- return self ._apply_math_operation (
1769
- other , np .multiply , txt = "x"
1770
- ) # x in place of *
1768
+ return self ._apply_math_operation (other , np .multiply )
1771
1769
1772
1770
def __pow__ (self , other : float ) -> "DataArray" :
1773
- return self ._apply_math_operation (other , np .power , txt = "**" )
1771
+ return self ._apply_math_operation (other , np .power )
1774
1772
1775
1773
def __truediv__ (self , other : "DataArray" | float ) -> "DataArray" :
1776
- return self ._apply_math_operation (other , np .divide , txt = "/" )
1774
+ return self ._apply_math_operation (other , np .divide )
1777
1775
1778
1776
def __floordiv__ (self , other : "DataArray" | float ) -> "DataArray" :
1779
- return self ._apply_math_operation (other , np .floor_divide , txt = "//" )
1777
+ return self ._apply_math_operation (other , np .floor_divide )
1780
1778
1781
1779
def __mod__ (self , other : float ) -> "DataArray" :
1782
- return self ._apply_math_operation (other , np .mod , txt = "%" )
1780
+ return self ._apply_math_operation (other , np .mod )
1783
1781
1784
1782
def __neg__ (self ) -> "DataArray" :
1785
1783
return self ._apply_unary_math_operation (np .negative )
@@ -1802,7 +1800,9 @@ def _apply_unary_math_operation(self, func: Callable) -> "DataArray":
1802
1800
return new_da
1803
1801
1804
1802
def _apply_math_operation (
1805
- self , other : "DataArray" | float , func : Callable , * , txt : str
1803
+ self ,
1804
+ other : "DataArray" | float ,
1805
+ func : Callable ,
1806
1806
) -> "DataArray" :
1807
1807
"""Apply a binary math operation with a scalar, an array or another DataArray."""
1808
1808
try :
@@ -1811,8 +1811,6 @@ def _apply_math_operation(
1811
1811
except TypeError :
1812
1812
raise TypeError ("Math operation could not be applied to DataArray" )
1813
1813
1814
- # TODO: check if geometry etc match if other is DataArray?
1815
-
1816
1814
new_da = self .copy () # TODO: alternatively: create new dataset (will validate)
1817
1815
new_da .values = data
1818
1816
0 commit comments