Skip to content

Commit d2acdee

Browse files
authored
DEPR: Enforce is_extension_type removal (#48822)
* DEPR: Enforce is_extension_type removal * Add typing * import future * Add whatsnew
1 parent a04754e commit d2acdee

File tree

8 files changed

+5
-102
lines changed

8 files changed

+5
-102
lines changed

doc/source/reference/arrays.rst

-1
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,6 @@ Data type introspection
630630
api.types.is_datetime64_dtype
631631
api.types.is_datetime64_ns_dtype
632632
api.types.is_datetime64tz_dtype
633-
api.types.is_extension_type
634633
api.types.is_extension_array_dtype
635634
api.types.is_float_dtype
636635
api.types.is_int64_dtype

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Deprecations
145145
Removal of prior version deprecations/changes
146146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147147
- Disallow passing non-round floats to :class:`Timestamp` with ``unit="M"`` or ``unit="Y"`` (:issue:`47266`)
148+
- Removed :func:`is_extension_type` in favor of :func:`is_extension_array_dtype` (:issue:`29457`)
148149
- Remove :meth:`DataFrameGroupBy.pad` and :meth:`DataFrameGroupBy.backfill` (:issue:`45076`)
149150

150151
.. ---------------------------------------------------------------------------

pandas/conftest.py

-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ def pytest_collection_modifyitems(items, config) -> None:
155155
("Series.append", "The series.append method is deprecated"),
156156
("dtypes.common.is_categorical", "is_categorical is deprecated"),
157157
("Categorical.replace", "Categorical.replace is deprecated"),
158-
("dtypes.common.is_extension_type", "'is_extension_type' is deprecated"),
159158
("Index.is_mixed", "Index.is_mixed is deprecated"),
160159
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
161160
# Docstring divides by zero to show behavior difference

pandas/core/arrays/sparse/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ def map(self: SparseArrayT, mapper) -> SparseArrayT:
13831383
Indices: array([1, 2], dtype=int32)
13841384
"""
13851385
# this is used in apply.
1386-
# We get hit since we're an "is_extension_type" but regular extension
1386+
# We get hit since we're an "is_extension_array_dtype" but regular extension
13871387
# types are not hit. This may be worth adding to the interface.
13881388
if isinstance(mapper, ABCSeries):
13891389
mapper = mapper.to_dict()

pandas/core/dtypes/api.py

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
is_dict_like,
1414
is_dtype_equal,
1515
is_extension_array_dtype,
16-
is_extension_type,
1716
is_file_like,
1817
is_float,
1918
is_float_dtype,
@@ -57,7 +56,6 @@
5756
"is_dict_like",
5857
"is_dtype_equal",
5958
"is_extension_array_dtype",
60-
"is_extension_type",
6159
"is_file_like",
6260
"is_float",
6361
"is_float_dtype",

pandas/core/dtypes/common.py

-66
Original file line numberDiff line numberDiff line change
@@ -1336,71 +1336,6 @@ def is_bool_dtype(arr_or_dtype) -> bool:
13361336
return issubclass(dtype.type, np.bool_)
13371337

13381338

1339-
def is_extension_type(arr) -> bool:
1340-
"""
1341-
Check whether an array-like is of a pandas extension class instance.
1342-
1343-
.. deprecated:: 1.0.0
1344-
Use ``is_extension_array_dtype`` instead.
1345-
1346-
Extension classes include categoricals, pandas sparse objects (i.e.
1347-
classes represented within the pandas library and not ones external
1348-
to it like scipy sparse matrices), and datetime-like arrays.
1349-
1350-
Parameters
1351-
----------
1352-
arr : array-like, scalar
1353-
The array-like to check.
1354-
1355-
Returns
1356-
-------
1357-
boolean
1358-
Whether or not the array-like is of a pandas extension class instance.
1359-
1360-
Examples
1361-
--------
1362-
>>> is_extension_type([1, 2, 3])
1363-
False
1364-
>>> is_extension_type(np.array([1, 2, 3]))
1365-
False
1366-
>>>
1367-
>>> cat = pd.Categorical([1, 2, 3])
1368-
>>>
1369-
>>> is_extension_type(cat)
1370-
True
1371-
>>> is_extension_type(pd.Series(cat))
1372-
True
1373-
>>> is_extension_type(pd.arrays.SparseArray([1, 2, 3]))
1374-
True
1375-
>>> from scipy.sparse import bsr_matrix
1376-
>>> is_extension_type(bsr_matrix([1, 2, 3]))
1377-
False
1378-
>>> is_extension_type(pd.DatetimeIndex([1, 2, 3]))
1379-
False
1380-
>>> is_extension_type(pd.DatetimeIndex([1, 2, 3], tz="US/Eastern"))
1381-
True
1382-
>>>
1383-
>>> dtype = DatetimeTZDtype("ns", tz="US/Eastern")
1384-
>>> s = pd.Series([], dtype=dtype)
1385-
>>> is_extension_type(s)
1386-
True
1387-
"""
1388-
warnings.warn(
1389-
"'is_extension_type' is deprecated and will be removed in a future "
1390-
"version. Use 'is_extension_array_dtype' instead.",
1391-
FutureWarning,
1392-
stacklevel=find_stack_level(),
1393-
)
1394-
1395-
if is_categorical_dtype(arr):
1396-
return True
1397-
elif is_sparse(arr):
1398-
return True
1399-
elif is_datetime64tz_dtype(arr):
1400-
return True
1401-
return False
1402-
1403-
14041339
def is_1d_only_ea_obj(obj: Any) -> bool:
14051340
"""
14061341
ExtensionArray that does not support 2D, or more specifically that does
@@ -1853,7 +1788,6 @@ def is_all_strings(value: ArrayLike) -> bool:
18531788
"is_dtype_equal",
18541789
"is_ea_or_datetimelike_dtype",
18551790
"is_extension_array_dtype",
1856-
"is_extension_type",
18571791
"is_file_like",
18581792
"is_float_dtype",
18591793
"is_int64_dtype",

pandas/tests/api/test_types.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import pandas._testing as tm
24
from pandas.api import types
35
from pandas.tests.api.test_api import Base
@@ -49,7 +51,7 @@ class TestTypes(Base):
4951
"infer_dtype",
5052
"is_extension_array_dtype",
5153
]
52-
deprecated = ["is_extension_type"]
54+
deprecated: list[str] = []
5355
dtypes = ["CategoricalDtype", "DatetimeTZDtype", "PeriodDtype", "IntervalDtype"]
5456

5557
def test_types(self):

pandas/tests/dtypes/test_common.py

-30
Original file line numberDiff line numberDiff line change
@@ -599,36 +599,6 @@ def test_is_bool_dtype_numpy_error():
599599
assert not com.is_bool_dtype("0 - Name")
600600

601601

602-
@pytest.mark.filterwarnings("ignore:'is_extension_type' is deprecated:FutureWarning")
603-
@pytest.mark.parametrize(
604-
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
605-
)
606-
def test_is_extension_type(check_scipy):
607-
assert not com.is_extension_type([1, 2, 3])
608-
assert not com.is_extension_type(np.array([1, 2, 3]))
609-
assert not com.is_extension_type(pd.DatetimeIndex([1, 2, 3]))
610-
611-
cat = pd.Categorical([1, 2, 3])
612-
assert com.is_extension_type(cat)
613-
assert com.is_extension_type(pd.Series(cat))
614-
assert com.is_extension_type(SparseArray([1, 2, 3]))
615-
assert com.is_extension_type(pd.DatetimeIndex(["2000"], tz="US/Eastern"))
616-
617-
dtype = DatetimeTZDtype("ns", tz="US/Eastern")
618-
s = pd.Series([], dtype=dtype)
619-
assert com.is_extension_type(s)
620-
621-
if check_scipy:
622-
import scipy.sparse
623-
624-
assert not com.is_extension_type(scipy.sparse.bsr_matrix([1, 2, 3]))
625-
626-
627-
def test_is_extension_type_deprecation():
628-
with tm.assert_produces_warning(FutureWarning):
629-
com.is_extension_type([1, 2, 3])
630-
631-
632602
@pytest.mark.parametrize(
633603
"check_scipy", [False, pytest.param(True, marks=td.skip_if_no_scipy)]
634604
)

0 commit comments

Comments
 (0)