From db64fd71b2b85a8a52efab91858f7eff2bdb2243 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 08:57:26 +0500 Subject: [PATCH 01/12] changes made to pandas/core/indexes/base.py in class Index for is_categorical --- pandas/core/indexes/base.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0959f44e62576..af82f251a209c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -23,6 +23,7 @@ import numpy as np +import pandas.api.types from pandas._config import get_option from pandas._libs import ( @@ -2204,7 +2205,7 @@ def is_boolean(self) -> bool: is_floating : Check if the Index is a floating type. 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 @@ -2239,7 +2240,7 @@ def is_integer(self) -> bool: is_floating : Check if the Index is a floating type. 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 @@ -2278,7 +2279,7 @@ def is_floating(self) -> bool: is_integer : Check if the Index only consists of integers. 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 @@ -2317,7 +2318,7 @@ def is_numeric(self) -> bool: is_integer : Check if the Index only consists of integers. is_floating : Check if the Index is a floating type. 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 @@ -2360,7 +2361,7 @@ def is_object(self) -> bool: is_integer : Check if the Index only consists of integers. is_floating : Check if the Index is a floating type. 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 @@ -2389,6 +2390,10 @@ def is_categorical(self) -> bool: """ Check if the Index holds categorical data. + .. deprecated:: 1.3.0 + + Use :meth:`is_categorical_dtype` instead. + Returns ------- bool @@ -2425,6 +2430,12 @@ 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 @@ -2445,7 +2456,7 @@ def is_interval(self) -> bool: is_floating : Check if the Index is a floating type. 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 -------- From 73f2a4fa9d9dc20a529441b4aeae45a92125efe7 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 09:05:03 +0500 Subject: [PATCH 02/12] changes made to pandas/tests/indexes/common.py in class Base sdded 'test_is_categorical_is_deprecated' --- pandas/tests/indexes/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 2fb95942b08db..294307f14dfd5 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -795,6 +795,12 @@ def test_inv(self, simple_index): with pytest.raises(TypeError, match=msg): ~Series(idx) + 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 7cf1e43de262fbcc6c24e1ff66b11e7f9cfc186f Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 09:12:25 +0500 Subject: [PATCH 03/12] changes made to doc/source/whatsnew/2.0.0.rst for indicating deprecation of Index.is_categorical' --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 139a00b9df4d6..76522b23e066c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -416,7 +416,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) .. --------------------------------------------------------------------------- From 1566fc2f23423a7764d1f1542d4457410b61ade5 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 10:51:11 +0500 Subject: [PATCH 04/12] fixes in pandas/core/indexes/base.py in class Index --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index af82f251a209c..026a63f9e5824 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2390,9 +2390,9 @@ def is_categorical(self) -> bool: """ Check if the Index holds categorical data. - .. deprecated:: 1.3.0 + .. deprecated:: 2.0.0 - Use :meth:`is_categorical_dtype` instead. + Use `pandas.api.types.is_bool_dtype` Returns ------- From 52bda61d91fd52ab254063cb1645ea3d588eda37 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 10:52:39 +0500 Subject: [PATCH 05/12] fixes in pandas/core/indexes/base.py in class Index --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 026a63f9e5824..588a93b3963d8 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -23,7 +23,7 @@ import numpy as np -import pandas.api.types + from pandas._config import get_option from pandas._libs import ( From 7f2f7d8fb940580c5ff5b08220538681d5e34580 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 11:55:48 +0500 Subject: [PATCH 06/12] minor fixes in pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 588a93b3963d8..eb6271624c3d4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2392,7 +2392,7 @@ def is_categorical(self) -> bool: .. deprecated:: 2.0.0 - Use `pandas.api.types.is_bool_dtype` + Use `pandas.api.types.is_categorical_dtype` instead. Returns ------- From b2bea33c3865547d8d39467aa3ed7c1f7ea4614e Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 08:57:26 +0500 Subject: [PATCH 07/12] changes made to pandas/core/indexes/base.py in class Index for is_categorical --- pandas/core/indexes/base.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0959f44e62576..af82f251a209c 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -23,6 +23,7 @@ import numpy as np +import pandas.api.types from pandas._config import get_option from pandas._libs import ( @@ -2204,7 +2205,7 @@ def is_boolean(self) -> bool: is_floating : Check if the Index is a floating type. 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 @@ -2239,7 +2240,7 @@ def is_integer(self) -> bool: is_floating : Check if the Index is a floating type. 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 @@ -2278,7 +2279,7 @@ def is_floating(self) -> bool: is_integer : Check if the Index only consists of integers. 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 @@ -2317,7 +2318,7 @@ def is_numeric(self) -> bool: is_integer : Check if the Index only consists of integers. is_floating : Check if the Index is a floating type. 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 @@ -2360,7 +2361,7 @@ def is_object(self) -> bool: is_integer : Check if the Index only consists of integers. is_floating : Check if the Index is a floating type. 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 @@ -2389,6 +2390,10 @@ def is_categorical(self) -> bool: """ Check if the Index holds categorical data. + .. deprecated:: 1.3.0 + + Use :meth:`is_categorical_dtype` instead. + Returns ------- bool @@ -2425,6 +2430,12 @@ 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 @@ -2445,7 +2456,7 @@ def is_interval(self) -> bool: is_floating : Check if the Index is a floating type. 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 -------- From 5c274e8d9a39bd0677a34b99ef714dca95d67acc Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 09:05:03 +0500 Subject: [PATCH 08/12] changes made to pandas/tests/indexes/common.py in class Base sdded 'test_is_categorical_is_deprecated' --- pandas/tests/indexes/common.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 2fb95942b08db..294307f14dfd5 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -795,6 +795,12 @@ def test_inv(self, simple_index): with pytest.raises(TypeError, match=msg): ~Series(idx) + 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 a5616c7ef64e030f6f12ae64fb3c6ad5d71be049 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 09:12:25 +0500 Subject: [PATCH 09/12] changes made to doc/source/whatsnew/2.0.0.rst for indicating deprecation of Index.is_categorical' --- doc/source/whatsnew/v2.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 3d0d6bc5d27f2..269c042ae4812 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -453,7 +453,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) .. --------------------------------------------------------------------------- From 6216682f30e282164dd845fbd55edcb6da14857f Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 10:51:11 +0500 Subject: [PATCH 10/12] fixes in pandas/core/indexes/base.py in class Index --- pandas/core/indexes/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index af82f251a209c..026a63f9e5824 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2390,9 +2390,9 @@ def is_categorical(self) -> bool: """ Check if the Index holds categorical data. - .. deprecated:: 1.3.0 + .. deprecated:: 2.0.0 - Use :meth:`is_categorical_dtype` instead. + Use `pandas.api.types.is_bool_dtype` Returns ------- From 4a73719a50115bb508586d0b43247bad8508e329 Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 10:52:39 +0500 Subject: [PATCH 11/12] fixes in pandas/core/indexes/base.py in class Index --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 026a63f9e5824..588a93b3963d8 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -23,7 +23,7 @@ import numpy as np -import pandas.api.types + from pandas._config import get_option from pandas._libs import ( From 9a54f51d634f4f382b3a1a33d8ae99f4d1d4451d Mon Sep 17 00:00:00 2001 From: ShisuiUzumaki Date: Tue, 13 Dec 2022 11:55:48 +0500 Subject: [PATCH 12/12] minor fixes in pandas/core/indexes/base.py --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 588a93b3963d8..eb6271624c3d4 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2392,7 +2392,7 @@ def is_categorical(self) -> bool: .. deprecated:: 2.0.0 - Use `pandas.api.types.is_bool_dtype` + Use `pandas.api.types.is_categorical_dtype` instead. Returns -------