Skip to content

API: indexing dates-with-datetime64 #62158

@jbrockmendel

Description

@jbrockmendel

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

ser = pd.Series(["2016-01-01"], dtype="date32[pyarrow]")
ser2 = ser.astype("timestamp[ns][pyarrow]")
ser3 = ser.astype("datetime64[ns]")

dti = pd.Index(ser3)
dti.get_loc(ser[0])  # raises KeyError
dti.get_indexer(ser.values)  # -1s
dti.get_indexer(ser.values.astype(object))  # 0s; inconsistent

Issue Description

DatetimeIndex.get_indexer has a special case (actually in Index._maybe_downcast_for_indexing) for sequences of date objects that is inconsistent with both scalar treatment and comparison op behavior. This was mostly benign before the existence of a date dtype, but now has the potential to cause problems. The special case should be deprecated.

Expected Behavior

NA

Installed Versions

Replace this line with the output of pd.show_versions()

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions