Skip to content

Commit

Permalink
DEPR: Remove offset and timeRule keywords from Series.tshift/shift, i…
Browse files Browse the repository at this point in the history
…n favor of freq, pandas-dev#4853, pandas-dev#4864
  • Loading branch information
jreback committed Aug 24, 2015
1 parent 0fde3ba commit 245791c
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 48 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ Removal of prior version deprecations/changes
- Remove ``table`` keyword in ``HDFStore.put/append``, in favor of using ``format=`` (:issue:`4645`)
- Remove ``kind`` in ``read_excel/ExcelFile`` as its unused (:issue:`4712`)
- Remove ``infer_type`` keyword from ``pd.read_html`` as its unused (:issue:`4770`, :issue:`7032`)

- Remove ``offset`` and ``timeRule`` keywords from ``Series.tshift/shift``, in favor of ``freq`` (:issue:`4853`, :issue:`4864`)

.. _whatsnew_0170.performance:

Expand Down
20 changes: 0 additions & 20 deletions pandas/core/datetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,3 @@
isBusinessDay = BDay().onOffset
isMonthEnd = MonthEnd().onOffset
isBMonthEnd = BMonthEnd().onOffset


def _resolve_offset(freq, kwds):
if 'timeRule' in kwds or 'offset' in kwds:
offset = kwds.get('offset', None)
offset = kwds.get('timeRule', offset)
if isinstance(offset, compat.string_types):
offset = getOffset(offset)
warn = True
else:
offset = freq
warn = False

if warn:
import warnings
warnings.warn("'timeRule' and 'offset' parameters are deprecated,"
" please use 'freq' instead",
FutureWarning)

return offset
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,9 +2618,9 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
**kwargs)

@Appender(_shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
def shift(self, periods=1, freq=None, axis=0):
return super(DataFrame, self).shift(periods=periods, freq=freq,
axis=axis, **kwargs)
axis=axis)

def set_index(self, keys, drop=True, append=False, inplace=False,
verify_integrity=False):
Expand Down
23 changes: 10 additions & 13 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3806,15 +3806,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
shifted : %(klass)s
""")
@Appender(_shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
def shift(self, periods=1, freq=None, axis=0):
if periods == 0:
return self

block_axis = self._get_block_manager_axis(axis)
if freq is None and not len(kwargs):
if freq is None:
new_data = self._data.shift(periods=periods, axis=block_axis)
else:
return self.tshift(periods, freq, **kwargs)
return self.tshift(periods, freq)

return self._constructor(new_data).__finalize__(self)

Expand Down Expand Up @@ -3854,7 +3854,7 @@ def slice_shift(self, periods=1, axis=0):

return new_obj.__finalize__(self)

def tshift(self, periods=1, freq=None, axis=0, **kwargs):
def tshift(self, periods=1, freq=None, axis=0):
"""
Shift the time index, using the index's frequency if available
Expand All @@ -3877,7 +3877,6 @@ def tshift(self, periods=1, freq=None, axis=0, **kwargs):
-------
shifted : NDFrame
"""
from pandas.core.datetools import _resolve_offset

index = self._get_axis(axis)
if freq is None:
Expand All @@ -3893,24 +3892,22 @@ def tshift(self, periods=1, freq=None, axis=0, **kwargs):
if periods == 0:
return self

offset = _resolve_offset(freq, kwargs)

if isinstance(offset, string_types):
offset = datetools.to_offset(offset)
if isinstance(freq, string_types):
freq = datetools.to_offset(freq)

block_axis = self._get_block_manager_axis(axis)
if isinstance(index, PeriodIndex):
orig_offset = datetools.to_offset(index.freq)
if offset == orig_offset:
orig_freq = datetools.to_offset(index.freq)
if freq == orig_freq:
new_data = self._data.copy()
new_data.axes[block_axis] = index.shift(periods)
else:
msg = ('Given freq %s does not match PeriodIndex freq %s' %
(offset.rule_code, orig_offset.rule_code))
(freq.rule_code, orig_freq.rule_code))
raise ValueError(msg)
else:
new_data = self._data.copy()
new_data.axes[block_axis] = index.shift(periods, offset)
new_data.axes[block_axis] = index.shift(periods, freq)

return self._constructor(new_data).__finalize__(self)

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,8 @@ def shift(self, periods=1, freq=None, axis='major'):

return super(Panel, self).slice_shift(periods, axis=axis)

def tshift(self, periods=1, freq=None, axis='major', **kwds):
return super(Panel, self).tshift(periods, freq, axis, **kwds)
def tshift(self, periods=1, freq=None, axis='major'):
return super(Panel, self).tshift(periods, freq, axis)

def join(self, other, how='left', lsuffix='', rsuffix=''):
"""
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,9 +2182,9 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
**kwargs)

@Appender(generic._shared_docs['shift'] % _shared_doc_kwargs)
def shift(self, periods=1, freq=None, axis=0, **kwargs):
def shift(self, periods=1, freq=None, axis=0):
return super(Series, self).shift(periods=periods, freq=freq,
axis=axis, **kwargs)
axis=axis)

def reindex_axis(self, labels, axis=0, **kwargs):
""" for compatibility with higher dims """
Expand Down
9 changes: 3 additions & 6 deletions pandas/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,13 +604,10 @@ def dropna(self, axis=0, inplace=False, **kwargs):
dense_valid = dense_valid[dense_valid != self.fill_value]
return dense_valid.to_sparse(fill_value=self.fill_value)

def shift(self, periods, freq=None, **kwds):
def shift(self, periods, freq=None):
"""
Analogous to Series.shift
"""
from pandas.core.datetools import _resolve_offset

offset = _resolve_offset(freq, kwds)

# no special handling of fill values yet
if not isnull(self.fill_value):
Expand All @@ -622,10 +619,10 @@ def shift(self, periods, freq=None, **kwds):
if periods == 0:
return self.copy()

if offset is not None:
if freq is not None:
return self._constructor(self.sp_values,
sparse_index=self.sp_index,
index=self.index.shift(periods, offset),
index=self.index.shift(periods, freq),
fill_value=self.fill_value).__finalize__(self)

int_index = self.sp_index.to_int_index()
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5385,10 +5385,10 @@ def test_shift(self):
self.assertRaises(ValueError, ps.shift, freq='D')

# legacy support
shifted4 = ps.shift(1, timeRule='B')
shifted4 = ps.shift(1, freq='B')
assert_series_equal(shifted2, shifted4)

shifted5 = ps.shift(1, offset=datetools.bday)
shifted5 = ps.shift(1, freq=datetools.bday)
assert_series_equal(shifted5, shifted4)

# 32-bit taking
Expand Down

0 comments on commit 245791c

Please sign in to comment.