Beispiel #1
0
    def test_indexer_between_time_non_nano(self, unit):
        # For simple cases like this, the non-nano indexer_between_time
        #  should match the nano result

        rng = date_range("1/1/2000", "1/5/2000", freq="5min")
        arr_nano = rng._data._ndarray

        arr = arr_nano.astype(f"M8[{unit}]")

        dta = type(rng._data)._simple_new(arr, dtype=arr.dtype)
        dti = DatetimeIndex(dta)
        assert dti.dtype == arr.dtype

        tic = time(1, 25)
        toc = time(2, 29)

        result = dti.indexer_between_time(tic, toc)
        expected = rng.indexer_between_time(tic, toc)
        tm.assert_numpy_array_equal(result, expected)

        # case with non-zero micros in arguments
        tic = time(1, 25, 0, 45678)
        toc = time(2, 29, 0, 1234)

        result = dti.indexer_between_time(tic, toc)
        expected = rng.indexer_between_time(tic, toc)
        tm.assert_numpy_array_equal(result, expected)
Beispiel #2
0
    def all_minutes(self):
        """
        返回表示此日历中所有分钟的`DatetimeIndex`。
        """
        opens_in_ns = self._opens.values.astype(
            'datetime64[ns]',
        ).view('int64')

        closes_in_ns = self._closes.values.astype(
            'datetime64[ns]',
        ).view('int64')
        # compute_all_minutes假设每天仅包含连续分钟块
        dts = DatetimeIndex(
            compute_all_minutes(opens_in_ns, closes_in_ns),
            tz='utc',
        )
        # 如果有午休,则排除午休时段
        if self.use_lunch_break:
            # 需要使用utc时间
            utc_start = days_at_time(
                [dts[0].date()], self.lunch_break_start_time, self.tz).time[0]
            utc_end = days_at_time(
                [dts[0].date()], self.lunch_break_end_time, self.tz).time[0]
            locs = dts.indexer_between_time(
                utc_start, utc_end, include_start=True, include_end=True)
            return dts.delete(locs)
        else:
            return dts