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: Categorical, Index #49220

Merged
merged 2 commits into from
Oct 21, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ generated/pandas.Index.argmax,../reference/api/pandas.Index.argmax
generated/pandas.Index.argmin,../reference/api/pandas.Index.argmin
generated/pandas.Index.argsort,../reference/api/pandas.Index.argsort
generated/pandas.Index.array,../reference/api/pandas.Index.array
generated/pandas.Index.asi8,../reference/api/pandas.Index.asi8
generated/pandas.Index.asof,../reference/api/pandas.Index.asof
generated/pandas.Index.asof_locs,../reference/api/pandas.Index.asof_locs
generated/pandas.Index.astype,../reference/api/pandas.Index.astype
Expand Down Expand Up @@ -680,15 +679,13 @@ generated/pandas.Index.isin,../reference/api/pandas.Index.isin
generated/pandas.Index.is_integer,../reference/api/pandas.Index.is_integer
generated/pandas.Index.is_interval,../reference/api/pandas.Index.is_interval
generated/pandas.Index.is_lexsorted_for_tuple,../reference/api/pandas.Index.is_lexsorted_for_tuple
generated/pandas.Index.is_mixed,../reference/api/pandas.Index.is_mixed
generated/pandas.Index.is_monotonic_decreasing,../reference/api/pandas.Index.is_monotonic_decreasing
generated/pandas.Index.is_monotonic,../reference/api/pandas.Index.is_monotonic
generated/pandas.Index.is_monotonic_increasing,../reference/api/pandas.Index.is_monotonic_increasing
generated/pandas.Index.isna,../reference/api/pandas.Index.isna
generated/pandas.Index.isnull,../reference/api/pandas.Index.isnull
generated/pandas.Index.is_numeric,../reference/api/pandas.Index.is_numeric
generated/pandas.Index.is_object,../reference/api/pandas.Index.is_object
generated/pandas.Index.is_type_compatible,../reference/api/pandas.Index.is_type_compatible
generated/pandas.Index.is_unique,../reference/api/pandas.Index.is_unique
generated/pandas.Index.item,../reference/api/pandas.Index.item
generated/pandas.Index.join,../reference/api/pandas.Index.join
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ public functions related to data types in pandas.
..
.. toctree::

api/pandas.Index.asi8
api/pandas.Index.holds_integer
api/pandas.Index.is_type_compatible
api/pandas.Index.nlevels
api/pandas.Index.sort

Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ Modifying and computations
Index.is_floating
Index.is_integer
Index.is_interval
Index.is_mixed
Index.is_numeric
Index.is_object
Index.min
Expand Down
8 changes: 8 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ Deprecations

Removal of prior version deprecations/changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Removed deprecated :meth:`Categorical.to_dense`, use ``np.asarray(cat)`` instead (:issue:`32639`)
- Removed deprecated :meth:`Categorical.take_nd` (:issue:`27745`)
- Removed deprecated :meth:`Categorical.mode`, use ``Series(cat).mode()`` instead (:issue:`45033`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbrockmendel I don't think this was actually removed in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, will make a PR now

- Removed deprecated :meth:`Categorical.is_dtype_equal` and :meth:`CategoricalIndex.is_dtype_equal` (:issue:`37545`)
- Removed deprecated :meth:`CategoricalIndex.take_nd` (:issue:`30702`)
- Removed deprecated :meth:`Index.is_type_compatible` (:issue:`42113`)
- Removed deprecated :meth:`Index.is_mixed`, check ``index.inferred_type`` directly instead (:issue:`32922`)
- Removed deprecated :meth:`Index.asi8` (:issue:`37877`)
- Enforced deprecation disallowing passing a timezone-aware :class:`Timestamp` and ``dtype="datetime64[ns]"`` to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Enforced deprecation disallowing passing a sequence of timezone-aware values and ``dtype="datetime64[ns]"`` to to :class:`Series` or :class:`DataFrame` constructors (:issue:`41555`)
- Removed Date parser functions :func:`~pandas.io.date_converters.parse_date_time`,
Expand Down
1 change: 0 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
("Index.is_mixed", "Index.is_mixed is deprecated"),
("MultiIndex._is_lexsorted", "MultiIndex.is_lexsorted is deprecated"),
# Docstring divides by zero to show behavior difference
("missing.mask_zero_div_zero", "divide by zero encountered"),
Expand Down
41 changes: 0 additions & 41 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,24 +2052,6 @@ def _values_for_rank(self):
)
return values

def to_dense(self) -> np.ndarray:
"""
Return my 'dense' representation

For internal compatibility with numpy arrays.

Returns
-------
dense : array
"""
warn(
"Categorical.to_dense is deprecated and will be removed in "
"a future version. Use np.asarray(cat) instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return np.asarray(self)

# ------------------------------------------------------------------
# NDArrayBackedExtensionArray compat

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

# ------------------------------------------------------------------

def take_nd(
self, indexer, allow_fill: bool = False, fill_value=None
) -> Categorical:
# GH#27745 deprecate alias that other EAs dont have
warn(
"Categorical.take_nd is deprecated, use Categorical.take instead",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.take(indexer, allow_fill=allow_fill, fill_value=fill_value)

def __iter__(self) -> Iterator:
"""
Returns an Iterator over the values of this Categorical.
Expand Down Expand Up @@ -2539,18 +2510,6 @@ def _categories_match_up_to_permutation(self, other: Categorical) -> bool:
"""
return hash(self.dtype) == hash(other.dtype)

def is_dtype_equal(self, other) -> bool:
warn(
"Categorical.is_dtype_equal is deprecated and will be removed "
"in a future version",
FutureWarning,
stacklevel=find_stack_level(),
)
try:
return self._categories_match_up_to_permutation(other)
except (AttributeError, TypeError):
return False

def describe(self) -> DataFrame:
"""
Describes this Categorical
Expand Down
74 changes: 0 additions & 74 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,23 +680,6 @@ def _dtype_to_subclass(cls, dtype: DtypeObj):
See each method's docstring.
"""

@property
def asi8(self):
"""
Integer representation of the values.

Returns
-------
ndarray
An ndarray with int64 dtype.
"""
warnings.warn(
"Index.asi8 is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return None

@classmethod
def _simple_new(cls: type[_IndexT], values, name: Hashable = None) -> _IndexT:
"""
Expand Down Expand Up @@ -2451,7 +2434,6 @@ def is_boolean(self) -> bool:
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2487,7 +2469,6 @@ def is_integer(self) -> bool:
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2527,7 +2508,6 @@ def is_floating(self) -> bool:
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2567,7 +2547,6 @@ def is_numeric(self) -> bool:
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2611,7 +2590,6 @@ def is_object(self) -> bool:
is_numeric : Check if the Index only consists of numeric data.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2653,7 +2631,6 @@ def is_categorical(self) -> bool:
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
is_interval : Check if the Index holds Interval objects.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand Down Expand Up @@ -2697,7 +2674,6 @@ def is_interval(self) -> bool:
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_mixed : Check if the Index holds data with mixed data types.

Examples
--------
Expand All @@ -2712,44 +2688,6 @@ def is_interval(self) -> bool:
"""
return self.inferred_type in ["interval"]

@final
def is_mixed(self) -> bool:
"""
Check if the Index holds data with mixed data types.

Returns
-------
bool
Whether or not the Index holds data with mixed data types.

See Also
--------
is_boolean : Check if the Index only consists of booleans.
is_integer : Check if the Index only consists of integers.
is_floating : Check if the Index is a floating type.
is_numeric : Check if the Index only consists of numeric data.
is_object : Check if the Index is of the object dtype.
is_categorical : Check if the Index holds categorical data.
is_interval : Check if the Index holds Interval objects.

Examples
--------
>>> idx = pd.Index(['a', np.nan, 'b'])
>>> idx.is_mixed()
True

>>> idx = pd.Index([1.0, 2.0, 3.0, 5.0])
>>> idx.is_mixed()
False
"""
warnings.warn(
"Index.is_mixed is deprecated and will be removed in a future version. "
"Check index.inferred_type directly instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.inferred_type in ["mixed"]

@final
def holds_integer(self) -> bool:
"""
Expand Down Expand Up @@ -5312,18 +5250,6 @@ def _is_memory_usage_qualified(self) -> bool:
"""
return self.is_object()

def is_type_compatible(self, kind: str_t) -> bool:
"""
Whether the index type is compatible with the provided type.
"""
warnings.warn(
"Index.is_type_compatible is deprecated and will be removed in a "
"future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return kind == self.inferred_type

def __contains__(self, key: Any) -> bool:
"""
Return a boolean indicating whether the provided key is in the index.
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"ordered",
"_reverse_indexer",
"searchsorted",
"is_dtype_equal",
"min",
"max",
],
Expand Down Expand Up @@ -489,16 +488,6 @@ def _maybe_cast_listlike_indexer(self, values) -> CategoricalIndex:
def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
return self.categories._is_comparable_dtype(dtype)

def take_nd(self, *args, **kwargs) -> CategoricalIndex:
"""Alias for `take`"""
warnings.warn(
"CategoricalIndex.take_nd is deprecated, use CategoricalIndex.take "
"instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self.take(*args, **kwargs)

def map(self, mapper):
"""
Map values using input an input mapping or function.
Expand Down
22 changes: 9 additions & 13 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
cast,
final,
)
import warnings

import numpy as np

Expand All @@ -29,14 +28,16 @@
parsing,
to_offset,
)
from pandas._typing import Axis
from pandas._typing import (
Axis,
npt,
)
from pandas.compat.numpy import function as nv
from pandas.util._decorators import (
Appender,
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_categorical_dtype,
Expand Down Expand Up @@ -80,7 +81,7 @@
DatetimeLikeArrayMixin,
cache=True,
)
@inherit_names(["mean", "asi8", "freq", "freqstr"], DatetimeLikeArrayMixin)
@inherit_names(["mean", "freq", "freqstr"], DatetimeLikeArrayMixin)
class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
"""
Common ops mixin to support a unified interface datetimelike Index.
Expand All @@ -93,6 +94,10 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
freqstr: str | None
_resolution_obj: Resolution

@property
def asi8(self) -> npt.NDArray[np.int64]:
return self._data.asi8

# ------------------------------------------------------------------------

@cache_readonly
Expand Down Expand Up @@ -394,15 +399,6 @@ def _with_freq(self, freq):
arr = self._data._with_freq(freq)
return type(self)._simple_new(arr, name=self._name)

def is_type_compatible(self, kind: str) -> bool:
warnings.warn(
f"{type(self).__name__}.is_type_compatible is deprecated and will be "
"removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return kind in self._data._infer_matches

@property
def values(self) -> np.ndarray:
# NB: For Datetime64TZ this is lossy
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def is_full(self) -> bool:
if not self.is_monotonic_increasing:
raise ValueError("Index is not monotonic")
values = self.asi8
return ((values[1:] - values[:-1]) < 2).all()
return bool(((values[1:] - values[:-1]) < 2).all())

@property
def inferred_type(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/tools/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def to_numeric(
elif isinstance(arg, ABCIndex):
is_index = True
if needs_i8_conversion(arg.dtype):
values = arg.asi8
values = arg.view("i8")
else:
values = arg.values
elif isinstance(arg, (list, tuple)):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Hashable,
Iterator,
Sized,
cast,
)
import warnings

Expand Down Expand Up @@ -442,7 +443,8 @@ def _insert_on_column(self, result: DataFrame, obj: DataFrame) -> None:
def _index_array(self):
# TODO: why do we get here with e.g. MultiIndex?
if needs_i8_conversion(self._on.dtype):
return self._on.asi8
idx = cast("PeriodIndex | DatetimeIndex | TimedeltaIndex", self._on)
return idx.asi8
return None

def _resolve_output(self, out: DataFrame, obj: DataFrame) -> DataFrame:
Expand Down
Loading