Skip to content

Commit 3b17ce6

Browse files
jbrockmendelnoatamir
authored andcommitted
DEPR: is_categorical (pandas-dev#49253)
1 parent 7e69586 commit 3b17ce6

File tree

9 files changed

+2
-78
lines changed

9 files changed

+2
-78
lines changed

doc/redirects.csv

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ generated/pandas.api.types.infer_dtype,../reference/api/pandas.api.types.infer_d
101101
generated/pandas.api.types.is_bool_dtype,../reference/api/pandas.api.types.is_bool_dtype
102102
generated/pandas.api.types.is_bool,../reference/api/pandas.api.types.is_bool
103103
generated/pandas.api.types.is_categorical_dtype,../reference/api/pandas.api.types.is_categorical_dtype
104-
generated/pandas.api.types.is_categorical,../reference/api/pandas.api.types.is_categorical
105104
generated/pandas.api.types.is_complex_dtype,../reference/api/pandas.api.types.is_complex_dtype
106105
generated/pandas.api.types.is_complex,../reference/api/pandas.api.types.is_complex
107106
generated/pandas.api.types.is_datetime64_any_dtype,../reference/api/pandas.api.types.is_datetime64_any_dtype

doc/source/reference/arrays.rst

-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ Scalar introspection
659659
:toctree: api/
660660

661661
api.types.is_bool
662-
api.types.is_categorical
663662
api.types.is_complex
664663
api.types.is_float
665664
api.types.is_hashable

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Removal of prior version deprecations/changes
164164
- Removed deprecated :meth:`CategoricalIndex.take_nd` (:issue:`30702`)
165165
- Removed deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
166166
- Removed deprecated :meth:`Index.is_mixed`, check ``index.inferred_type`` directly instead (:issue:`32922`)
167+
- Removed deprecated :func:`pandas.api.types.is_categorical`; use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`33385`)
167168
- Removed deprecated :meth:`Index.asi8` (:issue:`37877`)
168169
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
169170
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)

pandas/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def pytest_collection_modifyitems(items, config) -> None:
153153
# Deprecations where the docstring will emit a warning
154154
("DataFrame.append", "The frame.append method is deprecated"),
155155
("Series.append", "The series.append method is deprecated"),
156-
("dtypes.common.is_categorical", "is_categorical is deprecated"),
157156
# Docstring divides by zero to show behavior difference
158157
("missing.mask_zero_div_zero", "divide by zero encountered"),
159158
# Docstring demonstrates the call raises a warning

pandas/core/dtypes/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
is_array_like,
33
is_bool,
44
is_bool_dtype,
5-
is_categorical,
65
is_categorical_dtype,
76
is_complex,
87
is_complex_dtype,
@@ -45,7 +44,6 @@
4544
"is_array_like",
4645
"is_bool",
4746
"is_bool_dtype",
48-
"is_categorical",
4947
"is_categorical_dtype",
5048
"is_complex",
5149
"is_complex_dtype",

pandas/core/dtypes/common.py

+1-48
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Any,
88
Callable,
99
)
10-
import warnings
1110

1211
import numpy as np
1312

@@ -22,7 +21,6 @@
2221
ArrayLike,
2322
DtypeObj,
2423
)
25-
from pandas.util._exceptions import find_stack_level
2624

2725
from pandas.core.dtypes.base import _registry as registry
2826
from pandas.core.dtypes.dtypes import (
@@ -32,10 +30,7 @@
3230
IntervalDtype,
3331
PeriodDtype,
3432
)
35-
from pandas.core.dtypes.generic import (
36-
ABCCategorical,
37-
ABCIndex,
38-
)
33+
from pandas.core.dtypes.generic import ABCIndex
3934
from pandas.core.dtypes.inference import (
4035
is_array_like,
4136
is_bool,
@@ -275,47 +270,6 @@ def is_scipy_sparse(arr) -> bool:
275270
return _is_scipy_sparse(arr)
276271

277272

278-
def is_categorical(arr) -> bool:
279-
"""
280-
Check whether an array-like is a Categorical instance.
281-
282-
.. deprecated:: 1.1.0
283-
Use ``is_categorical_dtype`` instead.
284-
285-
Parameters
286-
----------
287-
arr : array-like
288-
The array-like to check.
289-
290-
Returns
291-
-------
292-
boolean
293-
Whether or not the array-like is of a Categorical instance.
294-
295-
Examples
296-
--------
297-
>>> is_categorical([1, 2, 3])
298-
False
299-
300-
Categoricals, Series Categoricals, and CategoricalIndex will return True.
301-
302-
>>> cat = pd.Categorical([1, 2, 3])
303-
>>> is_categorical(cat)
304-
True
305-
>>> is_categorical(pd.Series(cat))
306-
True
307-
>>> is_categorical(pd.CategoricalIndex([1, 2, 3]))
308-
True
309-
"""
310-
warnings.warn(
311-
"is_categorical is deprecated and will be removed in a future version. "
312-
"Use is_categorical_dtype instead.",
313-
FutureWarning,
314-
stacklevel=find_stack_level(),
315-
)
316-
return isinstance(arr, ABCCategorical) or is_categorical_dtype(arr)
317-
318-
319273
def is_datetime64_dtype(arr_or_dtype) -> bool:
320274
"""
321275
Check whether an array-like or dtype is of the datetime64 dtype.
@@ -1772,7 +1726,6 @@ def is_all_strings(value: ArrayLike) -> bool:
17721726
"is_array_like",
17731727
"is_bool",
17741728
"is_bool_dtype",
1775-
"is_categorical",
17761729
"is_categorical_dtype",
17771730
"is_complex",
17781731
"is_complex_dtype",

pandas/tests/api/test_types.py

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class TestTypes(Base):
1010
allowed = [
1111
"is_bool",
1212
"is_bool_dtype",
13-
"is_categorical",
1413
"is_categorical_dtype",
1514
"is_complex",
1615
"is_complex_dtype",

pandas/tests/dtypes/test_common.py

-16
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,6 @@ def test_is_scipy_sparse():
208208
assert not com.is_scipy_sparse(SparseArray([1, 2, 3]))
209209

210210

211-
def test_is_categorical():
212-
cat = pd.Categorical([1, 2, 3])
213-
with tm.assert_produces_warning(FutureWarning):
214-
assert com.is_categorical(cat)
215-
assert com.is_categorical(pd.Series(cat))
216-
assert com.is_categorical(pd.CategoricalIndex([1, 2, 3]))
217-
218-
assert not com.is_categorical([1, 2, 3])
219-
220-
221-
def test_is_categorical_deprecation():
222-
# GH#33385
223-
with tm.assert_produces_warning(FutureWarning):
224-
com.is_categorical([1, 2, 3])
225-
226-
227211
def test_is_datetime64_dtype():
228212
assert not com.is_datetime64_dtype(object)
229213
assert not com.is_datetime64_dtype([1, 2, 3])

pandas/tests/dtypes/test_dtypes.py

-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pandas.core.dtypes.base import _registry as registry
1010
from pandas.core.dtypes.common import (
1111
is_bool_dtype,
12-
is_categorical,
1312
is_categorical_dtype,
1413
is_datetime64_any_dtype,
1514
is_datetime64_dtype,
@@ -179,13 +178,6 @@ def test_basic(self, dtype):
179178
assert is_categorical_dtype(s)
180179
assert not is_categorical_dtype(np.dtype("float64"))
181180

182-
with tm.assert_produces_warning(FutureWarning):
183-
# GH#33385 deprecated
184-
assert is_categorical(s.dtype)
185-
assert is_categorical(s)
186-
assert not is_categorical(np.dtype("float64"))
187-
assert not is_categorical(1.0)
188-
189181
def test_tuple_categories(self):
190182
categories = [(1, "a"), (2, "b"), (3, "c")]
191183
result = CategoricalDtype(categories)

0 commit comments

Comments
 (0)