BUG: SparseArray.unique fails to keep original elements order · Issue #47809 · pandas-dev/pandas (original) (raw)

Pandas version checks

Reproducible Example

1.4.3

arr = SparseArray([np.nan, 1.0, 0, 0, np.nan, 2], fill_value=1.0) arr.unique() [nan, 0.0, 2.0, 1.0] Fill: 1.0 IntIndex Indices: array([0, 1, 2])

main

IndexError: index 5 is out of bounds for axis 0 with size 3

Issue Description

#46287 changes the implementation for SparseArray.unique, which raises for non-default fill_value. (Actually the original one in 1.4.3 is also not correct.)

Expected Behavior

>>> arr.unique()
[nan, 1.0, 0.0, 2.0]
Fill: 1.0
IntIndex
Indices: array([0, 2, 3])

Installed Versions

main