

def test_shift(self):
    shifted = self.ts.shift(1)
    unshifted = shifted.shift((- 1))
    tm.assert_dict_equal(unshifted.valid(), self.ts, compare_keys=False)
    offset = datetools.bday
    shifted = self.ts.shift(1, freq=offset)
    unshifted = shifted.shift((- 1), freq=offset)
    assert_series_equal(unshifted, self.ts)
    unshifted = self.ts.shift(0, freq=offset)
    assert_series_equal(unshifted, self.ts)
    shifted = self.ts.shift(1, freq='B')
    unshifted = shifted.shift((- 1), freq='B')
    assert_series_equal(unshifted, self.ts)
    unshifted = self.ts.shift(0)
    assert_series_equal(unshifted, self.ts)
    ps = tm.makePeriodSeries()
    shifted = ps.shift(1)
    unshifted = shifted.shift((- 1))
    tm.assert_dict_equal(unshifted.valid(), ps, compare_keys=False)
    shifted2 = ps.shift(1, 'B')
    shifted3 = ps.shift(1, datetools.bday)
    assert_series_equal(shifted2, shifted3)
    assert_series_equal(ps, shifted2.shift((- 1), 'B'))
    self.assertRaises(ValueError, ps.shift, freq='D')
    shifted4 = ps.shift(1, freq='B')
    assert_series_equal(shifted2, shifted4)
    shifted5 = ps.shift(1, freq=datetools.bday)
    assert_series_equal(shifted5, shifted4)
    index = date_range('2000-01-01', periods=5)
    for dtype in ['int32', 'int64']:
        s1 = Series(np.arange(5, dtype=dtype), index=index)
        p = s1.iloc[1]
        result = s1.shift(periods=p)
        expected = Series([np.nan, 0, 1, 2, 3], index=index)
        assert_series_equal(result, expected)
    s = Series(date_range('2000-01-01 09:00:00', periods=5, tz='US/Eastern'), name='foo')
    result = (s - unshifted.shift())
    assert_series_equal(result, Series(TimedeltaIndex((['NaT'] + (['1 days'] * 4))), name='foo'))
    s2 = Series(date_range('2000-01-01 09:00:00', periods=5, tz='CET'), name='foo')
    self.assertRaises(ValueError, (lambda : (s - s2)))

dataset/ETHPy150Open pydata/pandas/pandas/tests/series/test_timeseries.py TestSeriesTimeSeries.test_shift/VarMisuse@453/577 `s`->`unshifted`