Skip to content

Commit 8f39dbc

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex
1 parent 0d81824 commit 8f39dbc

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

pandas/core/indexes/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import warnings
2020

2121
import numpy as np
22+
import pyarrow as pa
2223

2324
from pandas._config import (
2425
get_option,
@@ -6303,6 +6304,19 @@ def _is_comparable_dtype(self, dtype: DtypeObj) -> bool:
63036304
return dtype.kind == "b"
63046305
elif is_numeric_dtype(self.dtype):
63056306
return is_numeric_dtype(dtype)
6307+
# GH#62158
6308+
elif isinstance(dtype, ArrowDtype):
6309+
if dtype.kind != "M":
6310+
return False
6311+
pa_dtype = dtype.pyarrow_dtype
6312+
if pa.types.is_date(pa_dtype):
6313+
return False
6314+
if pa.types.is_timestamp(pa_dtype):
6315+
if (getattr(pa_dtype, "tz", None) is None) ^ (
6316+
getattr(self, "tz", None) is None
6317+
):
6318+
return False
6319+
return True
63066320
# TODO: this was written assuming we only get here with object-dtype,
63076321
# which is no longer correct. Can we specialize for EA?
63086322
return True

pandas/core/indexes/datetimes.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
tz_to_dtype,
4343
)
4444
import pandas.core.common as com
45-
from pandas.core.indexes.api import ensure_index
4645
from pandas.core.indexes.base import (
4746
Index,
4847
maybe_extract_name,
@@ -699,21 +698,6 @@ def check_str_or_none(point) -> bool:
699698
else:
700699
return indexer
701700

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 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
715-
return super().get_indexer(tgt, method=method, limit=limit, tolerance=tolerance)
716-
717701
# --------------------------------------------------------------------
718702

719703
@property

0 commit comments

Comments
 (0)