From e96054a5315c0924bb241d53a72580ec8faeb9b5 Mon Sep 17 00:00:00 2001 From: cmmck <70769004+ConnorMcKinley@users.noreply.github.com> Date: Wed, 19 Apr 2023 18:13:11 -0400 Subject: [PATCH] TST: Add regression test for NaN sparse columns (#52772) * Add test for GH 27781 * Modify test for GH 27781 --- pandas/tests/arrays/sparse/test_array.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/arrays/sparse/test_array.py b/pandas/tests/arrays/sparse/test_array.py index 54c8e359b2859..4a0795137f80b 100644 --- a/pandas/tests/arrays/sparse/test_array.py +++ b/pandas/tests/arrays/sparse/test_array.py @@ -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)