Skip to content

BUG: fix Sparse reduction #27890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.25.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Reshaping

Sparse
^^^^^^

- Bug in reductions for :class:`Series` with Sparse dtypes (:issue:`27080`)
-
-
-
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,9 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
for sp_value, fv in zip(sp_values, fill_value)
)
return arrays
elif is_scalar(sp_values):
# e.g. reductions
return sp_values

return self._simple_new(
sp_values, self.sp_index, SparseDtype(sp_values.dtype, fill_value)
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,7 @@ def __add__(self, other):
"values",
[
pd.array([1, 3, 2]),
pytest.param(
pd.array([1, 10, 0], dtype="Sparse[int]"),
marks=pytest.mark.xfail(resason="GH-27080. Bug in SparseArray"),
),
pd.array([1, 10, 0], dtype="Sparse[int]"),
pd.to_datetime(["2000", "2010", "2001"]),
pd.to_datetime(["2000", "2010", "2001"]).tz_localize("CET"),
pd.to_datetime(["2000", "2010", "2001"]).to_period(freq="D"),
Expand Down