Skip to content

Commit b1b583b

Browse files
authored
DEPR: Categorical, Index (#49220)
* DEPR: Categorical, Index * mypy fixup
1 parent 1425ba0 commit b1b583b

File tree

17 files changed

+23
-200
lines changed

17 files changed

+23
-200
lines changed

doc/redirects.csv

-3
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ generated/pandas.Index.argmax,../reference/api/pandas.Index.argmax
637637
generated/pandas.Index.argmin,../reference/api/pandas.Index.argmin
638638
generated/pandas.Index.argsort,../reference/api/pandas.Index.argsort
639639
generated/pandas.Index.array,../reference/api/pandas.Index.array
640-
generated/pandas.Index.asi8,../reference/api/pandas.Index.asi8
641640
generated/pandas.Index.asof,../reference/api/pandas.Index.asof
642641
generated/pandas.Index.asof_locs,../reference/api/pandas.Index.asof_locs
643642
generated/pandas.Index.astype,../reference/api/pandas.Index.astype
@@ -680,15 +679,13 @@ generated/pandas.Index.isin,../reference/api/pandas.Index.isin
680679
generated/pandas.Index.is_integer,../reference/api/pandas.Index.is_integer
681680
generated/pandas.Index.is_interval,../reference/api/pandas.Index.is_interval
682681
generated/pandas.Index.is_lexsorted_for_tuple,../reference/api/pandas.Index.is_lexsorted_for_tuple
683-
generated/pandas.Index.is_mixed,../reference/api/pandas.Index.is_mixed
684682
generated/pandas.Index.is_monotonic_decreasing,../reference/api/pandas.Index.is_monotonic_decreasing
685683
generated/pandas.Index.is_monotonic,../reference/api/pandas.Index.is_monotonic
686684
generated/pandas.Index.is_monotonic_increasing,../reference/api/pandas.Index.is_monotonic_increasing
687685
generated/pandas.Index.isna,../reference/api/pandas.Index.isna
688686
generated/pandas.Index.isnull,../reference/api/pandas.Index.isnull
689687
generated/pandas.Index.is_numeric,../reference/api/pandas.Index.is_numeric
690688
generated/pandas.Index.is_object,../reference/api/pandas.Index.is_object
691-
generated/pandas.Index.is_type_compatible,../reference/api/pandas.Index.is_type_compatible
692689
generated/pandas.Index.is_unique,../reference/api/pandas.Index.is_unique
693690
generated/pandas.Index.item,../reference/api/pandas.Index.item
694691
generated/pandas.Index.join,../reference/api/pandas.Index.join

doc/source/reference/index.rst

-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ public functions related to data types in pandas.
4747
..
4848
.. toctree::
4949
50-
api/pandas.Index.asi8
5150
api/pandas.Index.holds_integer
52-
api/pandas.Index.is_type_compatible
5351
api/pandas.Index.nlevels
5452
api/pandas.Index.sort
5553

doc/source/reference/indexing.rst

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ Modifying and computations
6868
Index.is_floating
6969
Index.is_integer
7070
Index.is_interval
71-
Index.is_mixed
7271
Index.is_numeric
7372
Index.is_object
7473
Index.min

doc/source/whatsnew/v2.0.0.rst

+8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ Deprecations
156156

157157
Removal of prior version deprecations/changes
158158
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
159+
- Removed deprecated :meth:`Categorical.to_dense`, use ``np.asarray(cat)`` instead (:issue:`32639`)
160+
- Removed deprecated :meth:`Categorical.take_nd` (:issue:`27745`)
161+
- Removed deprecated :meth:`Categorical.mode`, use ``Series(cat).mode()`` instead (:issue:`45033`)
162+
- Removed deprecated :meth:`Categorical.is_dtype_equal` and :meth:`CategoricalIndex.is_dtype_equal` (:issue:`37545`)
163+
- Removed deprecated :meth:`CategoricalIndex.take_nd` (:issue:`30702`)
164+
- Removed deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
165+
- Removed deprecated :meth:`Index.is_mixed`, check ``index.inferred_type`` directly instead (:issue:`32922`)
166+
- Removed deprecated :meth:`Index.asi8` (:issue:`37877`)
159167
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
160168
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
161169
- Enforced deprecation disallowing using ``.astype`` to convert a ``datetime64[ns]`` :class:`Series`, :class:`DataFrame`, or :class:`DatetimeIndex` to timezone-aware dtype, use ``obj.tz_localize`` or ``ser.dt.tz_localize`` instead (:issue:`39258`)

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-
("Index.is_mixed", "Index.is_mixed is deprecated"),
159158
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
160159
# Docstring divides by zero to show behavior difference
161160
("missing.mask_zero_div_zero", "divide by zero encountered"),

pandas/core/arrays/categorical.py

-41
Original file line numberDiff line numberDiff line change
@@ -2052,24 +2052,6 @@ def _values_for_rank(self):
20522052
)
20532053
return values
20542054

2055-
def to_dense(self) -> np.ndarray:
2056-
"""
2057-
Return my 'dense' representation
2058-
2059-
For internal compatibility with numpy arrays.
2060-
2061-
Returns
2062-
-------
2063-
dense : array
2064-
"""
2065-
warn(
2066-
"Categorical.to_dense is deprecated and will be removed in "
2067-
"a future version. Use np.asarray(cat) instead.",
2068-
FutureWarning,
2069-
stacklevel=find_stack_level(),
2070-
)
2071-
return np.asarray(self)
2072-
20732055
# ------------------------------------------------------------------
20742056
# NDArrayBackedExtensionArray compat
20752057

@@ -2101,17 +2083,6 @@ def _unbox_scalar(self, key) -> int:
21012083

21022084
# ------------------------------------------------------------------
21032085

2104-
def take_nd(
2105-
self, indexer, allow_fill: bool = False, fill_value=None
2106-
) -> Categorical:
2107-
# GH#27745 deprecate alias that other EAs dont have
2108-
warn(
2109-
"Categorical.take_nd is deprecated, use Categorical.take instead",
2110-
FutureWarning,
2111-
stacklevel=find_stack_level(),
2112-
)
2113-
return self.take(indexer, allow_fill=allow_fill, fill_value=fill_value)
2114-
21152086
def __iter__(self) -> Iterator:
21162087
"""
21172088
Returns an Iterator over the values of this Categorical.
@@ -2539,18 +2510,6 @@ def _categories_match_up_to_permutation(self, other: Categorical) -> bool:
25392510
"""
25402511
return hash(self.dtype) == hash(other.dtype)
25412512

2542-
def is_dtype_equal(self, other) -> bool:
2543-
warn(
2544-
"Categorical.is_dtype_equal is deprecated and will be removed "
2545-
"in a future version",
2546-
FutureWarning,
2547-
stacklevel=find_stack_level(),
2548-
)
2549-
try:
2550-
return self._categories_match_up_to_permutation(other)
2551-
except (AttributeError, TypeError):
2552-
return False
2553-
25542513
def describe(self) -> DataFrame:
25552514
"""
25562515
Describes this Categorical

pandas/core/indexes/base.py

-74
Original file line numberDiff line numberDiff line change
@@ -680,23 +680,6 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
680680
See each method's docstring.
681681
"""
682682

683-
@property
684-
def asi8(self):
685-
"""
686-
Integer representation of the values.
687-
688-
Returns
689-
-------
690-
ndarray
691-
An ndarray with int64 dtype.
692-
"""
693-
warnings.warn(
694-
"Index.asi8 is deprecated and will be removed in a future version.",
695-
FutureWarning,
696-
stacklevel=find_stack_level(),
697-
)
698-
return None
699-
700683
@classmethod
701684
def _simple_new(cls: type[_IndexT], values, name: Hashable = None) -> _IndexT:
702685
"""
@@ -2451,7 +2434,6 @@ def is_boolean(self) -> bool:
24512434
is_object : Check if the Index is of the object dtype.
24522435
is_categorical : Check if the Index holds categorical data.
24532436
is_interval : Check if the Index holds Interval objects.
2454-
is_mixed : Check if the Index holds data with mixed data types.
24552437
24562438
Examples
24572439
--------
@@ -2487,7 +2469,6 @@ def is_integer(self) -> bool:
24872469
is_object : Check if the Index is of the object dtype.
24882470
is_categorical : Check if the Index holds categorical data.
24892471
is_interval : Check if the Index holds Interval objects.
2490-
is_mixed : Check if the Index holds data with mixed data types.
24912472
24922473
Examples
24932474
--------
@@ -2527,7 +2508,6 @@ def is_floating(self) -> bool:
25272508
is_object : Check if the Index is of the object dtype.
25282509
is_categorical : Check if the Index holds categorical data.
25292510
is_interval : Check if the Index holds Interval objects.
2530-
is_mixed : Check if the Index holds data with mixed data types.
25312511
25322512
Examples
25332513
--------
@@ -2567,7 +2547,6 @@ def is_numeric(self) -> bool:
25672547
is_object : Check if the Index is of the object dtype.
25682548
is_categorical : Check if the Index holds categorical data.
25692549
is_interval : Check if the Index holds Interval objects.
2570-
is_mixed : Check if the Index holds data with mixed data types.
25712550
25722551
Examples
25732552
--------
@@ -2611,7 +2590,6 @@ def is_object(self) -> bool:
26112590
is_numeric : Check if the Index only consists of numeric data.
26122591
is_categorical : Check if the Index holds categorical data.
26132592
is_interval : Check if the Index holds Interval objects.
2614-
is_mixed : Check if the Index holds data with mixed data types.
26152593
26162594
Examples
26172595
--------
@@ -2653,7 +2631,6 @@ def is_categorical(self) -> bool:
26532631
is_numeric : Check if the Index only consists of numeric data.
26542632
is_object : Check if the Index is of the object dtype.
26552633
is_interval : Check if the Index holds Interval objects.
2656-
is_mixed : Check if the Index holds data with mixed data types.
26572634
26582635
Examples
26592636
--------
@@ -2697,7 +2674,6 @@ def is_interval(self) -> bool:
26972674
is_numeric : Check if the Index only consists of numeric data.
26982675
is_object : Check if the Index is of the object dtype.
26992676
is_categorical : Check if the Index holds categorical data.
2700-
is_mixed : Check if the Index holds data with mixed data types.
27012677
27022678
Examples
27032679
--------
@@ -2712,44 +2688,6 @@ def is_interval(self) -> bool:
27122688
"""
27132689
return self.inferred_type in ["interval"]
27142690

2715-
@final
2716-
def is_mixed(self) -> bool:
2717-
"""
2718-
Check if the Index holds data with mixed data types.
2719-
2720-
Returns
2721-
-------
2722-
bool
2723-
Whether or not the Index holds data with mixed data types.
2724-
2725-
See Also
2726-
--------
2727-
is_boolean : Check if the Index only consists of booleans.
2728-
is_integer : Check if the Index only consists of integers.
2729-
is_floating : Check if the Index is a floating type.
2730-
is_numeric : Check if the Index only consists of numeric data.
2731-
is_object : Check if the Index is of the object dtype.
2732-
is_categorical : Check if the Index holds categorical data.
2733-
is_interval : Check if the Index holds Interval objects.
2734-
2735-
Examples
2736-
--------
2737-
>>> idx = pd.Index(['a', np.nan, 'b'])
2738-
>>> idx.is_mixed()
2739-
True
2740-
2741-
>>> idx = pd.Index([1.0, 2.0, 3.0, 5.0])
2742-
>>> idx.is_mixed()
2743-
False
2744-
"""
2745-
warnings.warn(
2746-
"Index.is_mixed is deprecated and will be removed in a future version. "
2747-
"Check index.inferred_type directly instead.",
2748-
FutureWarning,
2749-
stacklevel=find_stack_level(),
2750-
)
2751-
return self.inferred_type in ["mixed"]
2752-
27532691
@final
27542692
def holds_integer(self) -> bool:
27552693
"""
@@ -5312,18 +5250,6 @@ def _is_memory_usage_qualified(self) -> bool:
53125250
"""
53135251
return self.is_object()
53145252

5315-
def is_type_compatible(self, kind: str_t) -> bool:
5316-
"""
5317-
Whether the index type is compatible with the provided type.
5318-
"""
5319-
warnings.warn(
5320-
"Index.is_type_compatible is deprecated and will be removed in a "
5321-
"future version.",
5322-
FutureWarning,
5323-
stacklevel=find_stack_level(),
5324-
)
5325-
return kind == self.inferred_type
5326-
53275253
def __contains__(self, key: Any) -> bool:
53285254
"""
53295255
Return a boolean indicating whether the provided key is in the index.

pandas/core/indexes/category.py

-11
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"ordered",
6262
"_reverse_indexer",
6363
"searchsorted",
64-
"is_dtype_equal",
6564
"min",
6665
"max",
6766
],
@@ -489,16 +488,6 @@ def _maybe_cast_listlike_indexer(self, values) -> CategoricalIndex:
489488
def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
490489
return self.categories._is_comparable_dtype(dtype)
491490

492-
def take_nd(self, *args, **kwargs) -> CategoricalIndex:
493-
"""Alias for `take`"""
494-
warnings.warn(
495-
"CategoricalIndex.take_nd is deprecated, use CategoricalIndex.take "
496-
"instead.",
497-
FutureWarning,
498-
stacklevel=find_stack_level(),
499-
)
500-
return self.take(*args, **kwargs)
501-
502491
def map(self, mapper):
503492
"""
504493
Map values using input an input mapping or function.

pandas/core/indexes/datetimelike.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
cast,
1414
final,
1515
)
16-
import warnings
1716

1817
import numpy as np
1918

@@ -29,14 +28,16 @@
2928
parsing,
3029
to_offset,
3130
)
32-
from pandas._typing import Axis
31+
from pandas._typing import (
32+
Axis,
33+
npt,
34+
)
3335
from pandas.compat.numpy import function as nv
3436
from pandas.util._decorators import (
3537
Appender,
3638
cache_readonly,
3739
doc,
3840
)
39-
from pandas.util._exceptions import find_stack_level
4041

4142
from pandas.core.dtypes.common import (
4243
is_categorical_dtype,
@@ -80,7 +81,7 @@
8081
DatetimeLikeArrayMixin,
8182
cache=True,
8283
)
83-
@inherit_names(["mean", "asi8", "freq", "freqstr"], DatetimeLikeArrayMixin)
84+
@inherit_names(["mean", "freq", "freqstr"], DatetimeLikeArrayMixin)
8485
class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
8586
"""
8687
Common ops mixin to support a unified interface datetimelike Index.
@@ -93,6 +94,10 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
9394
freqstr: str | None
9495
_resolution_obj: Resolution
9596

97+
@property
98+
def asi8(self) -> npt.NDArray[np.int64]:
99+
return self._data.asi8
100+
96101
# ------------------------------------------------------------------------
97102

98103
@cache_readonly
@@ -394,15 +399,6 @@ def _with_freq(self, freq):
394399
arr = self._data._with_freq(freq)
395400
return type(self)._simple_new(arr, name=self._name)
396401

397-
def is_type_compatible(self, kind: str) -> bool:
398-
warnings.warn(
399-
f"{type(self).__name__}.is_type_compatible is deprecated and will be "
400-
"removed in a future version.",
401-
FutureWarning,
402-
stacklevel=find_stack_level(),
403-
)
404-
return kind in self._data._infer_matches
405-
406402
@property
407403
def values(self) -> np.ndarray:
408404
# NB: For Datetime64TZ this is lossy

pandas/core/indexes/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def is_full(self) -> bool:
354354
if not self.is_monotonic_increasing:
355355
raise ValueError("Index is not monotonic")
356356
values = self.asi8
357-
return ((values[1:] - values[:-1]) < 2).all()
357+
return bool(((values[1:] - values[:-1]) < 2).all())
358358

359359
@property
360360
def inferred_type(self) -> str:

pandas/core/tools/numeric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def to_numeric(
158158
elif isinstance(arg, ABCIndex):
159159
is_index = True
160160
if needs_i8_conversion(arg.dtype):
161-
values = arg.asi8
161+
values = arg.view("i8")
162162
else:
163163
values = arg.values
164164
elif isinstance(arg, (list, tuple)):

pandas/core/window/rolling.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Hashable,
1717
Iterator,
1818
Sized,
19+
cast,
1920
)
2021
import warnings
2122

@@ -409,7 +410,8 @@ def _insert_on_column(self, result: DataFrame, obj: DataFrame) -> None:
409410
def _index_array(self):
410411
# TODO: why do we get here with e.g. MultiIndex?
411412
if needs_i8_conversion(self._on.dtype):
412-
return self._on.asi8
413+
idx = cast("PeriodIndex | DatetimeIndex | TimedeltaIndex", self._on)
414+
return idx.asi8
413415
return None
414416

415417
def _resolve_output(self, out: DataFrame, obj: DataFrame) -> DataFrame:

0 commit comments

Comments
 (0)