From 3a6cfcaa60402258ed521dec8a06c29abc29365b Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 22:10:56 +0500 Subject: [PATCH 1/7] assertion error fix added in pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 7b8ba79789f41..922910d7005c8 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2425,6 +2425,13 @@ def is_categorical(self) -> bool: >>> s.index.is_categorical() False """ + warnings.warn( + f"{type(self).__name__}.is_categorical is deprecated." + "Use pandas.api.types.is_categorical_dtype instead", + FutureWarning, + stacklevel=find_stack_level(), + ) + return self.inferred_type in ["categorical"] @final From e79aaca60df80aca352296c97c455de346bb6d67 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Thu, 15 Dec 2022 19:40:29 +0500 Subject: [PATCH 2/7] unrelated changes removed --- doc/source/whatsnew/v2.0.0.rst | 1 + pandas/core/indexes/base.py | 19 +++++++++++++------ pandas/tests/indexes/common.py | 6 ++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 033f47f0c994d..7f983c97691ca 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -577,6 +577,7 @@ Deprecations - :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`) - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) +- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index ce65dab6cea14..862a18cbdbfb0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2250,7 +2250,7 @@ def is_integer(self) -> bool: is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. - is_categorical : Check if the Index holds categorical data. + is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects. Examples @@ -2298,7 +2298,7 @@ def is_floating(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. - is_categorical : Check if the Index holds categorical data. + is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects. Examples @@ -2343,7 +2343,7 @@ def is_numeric(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_object : Check if the Index is of the object dtype. - is_categorical : Check if the Index holds categorical data. + is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects. Examples @@ -2386,7 +2386,7 @@ def is_object(self) -> bool: is_integer : Check if the Index only consists of integers (deprecated). is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. - is_categorical : Check if the Index holds categorical data. + is_categorical : Check if the Index holds categorical data (deprecated). is_interval : Check if the Index holds Interval objects. Examples @@ -2415,6 +2415,9 @@ def is_categorical(self) -> bool: """ Check if the Index holds categorical data. + .. deprecated:: 2.0.0 + Use :meth:`pandas.api.types.is_categorical_dtype` instead. + Returns ------- bool @@ -2478,7 +2481,7 @@ def is_interval(self) -> bool: is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. - is_categorical : Check if the Index holds categorical data. + is_categorical : Check if the Index holds categorical data (deprecated). Examples -------- @@ -5040,7 +5043,11 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool: https://github.com/pandas-dev/pandas/issues/19764 """ - if self.is_object() or is_string_dtype(self.dtype) or self.is_categorical(): + if ( + self.is_object() + or is_string_dtype(self.dtype) + or is_categorical_dtype(self) + ): return name in self return False diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index ed8eb350234d1..1244bae4959bc 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -822,6 +822,12 @@ def test_holds_integer_deprecated(self, simple_index): with tm.assert_produces_warning(FutureWarning, match=msg): idx.holds_integer() + def test_is_categorical_is_deprecated(self, simple_index): + # GH50042 + idx = simple_index + with tm.assert_produces_warning(FutureWarning): + idx.is_categorical() + class NumericBase(Base): """ From 34af5a6b5da16cc9254343e454ae1c01c8dc3bd7 Mon Sep 17 00:00:00 2001 From: Salahuddin <60926009+ShisuiUzumaki@users.noreply.github.com> Date: Thu, 15 Dec 2022 18:32:43 +0000 Subject: [PATCH 3/7] removing unrelated changes --- doc/source/whatsnew/v2.0.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 7f983c97691ca..5609f18ac993f 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -579,6 +579,8 @@ Deprecations - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) +- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) + .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: From 633c48f92bb6150036388474e767ca06ac7cbfad Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Fri, 16 Dec 2022 12:39:44 +0500 Subject: [PATCH 4/7] replaced self with self.dtyp in base.py, removed extra line in 2.0.0.rst --- doc/source/whatsnew/v2.0.0.rst | 3 --- pandas/core/indexes/base.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 5609f18ac993f..b29d77da066e3 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -578,9 +578,6 @@ Deprecations - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - -- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 862a18cbdbfb0..9f86e5276b0d6 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -5046,7 +5046,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool: if ( self.is_object() or is_string_dtype(self.dtype) - or is_categorical_dtype(self) + or is_categorical_dtype(self.dtype) ): return name in self return False From 947284c1df67b8005091748308444176ade6466c Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Fri, 16 Dec 2022 14:21:14 +0500 Subject: [PATCH 5/7] added new line which was removed accidentally --- doc/source/whatsnew/v2.0.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index b29d77da066e3..7f983c97691ca 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -578,6 +578,7 @@ Deprecations - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) + .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: From bc36d1f0e5e079ad696975ee9d86c1c3bda2e630 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Fri, 16 Dec 2022 19:51:37 +0500 Subject: [PATCH 6/7] matching warning messege in test --- pandas/tests/indexes/common.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 1244bae4959bc..348f015f016f5 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -825,7 +825,11 @@ def test_holds_integer_deprecated(self, simple_index): def test_is_categorical_is_deprecated(self, simple_index): # GH50042 idx = simple_index - with tm.assert_produces_warning(FutureWarning): + with tm.assert_produces_warning( + FutureWarning, + match="Index.is_categorical is deprecated." + "Use pandas.api.types.is_categorical_dtype instead", + ): idx.is_categorical() From 709e0041d2e83b1139c39accb1544fecdc7309df Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Mon, 16 Jan 2023 17:10:27 +0500 Subject: [PATCH 7/7] fix for pre-commit check --- pandas/tests/indexes/common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 348f015f016f5..779c1cc6ccd05 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -827,8 +827,7 @@ def test_is_categorical_is_deprecated(self, simple_index): idx = simple_index with tm.assert_produces_warning( FutureWarning, - match="Index.is_categorical is deprecated." - "Use pandas.api.types.is_categorical_dtype instead", + match=r"Use pandas\.api\.types\.is_categorical_dtype instead", ): idx.is_categorical()