Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TST: Add regression test for NaN sparse columns #52772

Merged
merged 2 commits into from
Apr 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 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,12 @@ 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also compare this to a manually created dataframe i.e.

expected = pd.DataFrame({...})
tm.assert_frame_equal(result, expected)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it, thanks for the suggestion.

expected = df2.loc[df2["B"] != 2]
tm.assert_frame_equal(result, expected)