Skip to content

DEPR: deprecate Index.is_categorical #50225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 20 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2451,6 +2454,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
Expand All @@ -2471,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
--------
Expand Down Expand Up @@ -5033,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.dtype)
):
return name in self
return False

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,15 @@ 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,
match=r"Use pandas\.api\.types\.is_categorical_dtype instead",
):
idx.is_categorical()


class NumericBase(Base):
"""
Expand Down