Skip to content

Commit 364c9cb

Browse files
authored
BUG: all not ignoring na when skipna=True (#55367)
* BUG: all not ignoring na when skipna=True * Update v2.1.2.rst
1 parent 6a8055d commit 364c9cb

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

doc/source/whatsnew/v2.1.2.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Bug fixes
2929
- Fixed bug in :meth:`DataFrame.resample` not respecting ``closed`` and ``label`` arguments for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55282`)
3030
- Fixed bug in :meth:`DataFrame.resample` where bin edges were not correct for :class:`~pandas.tseries.offsets.BusinessDay` (:issue:`55281`)
3131
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
32+
- Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`)
3233
- Fixed bug in :meth:`Series.rank` for ``string[pyarrow_numpy]`` dtype (:issue:`55362`)
3334
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
3435
-

pandas/core/arrays/string_arrow.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,11 @@ def _reduce(
631631
self, name: str, *, skipna: bool = True, keepdims: bool = False, **kwargs
632632
):
633633
if name in ["any", "all"]:
634-
arr = pc.and_kleene(
635-
pc.invert(pc.is_null(self._pa_array)), pc.not_equal(self._pa_array, "")
636-
)
634+
if not skipna and name == "all":
635+
nas = pc.invert(pc.is_null(self._pa_array))
636+
arr = pc.and_kleene(nas, pc.not_equal(self._pa_array, ""))
637+
else:
638+
arr = pc.not_equal(self._pa_array, "")
637639
return ArrowExtensionArray(arr)._reduce(
638640
name, skipna=skipna, keepdims=keepdims, **kwargs
639641
)

pandas/tests/reductions/test_reductions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ def test_any_all_pyarrow_string(self):
10871087

10881088
ser = Series([None, "a"], dtype="string[pyarrow_numpy]")
10891089
assert ser.any()
1090-
assert not ser.all()
1090+
assert ser.all()
1091+
assert not ser.all(skipna=False)
10911092

10921093
ser = Series([None, ""], dtype="string[pyarrow_numpy]")
10931094
assert not ser.any()

0 commit comments

Comments
 (0)