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

BUG: PeriodIndex.get_loc with mismatched freq #41670

Merged
merged 3 commits into from
May 28, 2021

Conversation

jbrockmendel
Copy link
Member

  • closes #xxxx
  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them
  • whatsnew entry

@simonjayhawkins
Copy link
Member

is there an issue for this, does it need a release note?

@simonjayhawkins simonjayhawkins added Bug Frequency DateOffsets Index Related to the Index class or subclasses Period Period data type labels May 26, 2021
@jreback jreback added this to the 1.3 milestone May 27, 2021
@jreback
Copy link
Contributor

jreback commented May 27, 2021

lgtm ping with a whatsnew note

@simonjayhawkins
Copy link
Member

idx.get_loc(datetime.datetime(2000, 1, 2, 1, 0), "pad"), idx.get_loc(pd.Timestamp("2000-01-02 01:00:00"), "pad") and idx.get_loc('2000-01-02 00:00', "pad") still return 1. why do we need to disallow a mismatched Period object?

@jbrockmendel
Copy link
Member Author

i dont think there is a user-facing change bc __getitem__ goes through engine.get_loc where this needs to be addressed separately

@simonjayhawkins
Copy link
Member

Index.get_loc is public? so is a user-facing change? maybe should raise ValueError with appropriate message so it's more obvious when things fail. Raising a KeyError for a method that is supposed to return a value even when an exact match is not found seems counterintuitive.

@jbrockmendel
Copy link
Member Author

Index.get_loc is public? so is a user-facing change?

get_loc is in that weird space where it isn't really intended for users, but it is called from outside self, so it would be a code smell to make it private

I'll add a whatsnew note to be on the safe side

maybe should raise ValueError with appropriate message so it's more obvious when things fail. Raising a KeyError for a method that is supposed to return a value even when an exact match is not found seems counterintuitive

get_loc is pretty consistent about raising KeyError IIRC

@simonjayhawkins
Copy link
Member

maybe should raise ValueError with appropriate message so it's more obvious when things fail. Raising a KeyError for a method that is supposed to return a value even when an exact match is not found seems counterintuitive

get_loc is pretty consistent about raising KeyError IIRC

seems reasonable, my concern is that we are changing tested behavior without a deprecation and therefore it could break users code, so that break should be more obvious.

maybe add a warning or deprecate this behavior instead.

@simonjayhawkins
Copy link
Member

simonjayhawkins commented May 28, 2021

Index.get_loc is public? so is a user-facing change?

get_loc is in that weird space where it isn't really intended for users, but it is called from outside self, so it would be a code smell to make it private

nothing in the api to suggest to the user that this method should not be used https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.Index.get_loc.html

@jbrockmendel
Copy link
Member Author

nothing in the api to suggest to the user that this method should not be used

OK. I added a whatsnew note.

@jreback jreback merged commit ddc28a4 into pandas-dev:master May 28, 2021
@jreback
Copy link
Contributor

jreback commented May 28, 2021

thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the bug-pi-get_loc branch May 28, 2021 16:00
TLouf pushed a commit to TLouf/pandas that referenced this pull request Jun 1, 2021
@jorisvandenbossche
Copy link
Member

This seems to have caused slowdowns in several of the Period indexing benchmarks: see https://pandas.pydata.org/speed/pandas/#regressions?sort=1&dir=desc, scrolldown to "2021-05-28 17:58"

@jorisvandenbossche
Copy link
Member

I opened #42247 to keep track of this regression.

JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Frequency DateOffsets Index Related to the Index class or subclasses Period Period data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants