Skip to content

Commit

Permalink
BUG: SparseArray.unique with all sparse (#23186)
Browse files Browse the repository at this point in the history
* BUG: SparseArray.unique with all sparse

* fixup
  • Loading branch information
TomAugspurger committed Oct 18, 2018
1 parent 1546c35 commit dc5ef66
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ Sparse
- Improved performance of :meth:`Series.shift` for non-NA ``fill_value``, as values are no longer converted to a dense array.
- Bug in ``DataFrame.groupby`` not including ``fill_value`` in the groups for non-NA ``fill_value`` when grouping by a sparse column (:issue:`5078`)
- Bug in unary inversion operator (``~``) on a ``SparseSeries`` with boolean values. The performance of this has also been improved (:issue:`22835`)
- Bug in :meth:`SparseArary.unique` not returning the unique values (:issue:`19595`)

Build Changes
^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def _first_fill_value_loc(self):
return -1

indices = self.sp_index.to_int_index().indices
if indices[0] > 0:
if not len(indices) or indices[0] > 0:
return 0

diff = indices[1:] - indices[:-1]
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,14 @@ def test_unique_na_fill(arr, fill_value):
tm.assert_numpy_array_equal(a, b)


def test_unique_all_sparse():
# https://github.com/pandas-dev/pandas/issues/23168
arr = SparseArray([0, 0])
result = arr.unique()
expected = SparseArray([0])
tm.assert_sp_array_equal(result, expected)


def test_map():
arr = SparseArray([0, 1, 2])
expected = SparseArray([10, 11, 12], fill_value=10)
Expand Down

0 comments on commit dc5ef66

Please sign in to comment.