Skip to content

Commit 88c0a0e

Browse files
committed
Remove txt version of math operation
1 parent 9d4ad61 commit 88c0a0e

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

mikeio/dataset/_dataarray.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,33 +1753,31 @@ def __radd__(self, other: "DataArray" | float) -> "DataArray":
17531753
return self.__add__(other)
17541754

17551755
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)
17571757

17581758
def __rsub__(self, other: "DataArray" | float) -> "DataArray":
17591759
return other + self.__neg__()
17601760

17611761
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)
17631763

17641764
def __rmul__(self, other: "DataArray" | float) -> "DataArray":
17651765
return self.__mul__(other)
17661766

17671767
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)
17711769

17721770
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)
17741772

17751773
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)
17771775

17781776
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)
17801778

17811779
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)
17831781

17841782
def __neg__(self) -> "DataArray":
17851783
return self._apply_unary_math_operation(np.negative)
@@ -1802,7 +1800,9 @@ def _apply_unary_math_operation(self, func: Callable) -> "DataArray":
18021800
return new_da
18031801

18041802
def _apply_math_operation(
1805-
self, other: "DataArray" | float, func: Callable, *, txt: str
1803+
self,
1804+
other: "DataArray" | float,
1805+
func: Callable,
18061806
) -> "DataArray":
18071807
"""Apply a binary math operation with a scalar, an array or another DataArray."""
18081808
try:
@@ -1811,8 +1811,6 @@ def _apply_math_operation(
18111811
except TypeError:
18121812
raise TypeError("Math operation could not be applied to DataArray")
18131813

1814-
# TODO: check if geometry etc match if other is DataArray?
1815-
18161814
new_da = self.copy() # TODO: alternatively: create new dataset (will validate)
18171815
new_da.values = data
18181816

mikeio/dataset/_dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,7 @@ def _multiply_value(self, value: float | "Dataset") -> "Dataset":
17911791
self._check_datasets_match(value)
17921792
data = [x * y for x, y in zip(self, value)]
17931793
else:
1794-
data = [x * value for x in self]
1794+
data = [x * value for x in self] # type: ignore
17951795
except TypeError:
17961796
raise TypeError(f"{value} could not be multiplied to Dataset")
17971797
return Dataset(data)
@@ -1802,7 +1802,7 @@ def _divide_value(self, value: float | "Dataset") -> "Dataset":
18021802
self._check_datasets_match(value)
18031803
data = [x / y for x, y in zip(self, value)]
18041804
else:
1805-
data = [x / value for x in self]
1805+
data = [x / value for x in self] # type: ignore
18061806
except TypeError:
18071807
raise TypeError(f"{value} could not be divided to Dataset")
18081808
return Dataset(data)

0 commit comments

Comments
 (0)