Skip to content

ENH/TST: Add BaseUnaryOpsTests tests for ArrowExtensionArray #47711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ def __arrow_array__(self, type=None):
"""Convert myself to a pyarrow ChunkedArray."""
return self._data

def __invert__(self: ArrowExtensionArrayT) -> ArrowExtensionArrayT:
if pa_version_under2p0:
raise NotImplementedError("__invert__ not implement for pyarrow < 2.0")
return type(self)(pc.invert(self._data))

def __neg__(self: ArrowExtensionArrayT) -> ArrowExtensionArrayT:
return type(self)(pc.negate_checked(self._data))

def __pos__(self: ArrowExtensionArrayT) -> ArrowExtensionArrayT:
return type(self)(self._data)

def __abs__(self: ArrowExtensionArrayT) -> ArrowExtensionArrayT:
return type(self)(pc.abs_checked(self._data))

def _cmp_method(self, other, op):
from pandas.arrays import BooleanArray

Expand Down
18 changes: 18 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,24 @@ def test_EA_types(self, engine, data, request):
super().test_EA_types(engine, data)


class TestBaseUnaryOps(base.BaseUnaryOpsTests):
@pytest.mark.xfail(
pa_version_under2p0,
raises=NotImplementedError,
reason="pyarrow.compute.invert not supported in pyarrow<2.0",
)
def test_invert(self, data, request):
pa_dtype = data.dtype.pyarrow_dtype
if not pa.types.is_boolean(pa_dtype):
request.node.add_marker(
pytest.mark.xfail(
raises=pa.ArrowNotImplementedError,
reason=f"pyarrow.compute.invert does support {pa_dtype}",
)
)
super().test_invert(data)


class TestBaseMethods(base.BaseMethodsTests):
@pytest.mark.parametrize("dropna", [True, False])
def test_value_counts(self, all_data, dropna, request):
Expand Down