From 608b499d1366ae77cdf79dd183955c556fd4db1c Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 16 Aug 2018 14:57:35 -0500 Subject: [PATCH] Fixed Series[sparse].to_sparse Closes https://github.com/pandas-dev/pandas/issues/22389 --- doc/source/whatsnew/v0.24.0.txt | 1 + pandas/tests/sparse/series/test_series.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 119dc653d9431..c365a5a2f1d93 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -737,6 +737,7 @@ Sparse ^^^^^^ - Updating a boolean, datetime, or timedelta column to be Sparse now works (:issue:`22367`) +- Bug in :meth:`Series.to_sparse` with Series already holding sparse data not constructing properly (:issue:`22389`) Build Changes diff --git a/pandas/tests/sparse/series/test_series.py b/pandas/tests/sparse/series/test_series.py index 67cedf57d76f3..d48f06be4adf7 100644 --- a/pandas/tests/sparse/series/test_series.py +++ b/pandas/tests/sparse/series/test_series.py @@ -1499,3 +1499,11 @@ def test_constructor_dict_datetime64_index(datetime_type): expected = SparseSeries(values, map(pd.Timestamp, dates)) tm.assert_sp_series_equal(result, expected) + + +def test_to_sparse(): + # https://github.com/pandas-dev/pandas/issues/22389 + arr = pd.SparseArray([1, 2, None, 3]) + result = pd.Series(arr).to_sparse() + assert len(result) == 4 + tm.assert_sp_array_equal(result.values, arr)