Skip to content

Commit

Permalink
DEPR: to_native_types, set_value, iteritems, union_many, to_perioddel…
Browse files Browse the repository at this point in the history
…ta (pandas-dev#49244)

* DEPR: to_native_types, set_value, iteritems, union_many, to_perioddelta

* remove more

* missing tick

* remove duplicate note
  • Loading branch information
jbrockmendel authored and noatamir committed Nov 9, 2022
1 parent e0abaaa commit 53afebe
Show file tree
Hide file tree
Showing 20 changed files with 8 additions and 377 deletions.
7 changes: 0 additions & 7 deletions doc/redirects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,8 @@ generated/pandas.DataFrame.isna,../reference/api/pandas.DataFrame.isna
generated/pandas.DataFrame.isnull,../reference/api/pandas.DataFrame.isnull
generated/pandas.DataFrame.items,../reference/api/pandas.DataFrame.items
generated/pandas.DataFrame.__iter__,../reference/api/pandas.DataFrame.__iter__
generated/pandas.DataFrame.iteritems,../reference/api/pandas.DataFrame.iteritems
generated/pandas.DataFrame.iterrows,../reference/api/pandas.DataFrame.iterrows
generated/pandas.DataFrame.itertuples,../reference/api/pandas.DataFrame.itertuples
generated/pandas.DataFrame.ix,../reference/api/pandas.DataFrame.ix
generated/pandas.DataFrame.join,../reference/api/pandas.DataFrame.join
generated/pandas.DataFrame.keys,../reference/api/pandas.DataFrame.keys
generated/pandas.DataFrame.kurt,../reference/api/pandas.DataFrame.kurt
Expand Down Expand Up @@ -569,7 +567,6 @@ generated/pandas.DatetimeIndex.strftime,../reference/api/pandas.DatetimeIndex.st
generated/pandas.DatetimeIndex.time,../reference/api/pandas.DatetimeIndex.time
generated/pandas.DatetimeIndex.timetz,../reference/api/pandas.DatetimeIndex.timetz
generated/pandas.DatetimeIndex.to_frame,../reference/api/pandas.DatetimeIndex.to_frame
generated/pandas.DatetimeIndex.to_perioddelta,../reference/api/pandas.DatetimeIndex.to_perioddelta
generated/pandas.DatetimeIndex.to_period,../reference/api/pandas.DatetimeIndex.to_period
generated/pandas.DatetimeIndex.to_pydatetime,../reference/api/pandas.DatetimeIndex.to_pydatetime
generated/pandas.DatetimeIndex.to_series,../reference/api/pandas.DatetimeIndex.to_series
Expand Down Expand Up @@ -702,7 +699,6 @@ generated/pandas.Index.rename,../reference/api/pandas.Index.rename
generated/pandas.Index.repeat,../reference/api/pandas.Index.repeat
generated/pandas.Index.searchsorted,../reference/api/pandas.Index.searchsorted
generated/pandas.Index.set_names,../reference/api/pandas.Index.set_names
generated/pandas.Index.set_value,../reference/api/pandas.Index.set_value
generated/pandas.Index.shape,../reference/api/pandas.Index.shape
generated/pandas.Index.shift,../reference/api/pandas.Index.shift
generated/pandas.Index.size,../reference/api/pandas.Index.size
Expand All @@ -721,7 +717,6 @@ generated/pandas.Index.to_flat_index,../reference/api/pandas.Index.to_flat_index
generated/pandas.Index.to_frame,../reference/api/pandas.Index.to_frame
generated/pandas.Index.to_list,../reference/api/pandas.Index.to_list
generated/pandas.Index.tolist,../reference/api/pandas.Index.tolist
generated/pandas.Index.to_native_types,../reference/api/pandas.Index.to_native_types
generated/pandas.Index.to_numpy,../reference/api/pandas.Index.to_numpy
generated/pandas.Index.to_series,../reference/api/pandas.Index.to_series
generated/pandas.Index.transpose,../reference/api/pandas.Index.transpose
Expand Down Expand Up @@ -1081,8 +1076,6 @@ generated/pandas.Series.is_unique,../reference/api/pandas.Series.is_unique
generated/pandas.Series.item,../reference/api/pandas.Series.item
generated/pandas.Series.items,../reference/api/pandas.Series.items
generated/pandas.Series.__iter__,../reference/api/pandas.Series.__iter__
generated/pandas.Series.iteritems,../reference/api/pandas.Series.iteritems
generated/pandas.Series.ix,../reference/api/pandas.Series.ix
generated/pandas.Series.keys,../reference/api/pandas.Series.keys
generated/pandas.Series.kurt,../reference/api/pandas.Series.kurt
generated/pandas.Series.kurtosis,../reference/api/pandas.Series.kurtosis
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Indexing, iteration
DataFrame.insert
DataFrame.__iter__
DataFrame.items
DataFrame.iteritems
DataFrame.keys
DataFrame.iterrows
DataFrame.itertuples
Expand Down
2 changes: 0 additions & 2 deletions doc/source/reference/indexing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Conversion
Index.map
Index.ravel
Index.to_list
Index.to_native_types
Index.to_series
Index.to_frame
Index.view
Expand Down Expand Up @@ -393,7 +392,6 @@ Conversion
:toctree: api/

DatetimeIndex.to_period
DatetimeIndex.to_perioddelta
DatetimeIndex.to_pydatetime
DatetimeIndex.to_series
DatetimeIndex.to_frame
Expand Down
1 change: 0 additions & 1 deletion doc/source/reference/series.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Indexing, iteration
Series.iloc
Series.__iter__
Series.items
Series.iteritems
Series.keys
Series.pop
Series.item
Expand Down
6 changes: 6 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ Removal of prior version deprecations/changes
- Removed deprecated :meth:`Index.is_mixed`, check ``index.inferred_type`` directly instead (:issue:`32922`)
- Removed deprecated :func:`pandas.api.types.is_categorical`; use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`33385`)
- Removed deprecated :meth:`Index.asi8` (:issue:`37877`)
- Removed deprecated :meth:`DataFrame._AXIS_NUMBERS`, :meth:`DataFrame._AXIS_NAMES`, :meth:`Series._AXIS_NUMBERS`, :meth:`Series._AXIS_NAMES` (:issue:`33637`)
- Removed deprecated :meth:`Index.to_native_types`, use ``obj.astype(str)`` instead (:issue:`36418`)
- Removed deprecated :meth:`Series.iteritems`, :meth:`DataFrame.iteritems`, use ``obj.items`` instead (:issue:`45321`)
- Removed deprecated :meth:`DatetimeIndex.union_many` (:issue:`45018`)
- Removed deprecated :meth:`RangeIndex._start`, :meth:`RangeIndex._stop`, :meth:`RangeIndex._step`, use ``start``, ``stop``, ``step`` instead (:issue:`30482`)
- Removed deprecated :meth:`DatetimeIndex.to_perioddelta`, Use ``dtindex - dtindex.to_period(freq).to_timestamp()`` instead (:issue:`34853`)
- 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`)
- 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`)
Expand Down
37 changes: 1 addition & 36 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@
if TYPE_CHECKING:

from pandas import DataFrame
from pandas.core.arrays import (
PeriodArray,
TimedeltaArray,
)
from pandas.core.arrays import PeriodArray

_midnight = time(0, 0)

Expand Down Expand Up @@ -1194,38 +1191,6 @@ def to_period(self, freq=None) -> PeriodArray:

return PeriodArray._from_datetime64(self._ndarray, freq, tz=self.tz)

def to_perioddelta(self, freq) -> TimedeltaArray:
"""
Calculate deltas between self values and self converted to Periods at a freq.
Used for vectorized offsets.
Parameters
----------
freq : Period frequency
Returns
-------
TimedeltaArray/Index
"""
# Deprecaation GH#34853
warnings.warn(
"to_perioddelta is deprecated and will be removed in a "
"future version. "
"Use `dtindex - dtindex.to_period(freq).to_timestamp()` instead.",
FutureWarning,
# stacklevel chosen to be correct for when called from DatetimeIndex
stacklevel=find_stack_level(),
)
from pandas.core.arrays.timedeltas import TimedeltaArray

if self._ndarray.dtype != "M8[ns]":
raise NotImplementedError("Only supported for nanosecond resolution.")

i8delta = self.asi8 - self.to_period(freq).to_timestamp().asi8
m8delta = i8delta.view("m8[ns]")
return TimedeltaArray(m8delta)

# -----------------------------------------------------------------
# Properties - Vectorized Timestamp Properties/Methods

Expand Down
50 changes: 0 additions & 50 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1328,44 +1328,6 @@ def items(self) -> Iterable[tuple[Hashable, Series]]:
for i, k in enumerate(self.columns):
yield k, self._ixs(i, axis=1)

_shared_docs[
"iteritems"
] = r"""
Iterate over (column name, Series) pairs.
.. deprecated:: 1.5.0
iteritems is deprecated and will be removed in a future version.
Use .items instead.
Iterates over the DataFrame columns, returning a tuple with
the column name and the content as a Series.
Yields
------
label : object
The column names for the DataFrame being iterated over.
content : Series
The column entries belonging to each label, as a Series.
See Also
--------
DataFrame.iter : Recommended alternative.
DataFrame.iterrows : Iterate over DataFrame rows as
(index, Series) pairs.
DataFrame.itertuples : Iterate over DataFrame rows as namedtuples
of the values.
"""

@Appender(_shared_docs["iteritems"])
def iteritems(self) -> Iterable[tuple[Hashable, Series]]:
warnings.warn(
"iteritems is deprecated and will be removed in a future version. "
"Use .items instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
yield from self.items()

def iterrows(self) -> Iterable[tuple[Hashable, Series]]:
"""
Iterate over DataFrame rows as (index, Series) pairs.
Expand Down Expand Up @@ -11624,18 +11586,6 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame:
)
columns = properties.AxisProperty(axis=0, doc="The column labels of the DataFrame.")

@property
def _AXIS_NUMBERS(self) -> dict[str, int]:
""".. deprecated:: 1.1.0"""
super()._AXIS_NUMBERS
return {"index": 0, "columns": 1}

@property
def _AXIS_NAMES(self) -> dict[int, str]:
""".. deprecated:: 1.1.0"""
super()._AXIS_NAMES
return {0: "index", 1: "columns"}

# ----------------------------------------------------------------------
# Add plotting methods to DataFrame
plot = CachedAccessor("plot", pandas.plotting.PlotAccessor)
Expand Down
19 changes: 0 additions & 19 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,25 +494,6 @@ def _data(self):
_info_axis_name: Literal["index", "columns"]
_AXIS_LEN: int

@property
def _AXIS_NUMBERS(self) -> dict[str, int]:
""".. deprecated:: 1.1.0"""
warnings.warn(
"_AXIS_NUMBERS has been deprecated.",
FutureWarning,
stacklevel=find_stack_level(),
)
return {"index": 0}

@property
def _AXIS_NAMES(self) -> dict[int, str]:
""".. deprecated:: 1.1.0"""
level = self.ndim + 1
warnings.warn(
"_AXIS_NAMES has been deprecated.", FutureWarning, stacklevel=level
)
return {0: "index"}

@final
def _construct_axes_dict(self, axes: Sequence[Axis] | None = None, **kwargs):
"""Return an axes dictionary for myself."""
Expand Down
39 changes: 0 additions & 39 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,45 +1460,6 @@ def _format_with_header(self, header: list[str_t], na_rep: str_t) -> list[str_t]
result = trim_front(format_array(values, None, justify="left"))
return header + result

@final
def to_native_types(self, slicer=None, **kwargs) -> np.ndarray:
"""
Format specified values of `self` and return them.
.. deprecated:: 1.2.0
Parameters
----------
slicer : int, array-like
An indexer into `self` that specifies which values
are used in the formatting process.
kwargs : dict
Options for specifying how the values should be formatted.
These options include the following:
1) na_rep : str
The value that serves as a placeholder for NULL values
2) quoting : bool or None
Whether or not there are quoted values in `self`
3) date_format : str
The format used to represent date-like values.
Returns
-------
numpy.ndarray
Formatted values.
"""
warnings.warn(
"The 'to_native_types' method is deprecated and will be removed in "
"a future version. Use 'astype(str)' instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
values = self
if slicer is not None:
values = values[slicer]
return values._format_native_types(**kwargs)

def _format_native_types(
self, *, na_rep: str_t = "", quoting=None, **kwargs
) -> npt.NDArray[np.object_]:
Expand Down
47 changes: 0 additions & 47 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import pandas.core.common as com
from pandas.core.indexes.base import (
Index,
get_unanimous_names,
maybe_extract_name,
)
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
Expand All @@ -75,7 +74,6 @@
DataFrame,
Float64Index,
PeriodIndex,
TimedeltaIndex,
)


Expand Down Expand Up @@ -229,7 +227,6 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
floor
ceil
to_period
to_perioddelta
to_pydatetime
to_series
to_frame
Expand Down Expand Up @@ -295,13 +292,6 @@ def to_period(self, freq=None) -> PeriodIndex:
arr = self._data.to_period(freq)
return PeriodIndex._simple_new(arr, name=self.name)

@doc(DatetimeArray.to_perioddelta)
def to_perioddelta(self, freq) -> TimedeltaIndex:
from pandas.core.indexes.api import TimedeltaIndex

arr = self._data.to_perioddelta(freq)
return TimedeltaIndex._simple_new(arr, name=self.name)

@doc(DatetimeArray.to_julian_date)
def to_julian_date(self) -> Float64Index:
from pandas.core.indexes.api import Float64Index
Expand Down Expand Up @@ -439,43 +429,6 @@ def _can_range_setop(self, other) -> bool:
return False
return super()._can_range_setop(other)

def union_many(self, others):
"""
A bit of a hack to accelerate unioning a collection of indexes.
"""
warnings.warn(
"DatetimeIndex.union_many is deprecated and will be removed in "
"a future version. Use obj.union instead.",
FutureWarning,
stacklevel=find_stack_level(),
)

this = self

for other in others:
if not isinstance(this, DatetimeIndex):
this = Index.union(this, other)
continue

if not isinstance(other, DatetimeIndex):
try:
other = DatetimeIndex(other)
except TypeError:
pass

this, other = this._maybe_utc_convert(other)

if len(self) and len(other) and this._can_fast_union(other):
# union already has fastpath handling for empty cases
this = this._fast_union(other)
else:
this = Index.union(this, other)

res_name = get_unanimous_names(self, *others)[0]
if this.name != res_name:
return this.rename(res_name)
return this

def _maybe_utc_convert(self, other: Index) -> tuple[DatetimeIndex, Index]:
this = self

Expand Down
12 changes: 0 additions & 12 deletions pandas/core/indexes/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Callable,
Hashable,
)
import warnings

import numpy as np

Expand All @@ -20,7 +19,6 @@
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_dtype_equal,
Expand Down Expand Up @@ -356,16 +354,6 @@ class IntegerIndex(NumericIndex):

_is_backward_compat_public_numeric_index: bool = False

@property
def asi8(self) -> npt.NDArray[np.int64]:
# do not cache or you'll create a memory leak
warnings.warn(
"Index.asi8 is deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
return self._values.view(self._default_dtype)


class Int64Index(IntegerIndex):
_index_descr_args = {
Expand Down

0 comments on commit 53afebe

Please sign in to comment.