Skip to content

Commit ce36571

Browse files
committed
update ufunc test
1 parent 09e5bf5 commit ce36571

File tree

2 files changed

+9
-42
lines changed

2 files changed

+9
-42
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,10 @@
5050
pandas_dtype,
5151
)
5252
from pandas.core.dtypes.dtypes import DatetimeTZDtype
53-
from pandas.core.dtypes.generic import (
54-
ABCDataFrame,
55-
ABCIndex,
56-
ABCSeries,
57-
)
5853
from pandas.core.dtypes.missing import isna
5954

6055
from pandas.core import (
6156
algorithms as algos,
62-
arraylike,
6357
missing,
6458
ops,
6559
roperator,
@@ -758,39 +752,6 @@ def __array__(
758752

759753
return self.to_numpy(dtype=dtype, copy=copy)
760754

761-
def __array_ufunc__(self, ufunc: np.ufunc, method: str, *inputs, **kwargs):
762-
if any(
763-
isinstance(other, (ABCSeries, ABCIndex, ABCDataFrame)) for other in inputs
764-
):
765-
return NotImplemented
766-
767-
result = arraylike.maybe_dispatch_ufunc_to_dunder_op(
768-
self, ufunc, method, *inputs, **kwargs
769-
)
770-
if result is not NotImplemented:
771-
return result
772-
773-
if "out" in kwargs:
774-
return arraylike.dispatch_ufunc_with_out(
775-
self, ufunc, method, *inputs, **kwargs
776-
)
777-
778-
if method == "reduce":
779-
result = arraylike.dispatch_reduction_ufunc(
780-
self, ufunc, method, *inputs, **kwargs
781-
)
782-
if result is not NotImplemented:
783-
return result
784-
785-
if self.dtype.kind == "f":
786-
# e.g. test_log_arrow_backed_missing_value
787-
new_inputs = [
788-
x if x is not self else x.to_numpy(na_value=np.nan) for x in inputs
789-
]
790-
return getattr(ufunc, method)(*new_inputs, **kwargs)
791-
792-
return arraylike.default_array_ufunc(self, ufunc, method, *inputs, **kwargs)
793-
794755
def __invert__(self) -> Self:
795756
# This is a bit wise op for integer types
796757
if pa.types.is_integer(self._pa_array.type):

pandas/tests/series/test_npfuncs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ def test_numpy_argwhere(index):
4141
def test_log_arrow_backed_missing_value(using_nan_is_na):
4242
# GH#56285
4343
ser = Series([1, 2, None], dtype="float64[pyarrow]")
44-
result = np.log(ser)
45-
expected = np.log(Series([1, 2, None], dtype="float64"))
46-
tm.assert_series_equal(result, expected)
44+
if using_nan_is_na:
45+
result = np.log(ser)
46+
expected = np.log(Series([1, 2, None], dtype="float64"))
47+
tm.assert_series_equal(result, expected)
48+
else:
49+
# we get cast to object which raises
50+
msg = "loop of ufunc does not support argument"
51+
with pytest.raises(TypeError, match=msg):
52+
np.log(ser)

0 commit comments

Comments
 (0)