From d2acdee72b33c8c52bb5f8b902190bbfcf27ca47 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Wed, 19 Oct 2022 14:32:57 -0700 Subject: [PATCH] DEPR: Enforce is_extension_type removal (#48822) * DEPR: Enforce is_extension_type removal * Add typing * import future * Add whatsnew --- doc/source/reference/arrays.rst | 1 - doc/source/whatsnew/v2.0.0.rst | 1 + pandas/conftest.py | 1 - pandas/core/arrays/sparse/array.py | 2 +- pandas/core/dtypes/api.py | 2 - pandas/core/dtypes/common.py | 66 ------------------------------ pandas/tests/api/test_types.py | 4 +- pandas/tests/dtypes/test_common.py | 30 -------------- 8 files changed, 5 insertions(+), 102 deletions(-) diff --git a/doc/source/reference/arrays.rst b/doc/source/reference/arrays.rst index 61ee894f4b126..1011159a9ae5f 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -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 diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index f31f6cb325d2e..d49181238b6bc 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -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`) .. --------------------------------------------------------------------------- diff --git a/pandas/conftest.py b/pandas/conftest.py index 14d156acdf4de..e8f982949677c 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -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 diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 239ad66e3336c..38d3e0d73ef2c 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -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() diff --git a/pandas/core/dtypes/api.py b/pandas/core/dtypes/api.py index e6a59bf12d7cc..0456073eaa7c6 100644 --- a/pandas/core/dtypes/api.py +++ b/pandas/core/dtypes/api.py @@ -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, @@ -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", diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index deaa53f642e4f..61931b2a94490 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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 @@ -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", diff --git a/pandas/tests/api/test_types.py b/pandas/tests/api/test_types.py index 7b6cc9412e03d..80eb9a2593f40 100644 --- a/pandas/tests/api/test_types.py +++ b/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 @@ -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): diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 61c2b58388cc2..9f1ad2840ec87 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -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)] )