From e9892e2d1f526994dcf175e88195244e9e7ea253 Mon Sep 17 00:00:00 2001 From: Avinash Pancham Date: Sat, 11 Jul 2020 18:04:45 +0200 Subject: [PATCH 1/2] TST: Verify filtering operations on DataFrames with categorical Series --- pandas/tests/dtypes/test_common.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index ce12718e48d0d..c2d26aa6753b4 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -746,3 +746,15 @@ def test_astype_object_preserves_datetime_na(from_type): result = astype_nansafe(arr, dtype="object") assert isna(result)[0] + + +def test_categorical_filtering(): + # GH22609 Verify filtering operations on DataFrames with categorical Series + df = pd.DataFrame(data=[[0, 0], [1, 1]], columns=["a", "b"]) + df["b"] = df.b.astype("category") + + result = df.where(df.a > 0) + expected = df.copy() + expected.loc[0, :] = np.nan + + tm.assert_equal(result, expected) From e707c834562de9b89830241c0ac2736d8480a1bb Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Wed, 15 Jul 2020 14:05:59 -0500 Subject: [PATCH 2/2] move --- pandas/tests/dtypes/test_common.py | 12 ------------ pandas/tests/frame/indexing/test_categorical.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index c2d26aa6753b4..ce12718e48d0d 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -746,15 +746,3 @@ def test_astype_object_preserves_datetime_na(from_type): result = astype_nansafe(arr, dtype="object") assert isna(result)[0] - - -def test_categorical_filtering(): - # GH22609 Verify filtering operations on DataFrames with categorical Series - df = pd.DataFrame(data=[[0, 0], [1, 1]], columns=["a", "b"]) - df["b"] = df.b.astype("category") - - result = df.where(df.a > 0) - expected = df.copy() - expected.loc[0, :] = np.nan - - tm.assert_equal(result, expected) diff --git a/pandas/tests/frame/indexing/test_categorical.py b/pandas/tests/frame/indexing/test_categorical.py index d94dc8d2ffe00..25ad9063e7418 100644 --- a/pandas/tests/frame/indexing/test_categorical.py +++ b/pandas/tests/frame/indexing/test_categorical.py @@ -391,3 +391,14 @@ def test_loc_indexing_preserves_index_category_dtype(self): result = df.loc[["a"]].index.levels[0] tm.assert_index_equal(result, expected) + + def test_categorical_filtering(self): + # GH22609 Verify filtering operations on DataFrames with categorical Series + df = pd.DataFrame(data=[[0, 0], [1, 1]], columns=["a", "b"]) + df["b"] = df.b.astype("category") + + result = df.where(df.a > 0) + expected = df.copy() + expected.loc[0, :] = np.nan + + tm.assert_equal(result, expected)