Skip to content

DEPR: is_categorical #49253

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 2 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 0 additions & 1 deletion doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ generated/pandas.api.types.infer_dtype,../reference/api/pandas.api.types.infer_d
generated/pandas.api.types.is_bool_dtype,../reference/api/pandas.api.types.is_bool_dtype
generated/pandas.api.types.is_bool,../reference/api/pandas.api.types.is_bool
generated/pandas.api.types.is_categorical_dtype,../reference/api/pandas.api.types.is_categorical_dtype
generated/pandas.api.types.is_categorical,../reference/api/pandas.api.types.is_categorical
generated/pandas.api.types.is_complex_dtype,../reference/api/pandas.api.types.is_complex_dtype
generated/pandas.api.types.is_complex,../reference/api/pandas.api.types.is_complex
generated/pandas.api.types.is_datetime64_any_dtype,../reference/api/pandas.api.types.is_datetime64_any_dtype
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/arrays.rst
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,6 @@ Scalar introspection
:toctree: api/

api.types.is_bool
api.types.is_categorical
api.types.is_complex
api.types.is_float
api.types.is_hashable
Expand Down
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 @@ -164,6 +164,7 @@ Removal of prior version deprecations/changes
- Removed deprecated :meth:`CategoricalIndex.take_nd` (:issue:`30702`)
- Removed deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
- Removed deprecated :meth:`Index.is_mixed`, check ``index.inferred_type`` directly instead (:issue:`32922`)
- Removed deprecated :func:`pandas.api.types.is_categorical`; use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`33385`)
- Removed deprecated :meth:`Index.asi8` (:issue:`37877`)
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
Expand Down
1 change: 0 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def pytest_collection_modifyitems(items, config) -> None:
# Deprecations where the docstring will emit a warning
("DataFrame.append", "The frame.append method is deprecated"),
("Series.append", "The series.append method is deprecated"),
("dtypes.common.is_categorical", "is_categorical is deprecated"),
("Categorical.replace", "Categorical.replace is deprecated"),
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
# Docstring divides by zero to show behavior difference
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/dtypes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
is_array_like,
is_bool,
is_bool_dtype,
is_categorical,
is_categorical_dtype,
is_complex,
is_complex_dtype,
Expand Down Expand Up @@ -45,7 +44,6 @@
"is_array_like",
"is_bool",
"is_bool_dtype",
"is_categorical",
"is_categorical_dtype",
"is_complex",
"is_complex_dtype",
Expand Down
49 changes: 1 addition & 48 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Any,
Callable,
)
import warnings

import numpy as np

Expand All @@ -22,7 +21,6 @@
ArrayLike,
DtypeObj,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.base import _registry as registry
from pandas.core.dtypes.dtypes import (
Expand All @@ -32,10 +30,7 @@
IntervalDtype,
PeriodDtype,
)
from pandas.core.dtypes.generic import (
ABCCategorical,
ABCIndex,
)
from pandas.core.dtypes.generic import ABCIndex
from pandas.core.dtypes.inference import (
is_array_like,
is_bool,
Expand Down Expand Up @@ -275,47 +270,6 @@ def is_scipy_sparse(arr) -> bool:
return _is_scipy_sparse(arr)


def is_categorical(arr) -> bool:
"""
Check whether an array-like is a Categorical instance.

.. deprecated:: 1.1.0
Use ``is_categorical_dtype`` instead.

Parameters
----------
arr : array-like
The array-like to check.

Returns
-------
boolean
Whether or not the array-like is of a Categorical instance.

Examples
--------
>>> is_categorical([1, 2, 3])
False

Categoricals, Series Categoricals, and CategoricalIndex will return True.

>>> cat = pd.Categorical([1, 2, 3])
>>> is_categorical(cat)
True
>>> is_categorical(pd.Series(cat))
True
>>> is_categorical(pd.CategoricalIndex([1, 2, 3]))
True
"""
warnings.warn(
"is_categorical is deprecated and will be removed in a future version. "
"Use is_categorical_dtype instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return isinstance(arr, ABCCategorical) or is_categorical_dtype(arr)


def is_datetime64_dtype(arr_or_dtype) -> bool:
"""
Check whether an array-like or dtype is of the datetime64 dtype.
Expand Down Expand Up @@ -1772,7 +1726,6 @@ def is_all_strings(value: ArrayLike) -> bool:
"is_array_like",
"is_bool",
"is_bool_dtype",
"is_categorical",
"is_categorical_dtype",
"is_complex",
"is_complex_dtype",
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/api/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TestTypes(Base):
allowed = [
"is_bool",
"is_bool_dtype",
"is_categorical",
"is_categorical_dtype",
"is_complex",
"is_complex_dtype",
Expand Down
16 changes: 0 additions & 16 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,6 @@ def test_is_scipy_sparse():
assert not com.is_scipy_sparse(SparseArray([1, 2, 3]))


def test_is_categorical():
cat = pd.Categorical([1, 2, 3])
with tm.assert_produces_warning(FutureWarning):
assert com.is_categorical(cat)
assert com.is_categorical(pd.Series(cat))
assert com.is_categorical(pd.CategoricalIndex([1, 2, 3]))

assert not com.is_categorical([1, 2, 3])


def test_is_categorical_deprecation():
# GH#33385
with tm.assert_produces_warning(FutureWarning):
com.is_categorical([1, 2, 3])


def test_is_datetime64_dtype():
assert not com.is_datetime64_dtype(object)
assert not com.is_datetime64_dtype([1, 2, 3])
Expand Down
8 changes: 0 additions & 8 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pandas.core.dtypes.base import _registry as registry
from pandas.core.dtypes.common import (
is_bool_dtype,
is_categorical,
is_categorical_dtype,
is_datetime64_any_dtype,
is_datetime64_dtype,
Expand Down Expand Up @@ -179,13 +178,6 @@ def test_basic(self, dtype):
assert is_categorical_dtype(s)
assert not is_categorical_dtype(np.dtype("float64"))

with tm.assert_produces_warning(FutureWarning):
# GH#33385 deprecated
assert is_categorical(s.dtype)
assert is_categorical(s)
assert not is_categorical(np.dtype("float64"))
assert not is_categorical(1.0)

def test_tuple_categories(self):
categories = [(1, "a"), (2, "b"), (3, "c")]
result = CategoricalDtype(categories)
Expand Down