Skip to content

Commit 610868f

Browse files
committed
BUG: Remove special-casing for Python date objects in DatetimeIndex.get_indexer and update whatsnew note (#62158)
1 parent f8e4974 commit 610868f

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,8 @@ Datetimelike
889889
- Bug in constructing arrays with :class:`ArrowDtype` with ``timestamp`` type incorrectly allowing ``Decimal("NaN")`` (:issue:`61773`)
890890
- Bug in constructing arrays with a timezone-aware :class:`ArrowDtype` from timezone-naive datetime objects incorrectly treating those as UTC times instead of wall times like :class:`DatetimeTZDtype` (:issue:`61775`)
891891
- Bug in setting scalar values with mismatched resolution into arrays with non-nanosecond ``datetime64``, ``timedelta64`` or :class:`DatetimeTZDtype` incorrectly truncating those scalars (:issue:`56410`)
892+
- Removed the special casing for sequences of Python ``date`` objects in ``DatetimeIndex.get_indexer`` and related indexing logic.
893+
Indexing a ``DatetimeIndex`` with Python ``date`` objects now behaves consistently with other types. (:issue:`62158`)
892894

893895
Timedelta
894896
^^^^^^^^^

pandas/tests/indexes/datetimes/test_indexing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ def test_contains_nonunique(self, vals):
514514

515515
class TestGetIndexer:
516516
def test_get_indexer_date_objs(self):
517+
# Behavior for get_indexer with date objects changed in GH#62158.
517518
rng = date_range("1/1/2000", periods=20)
518519

519520
result = rng.get_indexer(rng.map(lambda x: x.date()))

pandas/tests/reshape/merge/test_merge.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,17 +2132,17 @@ def test_dtype_on_categorical_dates(self):
21322132

21332133
expected_outer = DataFrame(
21342134
[
2135-
[date(2001, 1, 1), 1.1, 1.3],
2136-
[date(2001, 1, 2), 1.3, np.nan],
2137-
[date(2001, 1, 3), np.nan, 1.4],
2135+
[pd.Timestamp("2001-01-01").date(), 1.1, 1.3],
2136+
[pd.Timestamp("2001-01-02").date(), 1.3, np.nan],
2137+
[pd.Timestamp("2001-01-03").date(), np.nan, 1.4],
21382138
],
21392139
columns=["date", "num2", "num4"],
21402140
)
21412141
result_outer = merge(df, df2, how="outer", on=["date"])
21422142
tm.assert_frame_equal(result_outer, expected_outer)
21432143

21442144
expected_inner = DataFrame(
2145-
[[date(2001, 1, 1), 1.1, 1.3]],
2145+
[[pd.Timestamp("2001-01-01").date(), 1.1, 1.3]],
21462146
columns=["date", "num2", "num4"],
21472147
)
21482148
result_inner = merge(df, df2, how="inner", on=["date"])

pandas/tests/series/test_arithmetic.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,7 @@ def test_align_date_objects_with_datetimeindex(self):
763763

764764
ts_slice = ts[5:]
765765
ts2 = ts_slice.copy()
766-
# Explicitly convert date objects to Timestamps for alignment
767-
ts2.index = [pd.Timestamp(x.date()) for x in ts2.index]
766+
ts2.index = [x.date() for x in ts2.index]
768767

769768
result = ts + ts2
770769
result2 = ts2 + ts

0 commit comments

Comments
 (0)