Skip to content

Conversation

@suzyahyah
Copy link
Contributor

@suzyahyah suzyahyah commented Oct 7, 2025

Indexing with out of range datetime objects of higher resolution should return empty slice instead of raising KeyError.

This is to be "consistent with normal slicing, where out of range slice bounds return an empty object, and don't raise an error".

As per this issue 25803, specifically #25803 (comment), if the date is of higher resolution than the current object in the series, e.g., day>minutes, then the empty slice should be returned instead of KeyError.

@suzyahyah suzyahyah force-pushed the fix_datetime_indexing_emptyslice branch 4 times, most recently from 5cc24d3 to 628583d Compare October 7, 2025 05:22
@suzyahyah suzyahyah force-pushed the fix_datetime_indexing_emptyslice branch from 628583d to 35c218d Compare October 7, 2025 05:46
@WillAyd
Copy link
Member

WillAyd commented Oct 8, 2025

Thanks for the PR. I'm somewhat hesitant to do this without a deprecation cycle as I think people could rely on the standing behavior in their code, but let's see what @jorisvandenbossche thinks

@suzyahyah
Copy link
Contributor Author

@jbrockmendel it seems like youre working on something similar with .loc indexing?

@jbrockmendel
Copy link
Member

it seems like youre working on something similar with .loc indexing?

Not sure what you're referring to, no.

I don't think the title is accurate. This isn't about the resolution of anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants