pandas icon indicating copy to clipboard operation
pandas copied to clipboard

BUG: Remove special-casing for date objects in DatetimeIndex indexing (GH#62158)

Open Aniketsy opened this issue 4 months ago • 17 comments

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 avatar Aug 26 '25 18:08 Aniketsy

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

Aniketsy avatar Aug 27 '25 04:08 Aniketsy

Mostly looks good, will need a whatsnew note

jbrockmendel avatar Sep 10 '25 21:09 jbrockmendel

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

Aniketsy avatar Sep 11 '25 09:09 Aniketsy

Can you get the CI passing?

jbrockmendel avatar Sep 22 '25 19:09 jbrockmendel

Sure, I’ll look into the CI failures.

Aniketsy avatar Sep 22 '25 19:09 Aniketsy

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?

Aniketsy avatar Sep 28 '25 06:09 Aniketsy

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

jbrockmendel avatar Sep 28 '25 18:09 jbrockmendel

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

Aniketsy avatar Sep 29 '25 04:09 Aniketsy

@Aniketsy whats the word here?

jbrockmendel avatar Oct 16 '25 21:10 jbrockmendel

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

Aniketsy avatar Oct 16 '25 23:10 Aniketsy

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

jbrockmendel avatar Oct 17 '25 15:10 jbrockmendel

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

Aniketsy avatar Oct 18 '25 03:10 Aniketsy

I've updated as per suggestions.

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

jbrockmendel avatar Oct 18 '25 21:10 jbrockmendel

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

Aniketsy avatar Oct 23 '25 08:10 Aniketsy

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'

jbrockmendel avatar Oct 27 '25 17:10 jbrockmendel

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

jbrockmendel avatar Nov 03 '25 16:11 jbrockmendel

@jbrockmendel Could you please review these changes as well? Only one test failure is left now. I’d like to wrap this up by sunday, if possible.

=========================== short test summary info ============================
FAILED pandas/tests/indexes/datetimes/test_indexing.py::TestGetIndexer::test_get_indexer_date_objs - AssertionError: numpy array are different

numpy array values are different (100.0 %)
[left]:  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
[right]: [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

Aniketsy avatar Nov 22 '25 08:11 Aniketsy