API/DEPR: 'periods' argument instead of 'n' for PeriodIndex.shift() by arminv · Pull Request #22912 · pandas-dev/pandas (original) (raw)

In order to be consistent with Index.shift & Series.shift & DatetimeIndex.shift, n argument was deprecated in favor of periods.

In [2]: idx = pd.PeriodIndex(freq='A', start='1/1/2001', end='12/1/2009')

In [3]: idx
Out[3]: 
PeriodIndex(['2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008',
             '2009'],
            dtype='period[A-DEC]', freq='A-DEC')

In [4]: idx.shift(1)
Out[4]: 
PeriodIndex(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009',
             '2010'],
            dtype='period[A-DEC]', freq='A-DEC')

In [5]: idx.shift(periods=1)
Out[5]: 
PeriodIndex(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009',
             '2010'],
            dtype='period[A-DEC]', freq='A-DEC')

In [6]: idx.shift(n=1)
//anaconda/envs/pandas_dev/bin/ipython:1: FutureWarning: the 'n' keyword is deprecated, use 'periods' instead
  #!//anaconda/envs/pandas_dev/bin/python
Out[6]: 
PeriodIndex(['2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009',
             '2010'],
            dtype='period[A-DEC]', freq='A-DEC')