>> dti.get_loc(dti2[0]) 0 >>> dti2.get_loc(dti[0]) KeyError: Timestamp('2016-01-01 00:00:00-0800...">

API: DatetimeIndex.get_loc(datetime) should require tzawareness compat? · Issue #30994 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

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