Skip to content

Commit 5de4e55

Browse files
jbrockmendelTomAugspurger
authored andcommitted
BUG: fix Sparse reduction (#27890)
* BUG: fix Sparse reduction
1 parent 80a7a45 commit 5de4e55

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

doc/source/whatsnew/v0.25.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ Reshaping
133133

134134
Sparse
135135
^^^^^^
136-
136+
- Bug in reductions for :class:`Series` with Sparse dtypes (:issue:`27080`)
137137
-
138138
-
139139
-

pandas/core/arrays/sparse.py

+3
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,9 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
16931693
for sp_value, fv in zip(sp_values, fill_value)
16941694
)
16951695
return arrays
1696+
elif is_scalar(sp_values):
1697+
# e.g. reductions
1698+
return sp_values
16961699

16971700
return self._simple_new(
16981701
sp_values, self.sp_index, SparseDtype(sp_values.dtype, fill_value)

pandas/tests/series/test_ufunc.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ def __add__(self, other):
252252
"values",
253253
[
254254
pd.array([1, 3, 2]),
255-
pytest.param(
256-
pd.array([1, 10, 0], dtype="Sparse[int]"),
257-
marks=pytest.mark.xfail(resason="GH-27080. Bug in SparseArray"),
258-
),
255+
pd.array([1, 10, 0], dtype="Sparse[int]"),
259256
pd.to_datetime(["2000", "2010", "2001"]),
260257
pd.to_datetime(["2000", "2010", "2001"]).tz_localize("CET"),
261258
pd.to_datetime(["2000", "2010", "2001"]).to_period(freq="D"),

0 commit comments

Comments
 (0)