BUG: Sparse indexing with bool sparse may be incorrect by sinhrks · Pull Request #13985 · pandas-dev/pandas (original) (raw)
indexing with SparseArray
with bool
dtype may return incorrect result because of some internal conversions.
arr = pd.SparseArray([1, 2, 3])
indexer = pd.SparseArray([True, False, True], fill_value=False, dtype=bool)
# NG
arr[indexer]
# [2.0, 2.0]
# Fill: nan
# IntIndex
# Indices: array([0, 1], dtype=int32)
# Expected (after this PR)
arr[indexer]
# [1.0, 3.0]
# Fill: nan
# IntIndex
# Indices: array([0, 1], dtype=int32)