Skip to content

Commit 4700a61

Browse files
authored
BUG: Series.any and Series.all for empty or all-null pyarrow-backed dtypes (#51631)
* BUG: ArrowExtensionArray boolean reductions for empty or all null array * whatsnew * clarify whatsnew
1 parent ade0418 commit 4700a61

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/source/whatsnew/v2.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ Sparse
200200

201201
ExtensionArray
202202
^^^^^^^^^^^^^^
203-
-
203+
- Bug in :meth:`Series.any` and :meth:`Series.all` returning ``NA`` for empty or all null pyarrow-backed data when ``skipna=True`` (:issue:`51624`)
204204
-
205205

206206
Styler

pandas/core/arrays/arrow/array.py

+4
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,10 @@ def pyarrow_meth(data, skip_nulls, **kwargs):
11421142
# Let ExtensionArray._reduce raise the TypeError
11431143
return super()._reduce(name, skipna=skipna, **kwargs)
11441144

1145+
# GH51624: pyarrow defaults to min_count=1, pandas behavior is min_count=0
1146+
if name in ["any", "all"] and "min_count" not in kwargs:
1147+
kwargs["min_count"] = 0
1148+
11451149
try:
11461150
result = pyarrow_meth(data_to_reduce, skip_nulls=skipna, **kwargs)
11471151
except (AttributeError, NotImplementedError, TypeError) as err:

pandas/tests/extension/test_arrow.py

+12
Original file line numberDiff line numberDiff line change
@@ -2144,3 +2144,15 @@ def test_dt_tz_localize(unit):
21442144
dtype=ArrowDtype(pa.timestamp(unit, "US/Pacific")),
21452145
)
21462146
tm.assert_series_equal(result, expected)
2147+
2148+
2149+
@pytest.mark.parametrize("skipna", [True, False])
2150+
def test_boolean_reduce_series_all_null(all_boolean_reductions, skipna):
2151+
# GH51624
2152+
ser = pd.Series([None], dtype="float64[pyarrow]")
2153+
result = getattr(ser, all_boolean_reductions)(skipna=skipna)
2154+
if skipna:
2155+
expected = all_boolean_reductions == "all"
2156+
else:
2157+
expected = pd.NA
2158+
assert result is expected

0 commit comments

Comments
 (0)