Skip to content

Commit 0c7eb2d

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex
1 parent 76c93e4 commit 0c7eb2d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pandas/core/indexes/datetimes.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,16 @@ def check_str_or_none(point) -> bool:
702702
def get_indexer(self, target, method=None, limit=None, tolerance=None):
703703
# Ensure Python `date` objects never match DatetimeIndex elements (GH#62158)
704704
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)
705+
if method is None and tolerance is None and tgt.dtype == object:
706+
result = super().get_indexer(
707+
tgt, method=method, limit=limit, tolerance=tolerance
708+
)
709+
mask = [
710+
isinstance(x, dt.date) and not isinstance(x, dt.datetime) for x in tgt
711+
]
712+
result = np.array(result)
713+
result[mask] = -1
714+
return result
711715
return super().get_indexer(tgt, method=method, limit=limit, tolerance=tolerance)
712716

713717
# --------------------------------------------------------------------

0 commit comments

Comments
 (0)