Skip to content

Commit f60be17

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex
1 parent 598f762 commit f60be17

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
tz_to_dtype,
4343
)
4444
import pandas.core.common as com
45+
from pandas.core.indexes.api import ensure_index
4546
from pandas.core.indexes.base import (
4647
Index,
4748
maybe_extract_name,
@@ -698,6 +699,17 @@ def check_str_or_none(point) -> bool:
698699
else:
699700
return indexer
700701

702+
def get_indexer(self, target, method=None, limit=None, tolerance=None):
703+
# Ensure Python `date` objects never match DatetimeIndex elements (GH#62158)
704+
tgt = ensure_index(target)
705+
if (
706+
method is None
707+
and tolerance is None
708+
and getattr(tgt, "inferred_type", None) == "date"
709+
):
710+
return np.full(len(tgt), -1, dtype=np.intp)
711+
return super().get_indexer(tgt, method=method, limit=limit, tolerance=tolerance)
712+
701713
# --------------------------------------------------------------------
702714

703715
@property

0 commit comments

Comments
 (0)