Skip to content

REF: make PeriodIndex.get_value wrap PeriodIndex.get_loc #31318

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

Merged
merged 1 commit into from
Jan 28, 2020

Conversation

jbrockmendel
Copy link
Member

AFAICT the only behavior this changes is in how datetime objects are treated. After this they are more consistent.

dti = pd.date_range("2016-01-01", periods=3, freq="MS")
pi = dti.to_period("H")
ser = pd.Series(range(7, 10), index=pi)

key = dti[0]

master

>>> pi.get_loc(key)
0
>>> pi.get_value(ser, key)
KeyError: Timestamp('2016-01-01 00:00:00', freq='MS')
>>> ser.loc[key]
7
>>> ser[key]
KeyError: Timestamp('2016-01-01 00:00:00', freq='MS')

Under this PR, the get_value and __getitem__ calls both return 7.

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type labels Jan 26, 2020
@jreback jreback added this to the 1.1 milestone Jan 26, 2020
@jreback
Copy link
Contributor

jreback commented Jan 26, 2020

sgtm.

@jbrockmendel
Copy link
Member Author

@jreback gentle ping, plenty more steps to go

@jreback jreback merged commit 5402ea5 into pandas-dev:master Jan 28, 2020
@jreback
Copy link
Contributor

jreback commented Jan 28, 2020

yep thanks

@TomAugspurger
Copy link
Contributor

@meeseeksdev backport to 1.0.x

Backporting this, in an attempt to close #32108.

@lumberbot-app
Copy link

lumberbot-app bot commented Mar 9, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout 1.0.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 5402ea57a6f0fe606a3de3731dcb903186b1f4c2
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #31318: REF: make PeriodIndex.get_value wrap PeriodIndex.get_loc'
  1. Push to a named branch :
git push YOURFORK 1.0.x:auto-backport-of-pr-31318-on-1.0.x
  1. Create a PR against branch 1.0.x, I would have named this PR:

"Backport PR #31318 on branch 1.0.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@TomAugspurger
Copy link
Contributor

Seems like backporting this will depend on too many other changes (at least PeriodIndex._get_values_for_loc). I won't pursue this any further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants