Skip to content

API: DatetimeIndex.get_loc(datetime) should require tzawareness compat? #30994

Closed
@jbrockmendel

Description

@jbrockmendel
dti = pd.date_range("2016-01-01", periods=3)
dti2 = dti.tz_localize("UTC").tz_convert("US/Pacific")

>>> dti.get_loc(dti2[0])
0
>>> dti2.get_loc(dti[0])
KeyError: Timestamp('2016-01-01 00:00:00-0800', tz='US/Pacific', freq='D')

ser = pd.Series(range(3), index=dti)
ser2 = pd.Series(range(3), index=dti2)

>>> ser.loc[dti2[1]]
1
>>> ser2.loc[dti[1]]
KeyError: Timestamp('2016-01-02 00:00:00-0800', tz='US/Pacific', freq='D')

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    IndexingRelated to indexing on series/frames, not to indexes themselvesNeeds DiscussionRequires discussion from core team before further actionTimezonesTimezone data dtype

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions