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: is_extension_type #29457

Merged
merged 4 commits into from
Nov 8, 2019
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
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ Deprecations
- ``Index.set_value`` has been deprecated. For a given index ``idx``, array ``arr``,
value in ``idx`` of ``idx_val`` and a new value of ``val``, ``idx.set_value(arr, idx_val, val)``
is equivalent to ``arr[idx.get_loc(idx_val)] = val``, which should be used instead (:issue:`28621`).
-
- :func:`is_extension_type` is deprecated, :func:`is_extension_array_dtype` should be used instead (:issue:`29457`)


.. _whatsnew_1000.prior_deprecations:

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from pandas.core.dtypes.common import (
is_dict_like,
is_extension_type,
is_extension_array_dtype,
is_list_like,
is_sequence,
)
Expand Down Expand Up @@ -230,7 +230,7 @@ def apply_standard(self):
# as demonstrated in gh-12244
if (
self.result_type in ["reduce", None]
and not self.dtypes.apply(is_extension_type).any()
and not self.dtypes.apply(is_extension_array_dtype).any()
# Disallow complex_internals since libreduction shortcut
# cannot handle MultiIndex
and not self.agg_axis._has_complex_internals
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
is_datetime64_ns_dtype,
is_datetime64tz_dtype,
is_dtype_equal,
is_extension_type,
is_extension_array_dtype,
is_float_dtype,
is_object_dtype,
is_period_dtype,
Expand Down Expand Up @@ -2131,7 +2131,7 @@ def maybe_convert_dtype(data, copy):
data = data.categories.take(data.codes, fill_value=NaT)._values
copy = False

elif is_extension_type(data) and not is_datetime64tz_dtype(data):
elif is_extension_array_dtype(data) and not is_datetime64tz_dtype(data):
# Includes categorical
# TODO: We have no tests for these
data = np.array(data, dtype=np.object_)
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
is_datetime64tz_dtype,
is_datetimelike,
is_extension_array_dtype,
is_extension_type,
is_list_like,
is_object_dtype,
is_scalar,
Expand Down Expand Up @@ -1268,7 +1267,7 @@ def _map_values(self, mapper, na_action=None):
# use the built in categorical series mapper which saves
# time by mapping the categories instead of all values
return self._values.map(mapper)
if is_extension_type(self.dtype):
if is_extension_array_dtype(self.dtype):
values = self._values
else:
values = self.values
Expand All @@ -1279,7 +1278,8 @@ def _map_values(self, mapper, na_action=None):
return new_values

# we must convert to python types
if is_extension_type(self.dtype):
if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"):
# GH#23179 some EAs do not have `map`
values = self._values
if na_action is not None:
raise NotImplementedError
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
is_categorical_dtype,
is_datetime64_ns_dtype,
is_extension_array_dtype,
is_extension_type,
is_float_dtype,
is_integer_dtype,
is_iterator,
Expand Down Expand Up @@ -527,7 +526,7 @@ def _try_cast(
and not (is_iterator(subarr) or isinstance(subarr, np.ndarray))
):
subarr = construct_1d_object_array_from_listlike(subarr)
elif not is_extension_type(subarr):
elif not is_extension_array_dtype(subarr):
subarr = construct_1d_ndarray_preserving_na(subarr, dtype, copy=copy)
except OutOfBoundsDatetime:
# in case of out of bound datetime64 -> always raise
Expand Down
5 changes: 2 additions & 3 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
is_datetimelike,
is_dtype_equal,
is_extension_array_dtype,
is_extension_type,
is_float,
is_float_dtype,
is_integer,
Expand Down Expand Up @@ -633,7 +632,7 @@ def infer_dtype_from_array(arr, pandas_dtype: bool = False):
if not is_list_like(arr):
arr = [arr]

if pandas_dtype and is_extension_type(arr):
if pandas_dtype and is_extension_array_dtype(arr):
return arr.dtype, arr

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

if is_extension_type(values):
if is_extension_array_dtype(values):
if copy:
values = values.copy()
else:
Expand Down
8 changes: 8 additions & 0 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,8 @@ def is_extension_type(arr):
"""
Check whether an array-like is of a pandas extension class instance.

.. deprecated:: 1.0.0

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.
Expand Down Expand Up @@ -1716,6 +1718,12 @@ def is_extension_type(arr):
>>> 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=2,
)

if is_categorical(arr):
return True
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
is_dict_like,
is_dtype_equal,
is_extension_array_dtype,
is_extension_type,
is_float_dtype,
is_hashable,
is_integer,
Expand Down Expand Up @@ -3690,7 +3689,7 @@ def reindexer(value):
value = maybe_cast_to_datetime(value, infer_dtype)

# return internal types directly
if is_extension_type(value) or is_extension_array_dtype(value):
if is_extension_array_dtype(value):
return value

# broadcast across multiple columns if necessary
Expand Down
7 changes: 1 addition & 6 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
is_datetime64tz_dtype,
is_dtype_equal,
is_extension_array_dtype,
is_extension_type,
is_float_dtype,
is_integer,
is_integer_dtype,
Expand Down Expand Up @@ -2605,10 +2604,6 @@ def should_store(self, value):
value.dtype.type,
(np.integer, np.floating, np.complexfloating, np.datetime64, np.bool_),
)
or
# TODO(ExtensionArray): remove is_extension_type
# when all extension arrays have been ported.
is_extension_type(value)
or is_extension_array_dtype(value)
)

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

if is_extension_type(v.dtype) and is_object_dtype(dtype):
if is_extension_array_dtype(v.dtype) and is_object_dtype(dtype):
v = v._internal_get_values(dtype)
else:
v = v.astype(dtype)
Expand Down
7 changes: 1 addition & 6 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
_NS_DTYPE,
is_datetimelike_v_numeric,
is_extension_array_dtype,
is_extension_type,
is_list_like,
is_numeric_v_string_like,
is_scalar,
Expand Down Expand Up @@ -1034,11 +1033,7 @@ def set(self, item, value):
# FIXME: refactor, clearly separate broadcasting & zip-like assignment
# can prob also fix the various if tests for sparse/categorical

# TODO(EA): Remove an is_extension_ when all extension types satisfy
# the interface
value_is_extension_type = is_extension_type(value) or is_extension_array_dtype(
value
)
value_is_extension_type = is_extension_array_dtype(value)

# categorical/sparse/datetimetz
if value_is_extension_type:
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/reshape/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pandas.util._decorators import Appender

from pandas.core.dtypes.common import is_extension_type, is_list_like
from pandas.core.dtypes.common import is_extension_array_dtype, is_list_like
from pandas.core.dtypes.concat import concat_compat
from pandas.core.dtypes.generic import ABCMultiIndex
from pandas.core.dtypes.missing import notna
Expand Down Expand Up @@ -103,7 +103,7 @@ def melt(
mdata = {}
for col in id_vars:
id_data = frame.pop(col)
if is_extension_type(id_data):
if is_extension_array_dtype(id_data):
id_data = concat([id_data] * K, ignore_index=True)
else:
id_data = np.tile(id_data.values, K)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
is_datetimelike,
is_dict_like,
is_extension_array_dtype,
is_extension_type,
is_integer,
is_iterator,
is_list_like,
Expand Down Expand Up @@ -3958,7 +3957,8 @@ def f(x):
return f(self)

# row-wise access
if is_extension_type(self.dtype):
if is_extension_array_dtype(self.dtype) and hasattr(self._values, "map"):
# GH#23179 some EAs do not have `map`
mapped = self._values.map(f)
else:
values = self.astype(object).values
Expand Down
4 changes: 2 additions & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
is_categorical_dtype,
is_datetime64_dtype,
is_datetime64tz_dtype,
is_extension_type,
is_extension_array_dtype,
is_list_like,
is_timedelta64_dtype,
)
Expand Down Expand Up @@ -2827,7 +2827,7 @@ def write_multi_index(self, key, index):
zip(index.levels, index.codes, index.names)
):
# write the level
if is_extension_type(lev):
if is_extension_array_dtype(lev):
raise NotImplementedError(
"Saving a MultiIndex with an extension dtype is not supported."
)
Expand Down
3 changes: 1 addition & 2 deletions pandas/tests/api/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class TestTypes(Base):
"is_datetime64_ns_dtype",
"is_datetime64tz_dtype",
"is_dtype_equal",
"is_extension_type",
"is_float",
"is_float_dtype",
"is_int64_dtype",
Expand Down Expand Up @@ -51,7 +50,7 @@ class TestTypes(Base):
"infer_dtype",
"is_extension_array_dtype",
]
deprecated = ["is_period", "is_datetimetz"]
deprecated = ["is_period", "is_datetimetz", "is_extension_type"]
dtypes = ["CategoricalDtype", "DatetimeTZDtype", "PeriodDtype", "IntervalDtype"]

def test_types(self):
Expand Down