|
25 | 25 | )
|
26 | 26 | from pandas._libs.tslibs import (
|
27 | 27 | Resolution,
|
28 |
| - parsing, |
29 | 28 | timezones,
|
30 | 29 | to_offset,
|
31 | 30 | )
|
@@ -686,48 +685,10 @@ def _maybe_cast_for_get_loc(self, key) -> Timestamp:
|
686 | 685 | key = key.tz_convert(self.tz)
|
687 | 686 | return key
|
688 | 687 |
|
| 688 | + @doc(DatetimeTimedeltaMixin._maybe_cast_slice_bound) |
689 | 689 | def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
|
690 |
| - """ |
691 |
| - If label is a string, cast it to datetime according to resolution. |
692 |
| -
|
693 |
| - Parameters |
694 |
| - ---------- |
695 |
| - label : object |
696 |
| - side : {'left', 'right'} |
697 |
| - kind : {'loc', 'getitem'} or None |
698 |
| -
|
699 |
| - Returns |
700 |
| - ------- |
701 |
| - label : object |
702 |
| -
|
703 |
| - Notes |
704 |
| - ----- |
705 |
| - Value of `side` parameter should be validated in caller. |
706 |
| - """ |
707 |
| - assert kind in ["loc", "getitem", None, lib.no_default] |
708 |
| - self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound") |
709 |
| - |
710 |
| - if isinstance(label, str): |
711 |
| - try: |
712 |
| - parsed, reso = self._parse_with_reso(label) |
713 |
| - except parsing.DateParseError as err: |
714 |
| - raise self._invalid_indexer("slice", label) from err |
715 |
| - |
716 |
| - lower, upper = self._parsed_string_to_bounds(reso, parsed) |
717 |
| - # lower, upper form the half-open interval: |
718 |
| - # [parsed, parsed + 1 freq) |
719 |
| - # because label may be passed to searchsorted |
720 |
| - # the bounds need swapped if index is reverse sorted and has a |
721 |
| - # length > 1 (is_monotonic_decreasing gives True for empty |
722 |
| - # and length 1 index) |
723 |
| - if self._is_strictly_monotonic_decreasing and len(self) > 1: |
724 |
| - return upper if side == "left" else lower |
725 |
| - return lower if side == "left" else upper |
726 |
| - elif isinstance(label, self._data._recognized_scalars): |
727 |
| - self._deprecate_mismatched_indexing(label) |
728 |
| - else: |
729 |
| - raise self._invalid_indexer("slice", label) |
730 |
| - |
| 690 | + label = super()._maybe_cast_slice_bound(label, side, kind=kind) |
| 691 | + self._deprecate_mismatched_indexing(label) |
731 | 692 | return self._maybe_cast_for_get_loc(label)
|
732 | 693 |
|
733 | 694 | def slice_indexer(self, start=None, end=None, step=None, kind=lib.no_default):
|
@@ -804,7 +765,7 @@ def check_str_or_none(point):
|
804 | 765 | return indexer
|
805 | 766 |
|
806 | 767 | @doc(Index.get_slice_bound)
|
807 |
| - def get_slice_bound(self, label, side: str, kind=None) -> int: |
| 768 | + def get_slice_bound(self, label, side: str, kind=lib.no_default) -> int: |
808 | 769 | # GH#42855 handle date here instead of _maybe_cast_slice_bound
|
809 | 770 | if isinstance(label, date) and not isinstance(label, datetime):
|
810 | 771 | label = Timestamp(label).to_pydatetime()
|
|
0 commit comments