-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
API: DatetimeIndex.get_loc(datetime) should require tzawareness compat? #30994
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
Comments
I agree with you here, we should be strict on tz awareness, though should'nt this actually raise a TypeError if its not tz compatible? |
The comparison would raise a TypeError, but get_loc would catch and re-raise with KeyError I think. I'll be double-checking that we're consistent about this throughout (with docstrings) @jorisvandenbossche any thoughts here before i move forward on this? |
I think the examples above might be a bit misleading. The original tz-naive timestamps are not in the
For tz-aware series/index, I think this actually makes some sense. At least, for example I expect "tz-naive" strings to work. The other way around (indexing a tz-naive index with a tz-aware timestamp), on the other hand, seems less useful to me. |
What are the proposed behavior here?
@jorisvandenbossche is the second part of my summary correct, that @jbrockmendel what's your proposal for indexing a DatetimeIndex with a tz-naive key, when the localized key is in the index? |
No, only tzawareness-compat, so no naive/aware mixing. If both are tzaware but different timezones, it converts (again, like every other comparison method; setitem-like methods require matching timezones) |
closed by #36148 |
get_loc is effectively an equality check, so I think it should behave like all our other comparisons and require tzawareness-compat. So all of these would raise KeyError.
xref #17920, #30819 (comment)
The text was updated successfully, but these errors were encountered: