Skip to content

Commit 245791c

Browse files
committed
DEPR: Remove offset and timeRule keywords from Series.tshift/shift, in favor of freq, pandas-dev#4853, pandas-dev#4864
1 parent 0fde3ba commit 245791c

File tree

8 files changed

+22
-48
lines changed

8 files changed

+22
-48
lines changed

doc/source/whatsnew/v0.17.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ Removal of prior version deprecations/changes
711711
- Remove ``table`` keyword in ``HDFStore.put/append``, in favor of using ``format=`` (:issue:`4645`)
712712
- Remove ``kind`` in ``read_excel/ExcelFile`` as its unused (:issue:`4712`)
713713
- Remove ``infer_type`` keyword from ``pd.read_html`` as its unused (:issue:`4770`, :issue:`7032`)
714-
714+
- Remove ``offset`` and ``timeRule`` keywords from ``Series.tshift/shift``, in favor of ``freq`` (:issue:`4853`, :issue:`4864`)
715715

716716
.. _whatsnew_0170.performance:
717717

pandas/core/datetools.py

-20
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,3 @@
4141
isBusinessDay = BDay().onOffset
4242
isMonthEnd = MonthEnd().onOffset
4343
isBMonthEnd = BMonthEnd().onOffset
44-
45-
46-
def _resolve_offset(freq, kwds):
47-
if 'timeRule' in kwds or 'offset' in kwds:
48-
offset = kwds.get('offset', None)
49-
offset = kwds.get('timeRule', offset)
50-
if isinstance(offset, compat.string_types):
51-
offset = getOffset(offset)
52-
warn = True
53-
else:
54-
offset = freq
55-
warn = False
56-
57-
if warn:
58-
import warnings
59-
warnings.warn("'timeRule' and 'offset' parameters are deprecated,"
60-
" please use 'freq' instead",
61-
FutureWarning)
62-
63-
return offset

pandas/core/frame.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2618,9 +2618,9 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
26182618
**kwargs)
26192619

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

26252625
def set_index(self, keys, drop=True, append=False, inplace=False,
26262626
verify_integrity=False):

pandas/core/generic.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -3806,15 +3806,15 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None,
38063806
shifted : %(klass)s
38073807
""")
38083808
@Appender(_shared_docs['shift'] % _shared_doc_kwargs)
3809-
def shift(self, periods=1, freq=None, axis=0, **kwargs):
3809+
def shift(self, periods=1, freq=None, axis=0):
38103810
if periods == 0:
38113811
return self
38123812

38133813
block_axis = self._get_block_manager_axis(axis)
3814-
if freq is None and not len(kwargs):
3814+
if freq is None:
38153815
new_data = self._data.shift(periods=periods, axis=block_axis)
38163816
else:
3817-
return self.tshift(periods, freq, **kwargs)
3817+
return self.tshift(periods, freq)
38183818

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

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

38553855
return new_obj.__finalize__(self)
38563856

3857-
def tshift(self, periods=1, freq=None, axis=0, **kwargs):
3857+
def tshift(self, periods=1, freq=None, axis=0):
38583858
"""
38593859
Shift the time index, using the index's frequency if available
38603860
@@ -3877,7 +3877,6 @@ def tshift(self, periods=1, freq=None, axis=0, **kwargs):
38773877
-------
38783878
shifted : NDFrame
38793879
"""
3880-
from pandas.core.datetools import _resolve_offset
38813880

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

3896-
offset = _resolve_offset(freq, kwargs)
3897-
3898-
if isinstance(offset, string_types):
3899-
offset = datetools.to_offset(offset)
3895+
if isinstance(freq, string_types):
3896+
freq = datetools.to_offset(freq)
39003897

39013898
block_axis = self._get_block_manager_axis(axis)
39023899
if isinstance(index, PeriodIndex):
3903-
orig_offset = datetools.to_offset(index.freq)
3904-
if offset == orig_offset:
3900+
orig_freq = datetools.to_offset(index.freq)
3901+
if freq == orig_freq:
39053902
new_data = self._data.copy()
39063903
new_data.axes[block_axis] = index.shift(periods)
39073904
else:
39083905
msg = ('Given freq %s does not match PeriodIndex freq %s' %
3909-
(offset.rule_code, orig_offset.rule_code))
3906+
(freq.rule_code, orig_freq.rule_code))
39103907
raise ValueError(msg)
39113908
else:
39123909
new_data = self._data.copy()
3913-
new_data.axes[block_axis] = index.shift(periods, offset)
3910+
new_data.axes[block_axis] = index.shift(periods, freq)
39143911

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

pandas/core/panel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,8 @@ def shift(self, periods=1, freq=None, axis='major'):
12101210

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

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

12161216
def join(self, other, how='left', lsuffix='', rsuffix=''):
12171217
"""

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2182,9 +2182,9 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
21822182
**kwargs)
21832183

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

21892189
def reindex_axis(self, labels, axis=0, **kwargs):
21902190
""" for compatibility with higher dims """

pandas/sparse/series.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,10 @@ def dropna(self, axis=0, inplace=False, **kwargs):
604604
dense_valid = dense_valid[dense_valid != self.fill_value]
605605
return dense_valid.to_sparse(fill_value=self.fill_value)
606606

607-
def shift(self, periods, freq=None, **kwds):
607+
def shift(self, periods, freq=None):
608608
"""
609609
Analogous to Series.shift
610610
"""
611-
from pandas.core.datetools import _resolve_offset
612-
613-
offset = _resolve_offset(freq, kwds)
614611

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

625-
if offset is not None:
622+
if freq is not None:
626623
return self._constructor(self.sp_values,
627624
sparse_index=self.sp_index,
628-
index=self.index.shift(periods, offset),
625+
index=self.index.shift(periods, freq),
629626
fill_value=self.fill_value).__finalize__(self)
630627

631628
int_index = self.sp_index.to_int_index()

pandas/tests/test_series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5385,10 +5385,10 @@ def test_shift(self):
53855385
self.assertRaises(ValueError, ps.shift, freq='D')
53865386

53875387
# legacy support
5388-
shifted4 = ps.shift(1, timeRule='B')
5388+
shifted4 = ps.shift(1, freq='B')
53895389
assert_series_equal(shifted2, shifted4)
53905390

5391-
shifted5 = ps.shift(1, offset=datetools.bday)
5391+
shifted5 = ps.shift(1, freq=datetools.bday)
53925392
assert_series_equal(shifted5, shifted4)
53935393

53945394
# 32-bit taking

0 commit comments

Comments
 (0)