Skip to content

BUG: preserve dtype to bool[pyarrow] when calling pyarrow backed Series.isna() #59436

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

Closed
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ Conversion
- Bug in :meth:`DataFrame.update` bool dtype being converted to object (:issue:`55509`)
- Bug in :meth:`Series.astype` might modify read-only array inplace when casting to a string dtype (:issue:`57212`)
- Bug in :meth:`Series.reindex` not maintaining ``float32`` type when a ``reindex`` introduces a missing value (:issue:`45857`)
- Bug in :meth:`Series.isna` returning ``bool`` instead of ``bool[pyarrow]`` for Arrow-based Series (:issue:`59436`)

Strings
^^^^^^^
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
is_string_or_object_np_dtype,
)
from pandas.core.dtypes.dtypes import (
ArrowDtype,
CategoricalDtype,
DatetimeTZDtype,
ExtensionDtype,
Expand Down Expand Up @@ -206,7 +207,10 @@ def _isna(obj):
elif isinstance(obj, ABCSeries):
result = _isna_array(obj._values)
# box
result = obj._constructor(result, index=obj.index, name=obj.name, copy=False)
new_dtype = "bool[pyarrow]" if isinstance(obj.dtype, ArrowDtype) else None
result = obj._constructor(
result, index=obj.index, name=obj.name, copy=False, dtype=new_dtype
)
return result
elif isinstance(obj, ABCDataFrame):
return obj.isna()
Expand Down
5 changes: 5 additions & 0 deletions pandas/tests/series/methods/test_isna.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ def test_isna(self):
expected = Series([False, False, True])
tm.assert_series_equal(ser.isna(), expected)
tm.assert_series_equal(ser.notna(), ~expected)

def test_is_valid_na_for_dtype_pyarrow(self):
s = Series([0, None, 4, 5], dtype="u1[pyarrow]")
assert s.isna().dtype == "bool[pyarrow]"
assert s.isna().dtype != "bool"
Loading