Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add test to verify dropna behaviour on pd.SparseArray
verify that calling `dropna` on a pd.SparseArray does not inadvertently drop non-na records on both DataFrames and the SparseArray itself.
  • Loading branch information
MBrouns committed Jun 20, 2020
commit dd4c22c74f9b12855067b86bfee37e8a2b485a6a
11 changes: 11 additions & 0 deletions pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,14 @@ def test_map_missing():

result = arr.map({0: 10, 1: 11})
tm.assert_sp_array_equal(result, expected)


def test_dropna_sparse_column_doesnt_drop_nonna():
# GH-28287
arr = SparseArray([np.nan, 1])
exp = SparseArray([1.0])
tm.assert_sp_array_equal(arr.dropna(), exp)

df = pd.DataFrame({"a": [0, 1], "b": arr})
expected_df = pd.DataFrame({"a": [1], "b": exp}, index=pd.Int64Index([1]))
tm.assert_equal(df.dropna(), expected_df)