Skip to content
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

DEPR: Enforce is_extension_type removal #48822

Merged
merged 6 commits into from
Oct 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/source/reference/arrays.rst
Expand Up @@ -630,7 +630,6 @@ Data type introspection
api.types.is_datetime64_dtype
api.types.is_datetime64_ns_dtype
api.types.is_datetime64tz_dtype
api.types.is_extension_type
api.types.is_extension_array_dtype
api.types.is_float_dtype
api.types.is_int64_dtype
Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Expand Up @@ -145,6 +145,7 @@ Deprecations
Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)

.. ---------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion pandas/conftest.py
Expand Up @@ -155,7 +155,6 @@ def pytest_collection_modifyitems(items, config) -> None:
("Series.append", "The series.append method is deprecated"),
("dtypes.common.is_categorical", "is_categorical is deprecated"),
("Categorical.replace", "Categorical.replace is deprecated"),
("dtypes.common.is_extension_type", "'is_extension_type' is deprecated"),
("Index.is_mixed", "Index.is_mixed is deprecated"),
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
# Docstring divides by zero to show behavior difference
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/array.py
Expand Up @@ -1383,7 +1383,7 @@ def map(self: SparseArrayT, mapper) -> SparseArrayT:
Indices: array([1, 2], dtype=int32)
"""
# this is used in apply.
# We get hit since we're an "is_extension_type" but regular extension
# We get hit since we're an "is_extension_array_dtype" but regular extension
# types are not hit. This may be worth adding to the interface.
if isinstance(mapper, ABCSeries):
mapper = mapper.to_dict()
Expand Down
2 changes: 0 additions & 2 deletions pandas/core/dtypes/api.py
Expand Up @@ -13,7 +13,6 @@
is_dict_like,
is_dtype_equal,
is_extension_array_dtype,
is_extension_type,
is_file_like,
is_float,
is_float_dtype,
Expand Down Expand Up @@ -57,7 +56,6 @@
"is_dict_like",
"is_dtype_equal",
"is_extension_array_dtype",
"is_extension_type",
"is_file_like",
"is_float",
"is_float_dtype",
Expand Down
66 changes: 0 additions & 66 deletions pandas/core/dtypes/common.py
Expand Up @@ -1336,71 +1336,6 @@ def is_bool_dtype(arr_or_dtype) -> bool:
return issubclass(dtype.type, np.bool_)


def is_extension_type(arr) -> bool:
"""
Check whether an array-like is of a pandas extension class instance.

.. deprecated:: 1.0.0
Use ``is_extension_array_dtype`` instead.

Extension classes include categoricals, pandas sparse objects (i.e.
classes represented within the pandas library and not ones external
to it like scipy sparse matrices), and datetime-like arrays.

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

Returns
-------
boolean
Whether or not the array-like is of a pandas extension class instance.

Examples
--------
>>> is_extension_type([1, 2, 3])
False
>>> is_extension_type(np.array([1, 2, 3]))
False
>>>
>>> cat = pd.Categorical([1, 2, 3])
>>>
>>> is_extension_type(cat)
True
>>> is_extension_type(pd.Series(cat))
True
>>> is_extension_type(pd.arrays.SparseArray([1, 2, 3]))
True
>>> from scipy.sparse import bsr_matrix
>>> is_extension_type(bsr_matrix([1, 2, 3]))
False
>>> is_extension_type(pd.DatetimeIndex([1, 2, 3]))
False
>>> is_extension_type(pd.DatetimeIndex([1, 2, 3], tz="US/Eastern"))
True
>>>
>>> dtype = DatetimeTZDtype("ns", tz="US/Eastern")
>>> s = pd.Series([], dtype=dtype)
>>> is_extension_type(s)
True
"""
warnings.warn(
"'is_extension_type' is deprecated and will be removed in a future "
"version. Use 'is_extension_array_dtype' instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

if is_categorical_dtype(arr):
return True
elif is_sparse(arr):
return True
elif is_datetime64tz_dtype(arr):
return True
return False


def is_1d_only_ea_obj(obj: Any) -> bool:
"""
ExtensionArray that does not support 2D, or more specifically that does
Expand Down Expand Up @@ -1853,7 +1788,6 @@ def is_all_strings(value: ArrayLike) -> bool:
"is_dtype_equal",
"is_ea_or_datetimelike_dtype",
"is_extension_array_dtype",
"is_extension_type",
"is_file_like",
"is_float_dtype",
"is_int64_dtype",
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/api/test_types.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import pandas._testing as tm
from pandas.api import types
from pandas.tests.api.test_api import Base
Expand Down Expand Up @@ -49,7 +51,7 @@ class TestTypes(Base):
"infer_dtype",
"is_extension_array_dtype",
]
deprecated = ["is_extension_type"]
deprecated: list[str] = []
dtypes = ["CategoricalDtype", "DatetimeTZDtype", "PeriodDtype", "IntervalDtype"]

def test_types(self):
Expand Down
30 changes: 0 additions & 30 deletions pandas/tests/dtypes/test_common.py
Expand Up @@ -599,36 +599,6 @@ def test_is_bool_dtype_numpy_error():
assert not com.is_bool_dtype("0 - Name")


@pytest.mark.filterwarnings("ignore:'is_extension_type' is deprecated:FutureWarning")
@pytest.mark.parametrize(
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
)
def test_is_extension_type(check_scipy):
assert not com.is_extension_type([1, 2, 3])
assert not com.is_extension_type(np.array([1, 2, 3]))
assert not com.is_extension_type(pd.DatetimeIndex([1, 2, 3]))

cat = pd.Categorical([1, 2, 3])
assert com.is_extension_type(cat)
assert com.is_extension_type(pd.Series(cat))
assert com.is_extension_type(SparseArray([1, 2, 3]))
assert com.is_extension_type(pd.DatetimeIndex(["2000"], tz="US/Eastern"))

dtype = DatetimeTZDtype("ns", tz="US/Eastern")
s = pd.Series([], dtype=dtype)
assert com.is_extension_type(s)

if check_scipy:
import scipy.sparse

assert not com.is_extension_type(scipy.sparse.bsr_matrix([1, 2, 3]))


def test_is_extension_type_deprecation():
with tm.assert_produces_warning(FutureWarning):
com.is_extension_type([1, 2, 3])


@pytest.mark.parametrize(
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
)
Expand Down