8000 Misc separable pieces of #24024 by jbrockmendel · Pull Request #24488 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

Misc separable pieces of #24024 #24488

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

Merged
merged 6 commits into from
Dec 30, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move shift back to DatetimeIndexOpsMixin
  • Loading branch information
jbrockmendel committed Dec 29, 2018
commit 016758d0ec295997fae62e053b16c519d6edbcad
33 changes: 0 additions & 33 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,39 +1077,6 @@ def _addsub_offset_array(self, other, op):
return type(self)(res_values, freq='infer')
return self._from_sequence(res_values)

@deprecate_kwarg(old_arg_name='n', new_arg_name='periods')
def shift(self, periods, freq=None):
"""
Shift index by desired number of time frequency increments.

This method is for shifting the values of datetime-like indexes
by a specified time increment a given number of times.

Parameters
----------
periods : int
Number of periods (or increments) to shift by,
can be positive or negative.

.. versionchanged:: 0.24.0

freq : pandas.DateOffset, pandas.Timedelta or string, optional
Frequency increment to shift by.
If None, the index is shifted by its own `freq` attribute.
Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

Returns
-------
pandas.DatetimeIndex
Shifted index.

See Also
--------
Index.shift : Shift values of Index.
PeriodIndex.shift : Shift values of PeriodIndex.
"""
return self._time_shift(periods=periods, freq=freq)

def _time_shift(self, periods, freq=None):
"""
Shift each value by `periods`.
Expand Down
27 changes: 0 additions & 27 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,33 +435,6 @@ def value_counts(self, dropna=False):

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

def shift(self, periods=1, fill_value=None):
"""
Shift values by desired number.

Newly introduced missing values are filled with
``self.dtype.na_value``.

.. versionadded:: 0.24.0

Parameters
----------
periods : int, default 1
The number of periods to shift. Negative values are allowed
for shifting backwards.
fill_value : optional, default NaT

.. versionadded:: 0.24.0

Returns
-------
shifted : PeriodArray
"""
# TODO(DatetimeArray): remove
# The semantics for Index.shift differ from EA.shift
# then just call super.
return ExtensionArray.shift(self, periods, fill_value=fill_value)

def _time_shift(self, n, freq=None):
"""
Shift each value by `periods`.
Expand Down
36 changes: 35 additions & 1 deletion pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pandas._libs import NaT, iNaT, lib
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
from pandas.util._decorators import Appender, cache_readonly
from pandas.util._decorators import Appender, cache_readonly, deprecate_kwarg

from pandas.core.dtypes.common import (
ensure_int64, is_bool_dtype, is_dtype_equal, is_float, is_integer,
Expand Down Expand Up @@ -581,6 +581,40 @@ def _time_shift(self, periods, freq=None):
result = self._eadata._time_shift(periods, freq=freq)
return type(self)(result, name=self.name)

@deprecate_kwarg(old_arg_name='n', new_arg_name='periods')
def shift(self, periods, freq=None):
"""
Shift index by desired number of time frequency increments.

This method is for shifting the values of datetime-like indexes
by a specified time increment a given number of times.

Parameters
----------
periods : int
Number of periods (or increments) to shift by,
can be positive or negative.

.. versionchanged:: 0.24.0

freq : pandas.DateOffset, pandas.Timedelta or string, optional
Frequency increment to shift by.
If None, the index is shifted by its own `freq` attribute.
Offset aliases are valid strings, e.g., 'D', 'W', 'M' etc.

Returns
-------
pandas.DatetimeIndex
Shifted index.

See Also
--------
Index.shift : Shift values of Index.
PeriodIndex.shift : Shift values of PeriodIndex.
"""
result = self._eadata._time_shift(periods, freq=freq)
return type(self)(result, name=self.name)


def wrap_arithmetic_op(self, other, result):
if result is NotImplemented:
Expand Down
0