Skip to content

Commit d02aa49

Browse files
lukemanleyphofl
authored andcommitted
BUG: Series.any and Series.all for empty or all-null pyarrow-backed dtypes (pandas-dev#51631)
* BUG: ArrowExtensionArray boolean reductions for empty or all null array * whatsnew * clarify whatsnew
1 parent b9dd4fa commit d02aa49

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pandas/core/arrays/arrow/array.py

Lines changed: 4 additions & 0 deletions
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

Lines changed: 10 additions & 6 deletions
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)