Skip to content

Commit 8daa913

Browse files
phofllukemanley
andauthored
Backport PR #51631 on branch 2.0.x (BUG: Series.any and Series.all for empty or all-null pyarrow-backed dtypes) (#51999)
Co-authored-by: Luke Manley <[email protected]>
1 parent 430d038 commit 8daa913

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ ExtensionArray
13621362
- Bug in :class:`Series` constructor unnecessarily overflowing for nullable unsigned integer dtypes (:issue:`38798`, :issue:`25880`)
13631363
- Bug in setting non-string value into ``StringArray`` raising ``ValueError`` instead of ``TypeError`` (:issue:`49632`)
13641364
- Bug in :meth:`DataFrame.reindex` not honoring the default ``copy=True`` keyword in case of columns with ExtensionDtype (and as a result also selecting multiple columns with getitem (``[]``) didn't correctly result in a copy) (:issue:`51197`)
1365+
- Bug in :meth:`Series.any` and :meth:`Series.all` returning ``NA`` for empty or all null pyarrow-backed data when ``skipna=True`` (:issue:`51624`)
13651366
- Bug in :class:`~arrays.ArrowExtensionArray` logical operations ``&`` and ``|`` raising ``KeyError`` (:issue:`51688`)
13661367

13671368
Styler

pandas/core/arrays/arrow/array.py

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

1148+
# GH51624: pyarrow defaults to min_count=1, pandas behavior is min_count=0
1149+
if name in ["any", "all"] and "min_count" not in kwargs:
1150+
kwargs["min_count"] = 0
1151+
11481152
try:
11491153
result = pyarrow_meth(data_to_reduce, skip_nulls=skipna, **kwargs)
11501154
except (AttributeError, NotImplementedError, TypeError) as err:

pandas/tests/extension/test_arrow.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -2328,9 +2328,13 @@ def test_dt_tz_localize(unit):
23282328
tm.assert_series_equal(result, expected)
23292329

23302330

2331-
def test_concat_empty_arrow_backed_series(dtype):
2332-
# GH#51734
2333-
ser = pd.Series([], dtype=dtype)
2334-
expected = ser.copy()
2335-
result = pd.concat([ser[np.array([], dtype=np.bool_)]])
2336-
tm.assert_series_equal(result, expected)
2331+
@pytest.mark.parametrize("skipna", [True, False])
2332+
def test_boolean_reduce_series_all_null(all_boolean_reductions, skipna):
2333+
# GH51624
2334+
ser = pd.Series([None], dtype="float64[pyarrow]")
2335+
result = getattr(ser, all_boolean_reductions)(skipna=skipna)
2336+
if skipna:
2337+
expected = all_boolean_reductions == "all"
2338+
else:
2339+
expected = pd.NA
2340+
assert result is expected

0 commit comments

Comments
 (0)