Beispiel #1
0
    def _maybe_cast_slice_bound(self, label, side: str, kind):
        """
        If label is a string, cast it to timedelta according to resolution.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'loc', 'getitem'} or None

        Returns
        -------
        label : object
        """
        assert kind in ["loc", "getitem", None]

        if isinstance(label, str):
            parsed = Timedelta(label)
            lbound = parsed.round(parsed.resolution_string)
            if side == "left":
                return lbound
            else:
                return lbound + to_offset(
                    parsed.resolution_string) - Timedelta(1, "ns")
        elif not isinstance(label, self._data._recognized_scalars):
            self._invalid_indexer("slice", label)

        return label
Beispiel #2
0
    def _maybe_cast_slice_bound(self, label, side: str, kind=lib.no_default):
        """
        If label is a string, cast it to timedelta according to resolution.

        Parameters
        ----------
        label : object
        side : {'left', 'right'}
        kind : {'loc', 'getitem'} or None

        Returns
        -------
        label : object
        """
        assert kind in ["loc", "getitem", None, lib.no_default]
        self._deprecated_arg(kind, "kind", "_maybe_cast_slice_bound")

        if isinstance(label, str):
            try:
                parsed = Timedelta(label)
            except ValueError as err:
                # e.g. 'unit abbreviation w/o a number'
                raise self._invalid_indexer("slice", label) from err

            # The next two lines are analogous to DTI/PI._parsed_str_to_bounds
            lower = parsed.round(parsed.resolution_string)
            upper = lower + to_offset(parsed.resolution_string) - Timedelta(
                1, "ns")
            return lower if side == "left" else upper
        elif not isinstance(label, self._data._recognized_scalars):
            raise self._invalid_indexer("slice", label)

        return label
 def _parsed_string_to_bounds(self, reso, parsed: Timedelta):
     # reso is unused, included to match signature of DTI/PI
     lbound = parsed.round(parsed.resolution_string)
     rbound = lbound + to_offset(parsed.resolution_string) - Timedelta(1, "ns")
     return lbound, rbound