Skip to content

Commit

Permalink
TST: Add regression test for NaN sparse columns (#52772)
Browse files Browse the repository at this point in the history
* Add test for GH 27781

* Modify test for GH 27781
  • Loading branch information
ConnorMcKinley committed Apr 19, 2023
1 parent fc4ff26 commit e96054a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pandas/tests/arrays/sparse/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,15 @@ def test_drop_duplicates_fill_value():
result = df.drop_duplicates()
expected = pd.DataFrame({i: SparseArray([0.0], fill_value=0) for i in range(5)})
tm.assert_frame_equal(result, expected)


def test_zero_sparse_column():
# GH 27781
df1 = pd.DataFrame({"A": SparseArray([0, 0, 0]), "B": [1, 2, 3]})
df2 = pd.DataFrame({"A": SparseArray([0, 1, 0]), "B": [1, 2, 3]})
result = df1.loc[df1["B"] != 2]
expected = df2.loc[df2["B"] != 2]
tm.assert_frame_equal(result, expected)

expected = pd.DataFrame({"A": SparseArray([0, 0]), "B": [1, 3]}, index=[0, 2])
tm.assert_frame_equal(result, expected)

0 comments on commit e96054a

Please sign in to comment.