Skip to content

Commit 6ef154e

Browse files
authored
REF: date arg not reachable in DTI._maybe_cast_slice_bound (pandas-dev#42855)
1 parent 28849e3 commit 6ef154e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pandas/core/indexes/datetimes.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
722722
if self._is_strictly_monotonic_decreasing and len(self) > 1:
723723
return upper if side == "left" else lower
724724
return lower if side == "left" else upper
725-
elif isinstance(label, (self._data._recognized_scalars, date)):
725+
elif isinstance(label, self._data._recognized_scalars):
726726
self._deprecate_mismatched_indexing(label)
727727
else:
728728
raise self._invalid_indexer("slice", label)
@@ -802,6 +802,13 @@ def check_str_or_none(point):
802802
else:
803803
return indexer
804804

805+
@doc(Index.get_slice_bound)
806+
def get_slice_bound(self, label, side: str, kind=None) -> int:
807+
# GH#42855 handle date here instead of _maybe_cast_slice_bound
808+
if isinstance(label, date) and not isinstance(label, datetime):
809+
label = Timestamp(label).to_pydatetime()
810+
return super().get_slice_bound(label, side=side, kind=kind)
811+
805812
# --------------------------------------------------------------------
806813

807814
@property

pandas/tests/indexes/datetimes/test_indexing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def test_get_slice_bounds_datetime_within(
746746
result = index.get_slice_bound(key, kind=kind, side=side)
747747
assert result == expected
748748

749-
@pytest.mark.parametrize("box", [date, datetime, Timestamp])
749+
@pytest.mark.parametrize("box", [datetime, Timestamp])
750750
@pytest.mark.parametrize("kind", ["getitem", "loc", None])
751751
@pytest.mark.parametrize("side", ["left", "right"])
752752
@pytest.mark.parametrize("year, expected", [(1999, 0), (2020, 30)])
@@ -764,7 +764,7 @@ def test_get_slice_bounds_datetime_outside(
764764
result = index.get_slice_bound(key, kind=kind, side=side)
765765
assert result == expected
766766

767-
@pytest.mark.parametrize("box", [date, datetime, Timestamp])
767+
@pytest.mark.parametrize("box", [datetime, Timestamp])
768768
@pytest.mark.parametrize("kind", ["getitem", "loc", None])
769769
def test_slice_datetime_locs(self, box, kind, tz_aware_fixture):
770770
# GH 34077

0 commit comments

Comments
 (0)