From 1737821cb30db9ab876702586ce85b02ac54266d Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Feb 2023 12:02:19 +0000 Subject: [PATCH 1/2] TST: add test for NaT in Categorical with empty string --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/tests/arrays/categorical/test_algos.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index bdbde438217b9..e8fc89bdd212d 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -1177,6 +1177,7 @@ Categorical - Bug in :meth:`Series.replace` with categorical dtype losing nullable dtypes of underlying categories (:issue:`49404`) - Bug in :meth:`DataFrame.groupby` and :meth:`Series.groupby` would reorder categories when used as a grouper (:issue:`48749`) - Bug in :class:`Categorical` constructor when constructing from a :class:`Categorical` object and ``dtype="category"`` losing ordered-ness (:issue:`49309`) +- Bug in :meth:`Categorical.isin` where ``Categorical([""]).isin(["", pd.NaT])`` returned ``np.array([False])`` (:issue:`36550`) - Bug in :meth:`.SeriesGroupBy.min`, :meth:`.SeriesGroupBy.max`, :meth:`.DataFrameGroupBy.min`, and :meth:`.DataFrameGroupBy.max` with unordered :class:`CategoricalDtype` with no groups failing to raise ``TypeError`` (:issue:`51034`) Datetimelike diff --git a/pandas/tests/arrays/categorical/test_algos.py b/pandas/tests/arrays/categorical/test_algos.py index ef165767ed5ed..d4c19a4970135 100644 --- a/pandas/tests/arrays/categorical/test_algos.py +++ b/pandas/tests/arrays/categorical/test_algos.py @@ -59,6 +59,15 @@ def test_isin_cats(): tm.assert_numpy_array_equal(expected, result) +@pytest.mark.parametrize("value", [[""], [None, ""], [pd.NaT, ""]]) +def test_isin_cats_corner_cases(value): + # GH36550 + cat = pd.Categorical([""]) + result = cat.isin(value) + expected = np.array([True], dtype=bool) + tm.assert_numpy_array_equal(expected, result) + + @pytest.mark.parametrize("empty", [[], pd.Series(dtype=object), np.array([])]) def test_isin_empty(empty): s = pd.Categorical(["a", "b"]) From 5530d0d07553f0eb9609fd77b3ad640ae15a602d Mon Sep 17 00:00:00 2001 From: Terji Petersen Date: Thu, 23 Feb 2023 15:08:08 +0000 Subject: [PATCH 2/2] remove whatsnew entry --- doc/source/whatsnew/v2.0.0.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index e8fc89bdd212d..bdbde438217b9 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -1177,7 +1177,6 @@ Categorical - Bug in :meth:`Series.replace` with categorical dtype losing nullable dtypes of underlying categories (:issue:`49404`) - Bug in :meth:`DataFrame.groupby` and :meth:`Series.groupby` would reorder categories when used as a grouper (:issue:`48749`) - Bug in :class:`Categorical` constructor when constructing from a :class:`Categorical` object and ``dtype="category"`` losing ordered-ness (:issue:`49309`) -- Bug in :meth:`Categorical.isin` where ``Categorical([""]).isin(["", pd.NaT])`` returned ``np.array([False])`` (:issue:`36550`) - Bug in :meth:`.SeriesGroupBy.min`, :meth:`.SeriesGroupBy.max`, :meth:`.DataFrameGroupBy.min`, and :meth:`.DataFrameGroupBy.max` with unordered :class:`CategoricalDtype` with no groups failing to raise ``TypeError`` (:issue:`51034`) Datetimelike