Skip to content

Commit e1a2973

Browse files
committed
unrelated changes removed
1 parent a5cbd1e commit e1a2973

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

doc/source/whatsnew/v2.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ Other API changes
491491

492492
Deprecations
493493
~~~~~~~~~~~~
494-
- Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`)
494+
495+
- :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`)
495496

496497
.. ---------------------------------------------------------------------------
497498

pandas/core/indexes/base.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,7 @@ def is_integer(self) -> bool:
22382238
is_floating : Check if the Index is a floating type.
22392239
is_numeric : Check if the Index only consists of numeric data.
22402240
is_object : Check if the Index is of the object dtype.
2241-
is_categorical : Check if the Index holds categorical data.
2241+
is_categorical : Check if the Index holds categorical data (deprecated).
22422242
is_interval : Check if the Index holds Interval objects.
22432243
22442244
Examples
@@ -2277,7 +2277,7 @@ def is_floating(self) -> bool:
22772277
is_integer : Check if the Index only consists of integers.
22782278
is_numeric : Check if the Index only consists of numeric data.
22792279
is_object : Check if the Index is of the object dtype.
2280-
is_categorical : Check if the Index holds categorical data.
2280+
is_categorical : Check if the Index holds categorical data (deprecated).
22812281
is_interval : Check if the Index holds Interval objects.
22822282
22832283
Examples
@@ -2316,7 +2316,7 @@ def is_numeric(self) -> bool:
23162316
is_integer : Check if the Index only consists of integers.
23172317
is_floating : Check if the Index is a floating type.
23182318
is_object : Check if the Index is of the object dtype.
2319-
is_categorical : Check if the Index holds categorical data.
2319+
is_categorical : Check if the Index holds categorical data (deprecated).
23202320
is_interval : Check if the Index holds Interval objects.
23212321
23222322
Examples
@@ -2359,7 +2359,7 @@ def is_object(self) -> bool:
23592359
is_integer : Check if the Index only consists of integers.
23602360
is_floating : Check if the Index is a floating type.
23612361
is_numeric : Check if the Index only consists of numeric data.
2362-
is_categorical : Check if the Index holds categorical data.
2362+
is_categorical : Check if the Index holds categorical data (deprecated).
23632363
is_interval : Check if the Index holds Interval objects.
23642364
23652365
Examples
@@ -2388,6 +2388,9 @@ def is_categorical(self) -> bool:
23882388
"""
23892389
Check if the Index holds categorical data.
23902390
2391+
.. deprecated:: 2.0.0
2392+
Use :meth:`pandas.api.types.is_categorical_dtype` instead.
2393+
23912394
Returns
23922395
-------
23932396
bool
@@ -2424,6 +2427,12 @@ def is_categorical(self) -> bool:
24242427
>>> s.index.is_categorical()
24252428
False
24262429
"""
2430+
warnings.warn(
2431+
f"{type(self).__name__}.is_categorical is deprecated."
2432+
"Use pandas.api.types.is_categorical_dtype instead",
2433+
FutureWarning,
2434+
stacklevel=find_stack_level(),
2435+
)
24272436
return self.inferred_type in ["categorical"]
24282437

24292438
@final
@@ -2444,7 +2453,7 @@ def is_interval(self) -> bool:
24442453
is_floating : Check if the Index is a floating type.
24452454
is_numeric : Check if the Index only consists of numeric data.
24462455
is_object : Check if the Index is of the object dtype.
2447-
is_categorical : Check if the Index holds categorical data.
2456+
is_categorical : Check if the Index holds categorical data (deprecated).
24482457
24492458
Examples
24502459
--------
@@ -5014,7 +5023,11 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
50145023
50155024
https://github.com/pandas-dev/pandas/issues/19764
50165025
"""
5017-
if self.is_object() or is_string_dtype(self.dtype) or self.is_categorical():
5026+
if (
5027+
self.is_object()
5028+
or is_string_dtype(self.dtype)
5029+
or is_categorical_dtype(self)
5030+
):
50185031
return name in self
50195032
return False
50205033

pandas/tests/indexes/common.py

+6
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ def test_inv(self, simple_index):
795795
with pytest.raises(TypeError, match=msg):
796796
~Series(idx)
797797

798+
def test_is_categorical_is_deprecated(self, simple_index):
799+
# GH50042
800+
idx = simple_index
801+
with tm.assert_produces_warning(FutureWarning):
802+
idx.is_categorical()
803+
798804

799805
class NumericBase(Base):
800806
"""

0 commit comments

Comments
 (0)