CLN: tshift & shift could be consolidated (original) (raw)

Particularly now that shift only works on datetime-like indexes (#11211)

They look almost the same, although not exactly:

In [11]: df=pd.DataFrame(pd.np.random.rand(5,2), index=pd.date_range(periods=5, start='2000'))

In [12]: df Out[12]: 0 1 2000-01-01 0.640148 0.781291 2000-01-02 0.261649 0.652372 2000-01-03 0.642422 0.734348 2000-01-04 0.582657 0.601868 2000-01-05 0.848645 0.078437

In [13]: df.shift() Out[13]: 0 1 2000-01-01 NaN NaN 2000-01-02 0.640148 0.781291 2000-01-03 0.261649 0.652372 2000-01-04 0.642422 0.734348 2000-01-05 0.582657 0.601868

In [14]: df.tshift() Out[14]: 0 1 2000-01-02 0.640148 0.781291 2000-01-03 0.261649 0.652372 2000-01-04 0.642422 0.734348 2000-01-05 0.582657 0.601868 2000-01-06 0.848645 0.078437

In [15]: df.shift(freq='D') Out[15]: 0 1 2000-01-02 0.640148 0.781291 2000-01-03 0.261649 0.652372 2000-01-04 0.642422 0.734348 2000-01-05 0.582657 0.601868 2000-01-06 0.848645 0.078437

In [16]: df.tshift(freq='D') Out[16]: 0 1 2000-01-02 0.640148 0.781291 2000-01-03 0.261649 0.652372 2000-01-04 0.642422 0.734348 2000-01-05 0.582657 0.601868 2000-01-06 0.848645 0.078437