Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API/DEPR: 'periods' argument instead of 'n' for PeriodIndex.shift() #22912

Merged
merged 5 commits into from
Oct 8, 2018

Conversation

arminv
Copy link
Contributor

@arminv arminv commented Sep 30, 2018

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')

@pep8speaks
Copy link

pep8speaks commented Sep 30, 2018

Hello @arminv! Thanks for updating the PR.

Comment last updated on October 08, 2018 at 18:08 Hours UTC

@codecov
Copy link

codecov bot commented Sep 30, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@e510b1a). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #22912   +/-   ##
=========================================
  Coverage          ?   92.19%           
=========================================
  Files             ?      169           
  Lines             ?    50879           
  Branches          ?        0           
=========================================
  Hits              ?    46910           
  Misses            ?     3969           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.61% <100%> (?)
#single 42.32% <66.66%> (?)
Impacted Files Coverage Δ
pandas/core/arrays/datetimelike.py 95.56% <ø> (ø)
pandas/core/generic.py 96.65% <ø> (ø)
pandas/core/arrays/period.py 92.04% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e510b1a...d5586e4. Read the comment docs.

@arminv
Copy link
Contributor Author

arminv commented Oct 1, 2018

@TomAugspurger can you review please?

@TomAugspurger TomAugspurger added the Deprecate Functionality to remove in pandas label Oct 1, 2018
@TomAugspurger TomAugspurger added this to the 0.24.0 milestone Oct 1, 2018
Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I didn't closely follow the issue and other discussion, but I just want to double-check that we really want to do this. DatetimeIndex / PeriodIndex.shift are fundamentally different from Series.shift, (shifting values vs. position). Still, I think changing the argument name is still for the best.

cc @jorisvandenbossche


See Also
--------
Index.shift : Shift values of Index.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think remove this. Index.shift isn't implemented, it's just for the date-like subclasses.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you update this @arminv

@jreback
Copy link
Contributor

jreback commented Oct 1, 2018

this is ok, we have an inconsistency in named args now.

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping on green.

@@ -573,7 +573,7 @@ Deprecations
- :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain
many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`)
- :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`)
- :func:`DatetimeIndex.shift` now accepts ``periods`` argument instead of ``n`` for consistency with :func:`Index.shift` and :func:`Series.shift`. Using ``n`` throws a deprecation warning (:issue:`22458`)
- :func:`DatetimeIndex.shift` and :func:`PeriodIndex.shift` now accept ``periods`` argument instead of ``n`` for consistency with :func:`Index.shift` and :func:`Series.shift`. Using ``n`` throws a deprecation warning (:issue:`22458`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add this issue as well here (this PR number is fine)

@jreback
Copy link
Contributor

jreback commented Oct 7, 2018

pls rebase on master as well

Copy link
Contributor

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about the merge conflict. This looks good.

@arminv
Copy link
Contributor Author

arminv commented Oct 8, 2018

@jreback all green.
@TomAugspurger thanks for reviewing.

@TomAugspurger TomAugspurger merged commit f5f6eca into pandas-dev:master Oct 8, 2018
@TomAugspurger
Copy link
Contributor

Thanks!

@arminv arminv deleted the periods_kwarg branch October 8, 2018 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent keyword argument name for the 'periods' in pandas.Index.shift for a DatetimeIndex
4 participants