From 95d64024643ba4b76c6f4f5c9c7caeb2c3419bbf Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Mon, 12 Aug 2019 18:51:28 -0700 Subject: [PATCH 1/2] BUG: fix Sparse reduction --- pandas/core/arrays/sparse.py | 3 +++ pandas/tests/series/test_ufunc.py | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/sparse.py b/pandas/core/arrays/sparse.py index 8aa83c3fbc37d..2234167fe0193 100644 --- a/pandas/core/arrays/sparse.py +++ b/pandas/core/arrays/sparse.py @@ -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) diff --git a/pandas/tests/series/test_ufunc.py b/pandas/tests/series/test_ufunc.py index c024e9caba156..8144a3931b9b8 100644 --- a/pandas/tests/series/test_ufunc.py +++ b/pandas/tests/series/test_ufunc.py @@ -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"), From 5f93ba43bb38872e9c2003bae07894ede44c03a4 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 13 Aug 2019 07:15:50 -0700 Subject: [PATCH 2/2] whatsnew --- doc/source/whatsnew/v0.25.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index b97f45efbeae9..dfa216b1db56e 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -133,7 +133,7 @@ Reshaping Sparse ^^^^^^ - +- Bug in reductions for :class:`Series` with Sparse dtypes (:issue:`27080`) - - -