Skip to content

Commit 8fd8cf4

Browse files
authored
Backport PR #55367 on branch 2.1.x (BUG: all not ignoring na when skipna=True) (#55407)
BUG: all not ignoring na when skipna=True (#55367) * BUG: all not ignoring na when skipna=True * Update v2.1.2.rst (cherry picked from commit 364c9cb)
1 parent f07deef commit 8fd8cf4

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
@@ -26,6 +26,7 @@ Bug fixes
2626
- Fixed bug in :meth:`DataFrame.idxmin` and :meth:`DataFrame.idxmax` raising for arrow dtypes (:issue:`55368`)
2727
- Fixed bug in :meth:`DataFrame.interpolate` raising incorrect error message (:issue:`55347`)
2828
- Fixed bug in :meth:`Index.insert` raising when inserting ``None`` into :class:`Index` with ``dtype="string[pyarrow_numpy]"`` (:issue:`55365`)
29+
- Fixed bug in :meth:`Series.all` and :meth:`Series.any` not treating missing values correctly for ``dtype="string[pyarrow_numpy]"`` (:issue:`55367`)
2930
- Silence ``Period[B]`` warnings introduced by :issue:`53446` during normal plotting activity (:issue:`55138`)
3031
-
3132

pandas/core/arrays/string_arrow.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,11 @@ def _reduce(
571571
self, name: str, *, skipna: bool = True, keepdims: bool = False, **kwargs
572572
):
573573
if name in ["any", "all"]:
574-
arr = pc.and_kleene(
575-
pc.invert(pc.is_null(self._pa_array)), pc.not_equal(self._pa_array, "")
576-
)
574+
if not skipna and name == "all":
575+
nas = pc.invert(pc.is_null(self._pa_array))
576+
arr = pc.and_kleene(nas, pc.not_equal(self._pa_array, ""))
577+
else:
578+
arr = pc.not_equal(self._pa_array, "")
577579
return ArrowExtensionArray(arr)._reduce(
578580
name, skipna=skipna, keepdims=keepdims, **kwargs
579581
)

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)