BUG: Remove special-casing for date objects in DatetimeIndex indexing (GH#62158)
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 !
@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!
Mostly looks good, will need a whatsnew note
@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.
Can you get the CI passing?
Sure, I’ll look into the CI failures.
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?
test_align_date_objects_with_datetimeindex involves alignment that will change when dates no longer match to datetimes
@jbrockmendel Thanks for the help! I’ve updated the changes, but CI is still failing. I’ll look into this in more detail.
@Aniketsy whats the word here?
@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?
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 still getting CI check fails, there are 3 test failure. I've updated as per suggestions.
I've updated as per suggestions.
Are you sure? The CI logs show pretty clearly what's wrong.
@jbrockmendel i may have missed something, could you please point out where the mistake is ?
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'
FAILED pandas/tests/indexes/datetimes/test_indexing.py::TestGetIndexer::test_get_indexer_date_objs - AssertionError: numpy array are different
@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]