Skip to content

BUG: slicing DatetimeIndex with unused and unordered levels gives incorrect results #53114

Open
@phofl

Description

@phofl

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

midx = MultiIndex(levels=[Index(["2019-12-31", "2019-12-30"], dtype="datetime64[ns]")], codes=[[0, 0]])
ser = Series([1, 2], index=midx)
ser.loc[:"2019-12-30"]

Issue Description

2019-12-31    1
2019-12-31    2
dtype: int64

This came out from the other issue, the index things it's monotonic, but this does not translate to it's levels.

cc @jbrockmendel thoughts on where to fix this? We could patch the indexing op, but not sure whether we could potentially run into other issues

Expected Behavior

empty series

Installed Versions

main

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDatetimeDatetime data dtypeIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions