Skip to content

Commit de78702

Browse files
jbrockmendelMateusz Górski
authored and
Mateusz Górski
committed
DEPR: is_extension_type (pandas-dev#29457)
1 parent 13eca16 commit de78702

File tree

14 files changed

+30
-35
lines changed

14 files changed

+30
-35
lines changed

doc/source/whatsnew/v1.0.0.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ Deprecations
213213
- ``Index.set_value`` has been deprecated. For a given index ``idx``, array ``arr``,
214214
value in ``idx`` of ``idx_val`` and a new value of ``val``, ``idx.set_value(arr, idx_val, val)``
215215
is equivalent to ``arr[idx.get_loc(idx_val)] = val``, which should be used instead (:issue:`28621`).
216-
-
216+
- :func:`is_extension_type` is deprecated, :func:`is_extension_array_dtype` should be used instead (:issue:`29457`)
217+
217218

218219
.. _whatsnew_1000.prior_deprecations:
219220

pandas/core/apply.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pandas.core.dtypes.common import (
99
is_dict_like,
10-
is_extension_type,
10+
is_extension_array_dtype,
1111
is_list_like,
1212
is_sequence,
1313
)
@@ -228,7 +228,7 @@ def apply_standard(self):
228228
# as demonstrated in gh-12244
229229
if (
230230
self.result_type in ["reduce", None]
231-
and not self.dtypes.apply(is_extension_type).any()
231+
and not self.dtypes.apply(is_extension_array_dtype).any()
232232
# Disallow complex_internals since libreduction shortcut
233233
# cannot handle MultiIndex
234234
and not self.agg_axis._has_complex_internals

pandas/core/arrays/datetimes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
is_datetime64_ns_dtype,
3232
is_datetime64tz_dtype,
3333
is_dtype_equal,
34-
is_extension_type,
34+
is_extension_array_dtype,
3535
is_float_dtype,
3636
is_object_dtype,
3737
is_period_dtype,
@@ -2131,7 +2131,7 @@ def maybe_convert_dtype(data, copy):
21312131
data = data.categories.take(data.codes, fill_value=NaT)._values
21322132
copy = False
21332133

2134-
elif is_extension_type(data) and not is_datetime64tz_dtype(data):
2134+
elif is_extension_array_dtype(data) and not is_datetime64tz_dtype(data):
21352135
# Includes categorical
21362136
# TODO: We have no tests for these
21372137
data = np.array(data, dtype=np.object_)

pandas/core/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
is_datetime64_ns_dtype,
2323
is_datetime64tz_dtype,
2424
is_extension_array_dtype,
25-
is_extension_type,
2625
is_list_like,
2726
is_object_dtype,
2827
is_scalar,
@@ -1267,7 +1266,7 @@ def _map_values(self, mapper, na_action=None):
12671266
# use the built in categorical series mapper which saves
12681267
# time by mapping the categories instead of all values
12691268
return self._values.map(mapper)
1270-
if is_extension_type(self.dtype):
1269+
if is_extension_array_dtype(self.dtype):
12711270
values = self._values
12721271
else:
12731272
values = self.values
@@ -1278,7 +1277,8 @@ def _map_values(self, mapper, na_action=None):
12781277
return new_values
12791278

12801279
# we must convert to python types
1281-
if is_extension_type(self.dtype):
1280+
if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"):
1281+
# GH#23179 some EAs do not have `map`
12821282
values = self._values
12831283
if na_action is not None:
12841284
raise NotImplementedError

pandas/core/construction.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
is_categorical_dtype,
2828
is_datetime64_ns_dtype,
2929
is_extension_array_dtype,
30-
is_extension_type,
3130
is_float_dtype,
3231
is_integer_dtype,
3332
is_iterator,
@@ -527,7 +526,7 @@ def _try_cast(
527526
and not (is_iterator(subarr) or isinstance(subarr, np.ndarray))
528527
):
529528
subarr = construct_1d_object_array_from_listlike(subarr)
530-
elif not is_extension_type(subarr):
529+
elif not is_extension_array_dtype(subarr):
531530
subarr = construct_1d_ndarray_preserving_na(subarr, dtype, copy=copy)
532531
except OutOfBoundsDatetime:
533532
# in case of out of bound datetime64 -> always raise

pandas/core/dtypes/cast.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
is_datetime_or_timedelta_dtype,
3030
is_dtype_equal,
3131
is_extension_array_dtype,
32-
is_extension_type,
3332
is_float,
3433
is_float_dtype,
3534
is_integer,
@@ -632,7 +631,7 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False):
632631
if not is_list_like(arr):
633632
arr = [arr]
634633

635-
if pandas_dtype and is_extension_type(arr):
634+
if pandas_dtype and is_extension_array_dtype(arr):
636635
return arr.dtype, arr
637636

638637
elif isinstance(arr, ABCSeries):
@@ -694,7 +693,7 @@ def maybe_upcast(values, fill_value=np.nan, dtype=None, copy=False):
694693
# We allow arbitrary fill values for object dtype
695694
raise ValueError("fill_value must be a scalar")
696695

697-
if is_extension_type(values):
696+
if is_extension_array_dtype(values):
698697
if copy:
699698
values = values.copy()
700699
else:

pandas/core/dtypes/common.py

+8
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,8 @@ def is_extension_type(arr):
16251625
"""
16261626
Check whether an array-like is of a pandas extension class instance.
16271627
1628+
.. deprecated:: 1.0.0
1629+
16281630
Extension classes include categoricals, pandas sparse objects (i.e.
16291631
classes represented within the pandas library and not ones external
16301632
to it like scipy sparse matrices), and datetime-like arrays.
@@ -1667,6 +1669,12 @@ def is_extension_type(arr):
16671669
>>> is_extension_type(s)
16681670
True
16691671
"""
1672+
warnings.warn(
1673+
"'is_extension_type' is deprecated and will be removed in a future "
1674+
"version. Use 'is_extension_array_dtype' instead.",
1675+
FutureWarning,
1676+
stacklevel=2,
1677+
)
16701678

16711679
if is_categorical(arr):
16721680
return True

pandas/core/frame.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
is_dict_like,
7272
is_dtype_equal,
7373
is_extension_array_dtype,
74-
is_extension_type,
7574
is_float_dtype,
7675
is_hashable,
7776
is_integer,
@@ -3658,7 +3657,7 @@ def reindexer(value):
36583657
value = maybe_cast_to_datetime(value, infer_dtype)
36593658

36603659
# return internal types directly
3661-
if is_extension_type(value) or is_extension_array_dtype(value):
3660+
if is_extension_array_dtype(value):
36623661
return value
36633662

36643663
# broadcast across multiple columns if necessary

pandas/core/internals/blocks.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
is_datetime64tz_dtype,
3838
is_dtype_equal,
3939
is_extension_array_dtype,
40-
is_extension_type,
4140
is_float_dtype,
4241
is_integer,
4342
is_integer_dtype,
@@ -2605,10 +2604,6 @@ def should_store(self, value):
26052604
value.dtype.type,
26062605
(np.integer, np.floating, np.complexfloating, np.datetime64, np.bool_),
26072606
)
2608-
or
2609-
# TODO(ExtensionArray): remove is_extension_type
2610-
# when all extension arrays have been ported.
2611-
is_extension_type(value)
26122607
or is_extension_array_dtype(value)
26132608
)
26142609

@@ -3168,7 +3163,7 @@ def _putmask_preserve(nv, n):
31683163
# change the dtype if needed
31693164
dtype, _ = maybe_promote(n.dtype)
31703165

3171-
if is_extension_type(v.dtype) and is_object_dtype(dtype):
3166+
if is_extension_array_dtype(v.dtype) and is_object_dtype(dtype):
31723167
v = v._internal_get_values(dtype)
31733168
else:
31743169
v = v.astype(dtype)

pandas/core/internals/managers.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
_NS_DTYPE,
2121
is_datetimelike_v_numeric,
2222
is_extension_array_dtype,
23-
is_extension_type,
2423
is_list_like,
2524
is_numeric_v_string_like,
2625
is_scalar,
@@ -1034,11 +1033,7 @@ def set(self, item, value):
10341033
# FIXME: refactor, clearly separate broadcasting & zip-like assignment
10351034
# can prob also fix the various if tests for sparse/categorical
10361035

1037-
# TODO(EA): Remove an is_extension_ when all extension types satisfy
1038-
# the interface
1039-
value_is_extension_type = is_extension_type(value) or is_extension_array_dtype(
1040-
value
1041-
)
1036+
value_is_extension_type = is_extension_array_dtype(value)
10421037

10431038
# categorical/sparse/datetimetz
10441039
if value_is_extension_type:

pandas/core/reshape/melt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from pandas.util._decorators import Appender
66

7-
from pandas.core.dtypes.common import is_extension_type, is_list_like
7+
from pandas.core.dtypes.common import is_extension_array_dtype, is_list_like
88
from pandas.core.dtypes.concat import concat_compat
99
from pandas.core.dtypes.generic import ABCMultiIndex
1010
from pandas.core.dtypes.missing import notna
@@ -103,7 +103,7 @@ def melt(
103103
mdata = {}
104104
for col in id_vars:
105105
id_data = frame.pop(col)
106-
if is_extension_type(id_data):
106+
if is_extension_array_dtype(id_data):
107107
id_data = concat([id_data] * K, ignore_index=True)
108108
else:
109109
id_data = np.tile(id_data.values, K)

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
is_datetime64_dtype,
2828
is_dict_like,
2929
is_extension_array_dtype,
30-
is_extension_type,
3130
is_integer,
3231
is_iterator,
3332
is_list_like,
@@ -3957,7 +3956,8 @@ def f(x):
39573956
return f(self)
39583957

39593958
# row-wise access
3960-
if is_extension_type(self.dtype):
3959+
if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"):
3960+
# GH#23179 some EAs do not have `map`
39613961
mapped = self._values.map(f)
39623962
else:
39633963
values = self.astype(object).values

pandas/io/pytables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
is_categorical_dtype,
2727
is_datetime64_dtype,
2828
is_datetime64tz_dtype,
29-
is_extension_type,
29+
is_extension_array_dtype,
3030
is_list_like,
3131
is_timedelta64_dtype,
3232
)
@@ -2827,7 +2827,7 @@ def write_multi_index(self, key, index):
28272827
zip(index.levels, index.codes, index.names)
28282828
):
28292829
# write the level
2830-
if is_extension_type(lev):
2830+
if is_extension_array_dtype(lev):
28312831
raise NotImplementedError(
28322832
"Saving a MultiIndex with an extension dtype is not supported."
28332833
)

pandas/tests/api/test_types.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class TestTypes(Base):
1818
"is_datetime64_ns_dtype",
1919
"is_datetime64tz_dtype",
2020
"is_dtype_equal",
21-
"is_extension_type",
2221
"is_float",
2322
"is_float_dtype",
2423
"is_int64_dtype",
@@ -51,7 +50,7 @@ class TestTypes(Base):
5150
"infer_dtype",
5251
"is_extension_array_dtype",
5352
]
54-
deprecated = ["is_period", "is_datetimetz"]
53+
deprecated = ["is_period", "is_datetimetz", "is_extension_type"]
5554
dtypes = ["CategoricalDtype", "DatetimeTZDtype", "PeriodDtype", "IntervalDtype"]
5655

5756
def test_types(self):

0 commit comments

Comments
 (0)