Skip to content

Commit 256908c

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex
1 parent 1c59ae7 commit 256908c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pandas/core/indexes/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from collections import abc
4+
import datetime as dt
45
from datetime import datetime
56
import functools
67
from itertools import zip_longest
@@ -177,6 +178,7 @@
177178
disallow_ndim_indexing,
178179
is_valid_positional_slice,
179180
)
181+
from pandas.core.indexes.datetimes import DatetimeIndex
180182
from pandas.core.indexes.frozen import FrozenList
181183
from pandas.core.missing import clean_reindex_fill_method
182184
from pandas.core.ops import get_op_result_name
@@ -3668,6 +3670,15 @@ def get_indexer(
36683670
Notice that the return value is an array of locations in ``index``
36693671
and ``x`` is marked by -1, as it is not in ``index``.
36703672
"""
3673+
if isinstance(self, DatetimeIndex):
3674+
if hasattr(target, "__iter__") and not isinstance(target, (str, bytes)):
3675+
seq = list(target)
3676+
if seq and all(
3677+
isinstance(x, dt.date) and not isinstance(x, dt.datetime)
3678+
for x in seq
3679+
):
3680+
return np.full(len(seq), -1, dtype=np.intp)
3681+
36713682
method = clean_reindex_fill_method(method)
36723683
orig_target = target
36733684
target = self._maybe_cast_listlike_indexer(target)

pandas/tests/series/test_arithmetic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def test_align_date_objects_with_datetimeindex(self):
769769
result2 = ts2 + ts
770770

771771
date_labels = [x.date() for x in rng[5:]]
772-
expected_index = Index(date_labels + list(rng), dtype=object)
772+
expected_index = Index(list(rng) + date_labels, dtype=object)
773773

774774
# Length and index checks
775775
assert len(result) == 35

0 commit comments

Comments
 (0)