Skip to content

Commit 2f98bd4

Browse files
committed
BUG: Remove special-casing for date objects in DatetimeIndex indexing (GH#62157)
1 parent 29662c0 commit 2f98bd4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

pandas/core/indexes/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
no_default,
4040
)
4141
from pandas._libs.tslibs import (
42-
OutOfBoundsDatetime,
4342
Timestamp,
4443
tz_compare,
4544
)
@@ -6204,11 +6203,6 @@ def _maybe_downcast_for_indexing(self, other: Index) -> tuple[Index, Index]:
62046203
# standardize on UTC
62056204
return self.tz_convert("UTC"), other.tz_convert("UTC")
62066205

6207-
elif self.inferred_type == "date" and isinstance(other, ABCDatetimeIndex):
6208-
try:
6209-
return type(other)(self), other
6210-
except OutOfBoundsDatetime:
6211-
return self, other
62126206
elif self.inferred_type == "timedelta" and isinstance(other, ABCTimedeltaIndex):
62136207
# TODO: we dont have tests that get here
62146208
return type(other)(self), other

pandas/core/series.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6073,9 +6073,7 @@ def eq(
60736073
Parameters
60746074
----------
60756075
other : Series or scalar value
6076-
The second operand in this operation. Only `np.ndarray`, `list`, `tuple`,
6077-
and `Series` are considered "list-like" by pandas. All other types will
6078-
be treated as scalar values.
6076+
The second operand in this operation.
60796077
level : int or name
60806078
Broadcast across a level, matching Index values on the
60816079
passed MultiIndex level.

pandas/tests/frame/indexing/test_indexing.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,17 @@ def test_add_new_column_infer_string():
18801880
tm.assert_frame_equal(df, expected)
18811881

18821882

1883+
def test_datetime_indexer_consistency_pyarrow_date32():
1884+
# GH#62158
1885+
ser = Series(["2016-01-01"], dtype="date32[pyarrow]")
1886+
ser3 = ser.astype("datetime64[ns]")
1887+
dti = Index(ser3)
1888+
# All should be consistent
1889+
assert dti.get_loc(ser[0]) == 0
1890+
tm.assert_numpy_array_equal(dti.get_indexer(ser.values), [0])
1891+
tm.assert_numpy_array_equal(dti.get_indexer(ser.values.astype(object)), [0])
1892+
1893+
18831894
class TestSetitemValidation:
18841895
# This is adapted from pandas/tests/arrays/masked/test_indexing.py
18851896
def _check_setitem_invalid(self, df, invalid, indexer):

0 commit comments

Comments
 (0)