Skip to content

Conversation

@Aniketsy
Copy link
Contributor

This PR resolves (GH#62158) by removing the legacy special-casing for Python date objects in DatetimeIndex indexing logic.

What’s Changed:
Removed the special-case handling of date objects in DatetimeIndex.getitem.

Updated/added tests in pandas/tests/frame/indexing/test_indexing.py to reflect the new, consistent behavior.

Please let me know if my approach or fix needs any improvements . I’m open to feedback and happy to make changes based on suggestions.
Thankyou !

@Aniketsy
Copy link
Contributor Author

@jbrockmendel hi
Could you please review my PR for the datetime/date indexing deprecation?

I have a question about handling the new deprecation warning
Do I need to add @pytest.mark.filterwarnings("ignore:Indexing/slicing with datetime.date is deprecated") to every individual test that triggers this warning, or is there a preferred way to handle this globally for the test suite?
Also should I update every test that uses the deprecated behavior, or is there a more efficient approach?

Thanks!

@jbrockmendel
Copy link
Member

Mostly looks good, will need a whatsnew note

@Aniketsy
Copy link
Contributor Author

@jbrockmendel Thanks for the feedback! I’ve applied the suggested changes and updated the PR. Please let me know if there’s anything else that needs adjustment.

@jbrockmendel
Copy link
Member

Can you get the CI passing?

@Aniketsy
Copy link
Contributor Author

Sure, I’ll look into the CI failures.

@Aniketsy
Copy link
Contributor Author

Hi @jbrockmendel , I’ve identified that one of the CI failures is due to the pyarrow import error, which I’ve skipped. However, I’m still having trouble understanding the cause of the other three failed tests. Could you help me take a look?

@jbrockmendel
Copy link
Member

test_align_date_objects_with_datetimeindex involves alignment that will change when dates no longer match to datetimes

@Aniketsy
Copy link
Contributor Author

@jbrockmendel Thanks for the help! I’ve updated the changes, but CI is still failing. I’ll look into this in more detail.

@Aniketsy Aniketsy force-pushed the fix-datetime-indexing-62158-clean branch from 256908c to 1c59ae7 Compare October 1, 2025 05:35
@Aniketsy
Copy link
Contributor Author

@jbrockmendel i’m stuck- getting 3 check fails, i tried to fix them but haven't been successful. Could you please take a look and guide me on this?

@jbrockmendel
Copy link
Member

The test_align_date_objects_with_datetimeindex ones look like the behavior is correct and the test expected needs to be updated (with comment about the history and whatsnew note about the change).

The pyarrow one looks like you need to add a check to exclude pa.types.is_date in a place where it is implicitly (incorrectly) assuming that dtype.kind =="M" \Rightarrow pa.types.is_timestap

@Aniketsy
Copy link
Contributor Author

@jbrockmendel still getting CI check fails, there are 3 test failure. I've updated as per suggestions.

@jbrockmendel
Copy link
Member

I've updated as per suggestions.

Are you sure? The CI logs show pretty clearly what's wrong.

@Aniketsy
Copy link
Contributor Author

@jbrockmendel i may have missed something, could you please point out where the mistake is ?

else:
return indexer

def get_indexer(self, target, method=None, limit=None, tolerance=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this override really shouldnt be needed

@jbrockmendel
Copy link
Member

Look in the CI log:

    def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
        """
        Can we compare values of the given dtype to our own?
        """
        if isinstance(dtype, ArrowDtype):
            # GH#62277
            if dtype.kind != "M":
                return False
    
            pa_dtype = dtype.pyarrow_dtype
>           if (pa_dtype.tz is None) ^ (self.tz is None):
                ^^^^^^^^^^^
E           AttributeError: 'pyarrow.lib.DataType' object has no attribute 'tz'

import pyarrow as pa

if dtype.kind != "M":
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this depend on self.dtype?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have updated with self.dtype.kind or dtype.kind, please correct me if i should only use self.dtype.kind

if pa.types.is_date(pa_dtype):
return False
if pa.types.is_timestamp(pa_dtype):
if (getattr(pa_dtype, "tz", None) is None) ^ (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the condition on L6315 implies that the attribute always exists?

@jbrockmendel
Copy link
Member

FAILED pandas/tests/indexes/datetimes/test_indexing.py::TestGetIndexer::test_get_indexer_date_objs - AssertionError: numpy array are different

elif is_numeric_dtype(self.dtype):
return is_numeric_dtype(dtype)
# GH#62158
elif self.dtype.kind == "M" and dtype == object:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think object dtype is always comparable?


pa_dtype = dtype.pyarrow_dtype
if self.dtype.kind != "M" or dtype.kind != "M":
return False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems weird. wouldn't this return False if both are int64 dtypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added checks inside the arrow dtype, also in _should_compare hope I'm not going in the wrong direction. please correct me if I am.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants