Skip to content

Commit 2e11d26

Browse files
committed
Updated deprecated test behavior
1 parent b60c744 commit 2e11d26

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

pandas/tests/frame/methods/test_asfreq.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ def test_asfreq_fillvalue(self):
185185
actual_series = ts.asfreq(freq="1s", fill_value=9.0)
186186
tm.assert_series_equal(expected_series, actual_series)
187187

188+
def test_asfreq_with_date_object_index(self, frame_or_series):
189+
# GH#62158 date objects lose indexing special case
190+
rng = date_range("1/1/2000", periods=20)
191+
ts = frame_or_series(np.random.default_rng(2).standard_normal(20), index=rng)
192+
ts.index = [x.date() for x in ts.index]
193+
194+
with pytest.raises(TypeError, match="Cannot compare Timestamp with datetime.date"):
195+
ts.asfreq("4h", method="ffill")
196+
188197
def test_asfreq_with_unsorted_index(self, frame_or_series):
189198
# GH#39805
190199
# Test that rows are not dropped when the datetime index is out of order

pandas/tests/indexes/datetimes/test_indexing.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ def test_get_indexer_pyarrow(self, as_td):
534534
result2 = target.get_indexer(index)
535535
tm.assert_numpy_array_equal(result2, expected)
536536

537+
def test_get_indexer_date_objs(self):
538+
# GH#62158 date objects lose indexing special case
539+
rng = date_range("1/1/2000", periods=20)
540+
result = rng.get_indexer(rng.map(lambda x: x.date()))
541+
542+
expected = np.full(len(rng), -1, dtype=np.intp)
543+
tm.assert_numpy_array_equal(result, expected)
544+
537545
def test_get_indexer(self):
538546
idx = date_range("2000-01-01", periods=3)
539547
exp = np.array([0, 1, 2], dtype=np.intp)
@@ -575,6 +583,20 @@ def test_get_indexer(self):
575583
with pytest.raises(ValueError, match="abbreviation w/o a number"):
576584
idx.get_indexer(idx[[0]], method="nearest", tolerance="foo")
577585

586+
@pytest.mark.parametrize(
587+
"target, expected",
588+
[
589+
([date(2020, 1, 1), Timestamp("2020-01-02")], np.array([-1, 1], dtype=np.intp)),
590+
([Timestamp("2020-01-01"), date(2020, 1, 2)], np.array([0, -1], dtype=np.intp)),
591+
],
592+
)
593+
def test_get_indexer_mixed_dtypes(self, target, expected):
594+
# GH#33741 regression test: mixed dtypes should not error
595+
# GH#62158 date objects lose indexing special case
596+
values = DatetimeIndex([Timestamp("2020-01-01"), Timestamp("2020-01-02")])
597+
result = values.get_indexer(target)
598+
tm.assert_numpy_array_equal(result, expected)
599+
578600
@pytest.mark.parametrize(
579601
"target, positions",
580602
[

pandas/tests/series/test_arithmetic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,20 @@ def test_datetime_understood(self, unit):
757757
expected = Series(exp_dti)
758758
tm.assert_series_equal(result, expected)
759759

760+
def test_align_date_objects_with_datetimeindex_coerced(self):
761+
# GH#62158: datetime.date objects no longer auto-align with Timestamps
762+
rng = date_range("1/1/2000", periods=20)
763+
ts = Series(np.random.default_rng(2).standard_normal(20), index=rng)
764+
765+
ts_slice = ts[5:]
766+
ts2 = ts_slice.copy()
767+
ts2.index = pd.to_datetime([x.date() for x in ts2.index])
768+
769+
result = ts + ts2
770+
expected = ts + ts[5:]
771+
expected.index = expected.index._with_freq(None)
772+
tm.assert_series_equal(result, expected)
773+
760774

761775
class TestNamePreservation:
762776
@pytest.mark.parametrize("box", [list, tuple, np.array, Index, Series, pd.array])

0 commit comments

Comments
 (0)