コード例 #1
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
    def test_round_tzaware(self):
        dt = Timestamp("20130101 09:10:11", tz="US/Eastern")
        result = dt.round("D")
        expected = Timestamp("20130101", tz="US/Eastern")
        assert result == expected

        dt = Timestamp("20130101 09:10:11", tz="US/Eastern")
        result = dt.round("s")
        assert result == dt
コード例 #2
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
    def test_round_tzaware(self):
        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('D')
        expected = Timestamp('20130101', tz='US/Eastern')
        assert result == expected

        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('s')
        assert result == dt
コード例 #3
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
    def test_round_tzaware(self):
        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('D')
        expected = Timestamp('20130101', tz='US/Eastern')
        assert result == expected

        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('s')
        assert result == dt
コード例 #4
0
ファイル: dataset.py プロジェクト: accurrently/evnrg
def expand_trip(
    start: pd.Timestamp,
    end: pd.Timestamp,
    val: float,
    out_df: pd.DataFrame,
    vid: str):

    b = start.round(out_df.index.freq)
    e = end.round(out_df.index.freq)
    idx = pd.date_range(b, e, freq=out_df.index.freq)
    if len(idx) > 1:
        i = idx[:-1]
        out_df.loc[i,col] = float(val/len(i)) if val >= 0 else -1
コード例 #5
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
    def test_round_day_naive(self):
        dt = Timestamp('20130101 09:10:11')
        result = dt.round('D')
        expected = Timestamp('20130101')
        assert result == expected

        dt = Timestamp('20130101 19:10:11')
        result = dt.round('D')
        expected = Timestamp('20130102')
        assert result == expected

        dt = Timestamp('20130201 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130202')
        assert result == expected

        dt = Timestamp('20130104 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130105')
        assert result == expected
コード例 #6
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
    def test_round_day_naive(self):
        dt = Timestamp('20130101 09:10:11')
        result = dt.round('D')
        expected = Timestamp('20130101')
        assert result == expected

        dt = Timestamp('20130101 19:10:11')
        result = dt.round('D')
        expected = Timestamp('20130102')
        assert result == expected

        dt = Timestamp('20130201 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130202')
        assert result == expected

        dt = Timestamp('20130104 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130105')
        assert result == expected
コード例 #7
0
ファイル: test_unary_ops.py プロジェクト: Safrone/pandas
    def test_round_minute_freq(self, test_input, freq, expected):
        # ensure timestamps that shouldn't round don't
        # GH#21262
        dt = Timestamp(test_input)
        expected = Timestamp(expected)

        result_ceil = dt.ceil(freq)
        assert result_ceil == expected
        result_floor = dt.floor(freq)
        assert result_floor == expected
        result_round = dt.round(freq)
        assert result_round == expected
コード例 #8
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
    def test_round_subsecond(self):
        # GH#14440 & GH#15578
        result = Timestamp('2016-10-17 12:00:00.0015').round('ms')
        expected = Timestamp('2016-10-17 12:00:00.002000')
        assert result == expected

        result = Timestamp('2016-10-17 12:00:00.00149').round('ms')
        expected = Timestamp('2016-10-17 12:00:00.001000')
        assert result == expected

        ts = Timestamp('2016-10-17 12:00:00.0015')
        for freq in ['us', 'ns']:
            assert ts == ts.round(freq)

        result = Timestamp('2016-10-17 12:00:00.001501031').round('10ns')
        expected = Timestamp('2016-10-17 12:00:00.001501030')
        assert result == expected
コード例 #9
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
    def test_round_subsecond(self):
        # GH#14440 & GH#15578
        result = Timestamp('2016-10-17 12:00:00.0015').round('ms')
        expected = Timestamp('2016-10-17 12:00:00.002000')
        assert result == expected

        result = Timestamp('2016-10-17 12:00:00.00149').round('ms')
        expected = Timestamp('2016-10-17 12:00:00.001000')
        assert result == expected

        ts = Timestamp('2016-10-17 12:00:00.0015')
        for freq in ['us', 'ns']:
            assert ts == ts.round(freq)

        result = Timestamp('2016-10-17 12:00:00.001501031').round('10ns')
        expected = Timestamp('2016-10-17 12:00:00.001501030')
        assert result == expected
コード例 #10
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
    def test_round_subsecond(self):
        # GH#14440 & GH#15578
        result = Timestamp("2016-10-17 12:00:00.0015").round("ms")
        expected = Timestamp("2016-10-17 12:00:00.002000")
        assert result == expected

        result = Timestamp("2016-10-17 12:00:00.00149").round("ms")
        expected = Timestamp("2016-10-17 12:00:00.001000")
        assert result == expected

        ts = Timestamp("2016-10-17 12:00:00.0015")
        for freq in ["us", "ns"]:
            assert ts == ts.round(freq)

        result = Timestamp("2016-10-17 12:00:00.001501031").round("10ns")
        expected = Timestamp("2016-10-17 12:00:00.001501030")
        assert result == expected
コード例 #11
0
ファイル: test_unary_ops.py プロジェクト: zenquiorra/pandas
    def test_round_int64(self, timestamp, freq):
        # check that all rounding modes are accurate to int64 precision
        # see GH#22591
        dt = Timestamp(timestamp)
        unit = to_offset(freq).nanos

        # test floor
        result = dt.floor(freq)
        assert result.value % unit == 0, f"floor not a {freq} multiple"
        assert 0 <= dt.value - result.value < unit, "floor error"

        # test ceil
        result = dt.ceil(freq)
        assert result.value % unit == 0, f"ceil not a {freq} multiple"
        assert 0 <= result.value - dt.value < unit, "ceil error"

        # test round
        result = dt.round(freq)
        assert result.value % unit == 0, f"round not a {freq} multiple"
        assert abs(result.value - dt.value) <= unit // 2, "round error"
        if unit % 2 == 0 and abs(result.value - dt.value) == unit // 2:
            # round half to even
            assert result.value // unit % 2 == 0, "round half to even error"
コード例 #12
0
ファイル: test_unary_ops.py プロジェクト: bkandel/pandas
    def test_round_int64(self, timestamp, freq):
        """check that all rounding modes are accurate to int64 precision
           see GH#22591
        """
        dt = Timestamp(timestamp)
        unit = to_offset(freq).nanos

        # test floor
        result = dt.floor(freq)
        assert result.value % unit == 0, "floor not a {} multiple".format(freq)
        assert 0 <= dt.value - result.value < unit, "floor error"

        # test ceil
        result = dt.ceil(freq)
        assert result.value % unit == 0, "ceil not a {} multiple".format(freq)
        assert 0 <= result.value - dt.value < unit, "ceil error"

        # test round
        result = dt.round(freq)
        assert result.value % unit == 0, "round not a {} multiple".format(freq)
        assert abs(result.value - dt.value) <= unit // 2, "round error"
        if unit % 2 == 0 and abs(result.value - dt.value) == unit // 2:
            # round half to even
            assert result.value // unit % 2 == 0, "round half to even error"
コード例 #13
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
 def test_round_invalid_arg(self):
     stamp = Timestamp('2000-01-05 05:09:15.13')
     with tm.assert_raises_regex(ValueError, _INVALID_FREQ_ERROR):
         stamp.round('foo')
コード例 #14
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
 def test_round_30min(self):
     # round
     dt = Timestamp('20130104 12:32:00')
     result = dt.round('30Min')
     expected = Timestamp('20130104 12:30:00')
     assert result == expected
コード例 #15
0
ファイル: test_unary_ops.py プロジェクト: christlc/pandas
 def test_round_invalid_arg(self):
     stamp = Timestamp('2000-01-05 05:09:15.13')
     with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG):
         stamp.round('foo')
コード例 #16
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
    def test_round_frequencies(self, freq, expected):
        stamp = Timestamp('2000-01-05 05:09:15.13')

        result = stamp.round(freq=freq)
        assert result == expected
コード例 #17
0
 def round_value(self, value: pd.Timestamp) -> pd.Timestamp:
     logger.debug(f"Rounding value: {value}")
     round_step_in_seconds = int(self._round_step.total_seconds())
     rounded_value = value.round(f"{round_step_in_seconds}s")
     return rounded_value
コード例 #18
0
 def test_round_frequencies(self, timestamp, freq, expected):
     dt = Timestamp(timestamp)
     result = dt.round(freq)
     expected = Timestamp(expected)
     assert result == expected
コード例 #19
0
ファイル: test_unary_ops.py プロジェクト: zer05um2017/pandas
    def test_round_frequencies(self, freq, expected):
        stamp = Timestamp('2000-01-05 05:09:15.13')

        result = stamp.round(freq=freq)
        assert result == expected
コード例 #20
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
 def test_round_frequencies(self, timestamp, freq, expected):
     dt = Timestamp(timestamp)
     result = dt.round(freq)
     expected = Timestamp(expected)
     assert result == expected
コード例 #21
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
 def test_round_30min(self):
     # round
     dt = Timestamp('20130104 12:32:00')
     result = dt.round('30Min')
     expected = Timestamp('20130104 12:30:00')
     assert result == expected
コード例 #22
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
 def test_round_30min(self):
     # round
     dt = Timestamp("20130104 12:32:00")
     result = dt.round("30Min")
     expected = Timestamp("20130104 12:30:00")
     assert result == expected
コード例 #23
0
ファイル: test_unary_ops.py プロジェクト: MasonGallo/pandas
 def test_round_invalid_arg(self):
     stamp = Timestamp('2000-01-05 05:09:15.13')
     with tm.assert_raises_regex(ValueError, _INVALID_FREQ_ERROR):
         stamp.round('foo')
コード例 #24
0
ファイル: test_unary_ops.py プロジェクト: 09acp/Dash-Examples
 def test_round_invalid_arg(self):
     stamp = Timestamp("2000-01-05 05:09:15.13")
     with pytest.raises(ValueError, match=INVALID_FREQ_ERR_MSG):
         stamp.round("foo")
コード例 #25
0
    def test_round(self):

        # round
        dt = Timestamp('20130101 09:10:11')
        result = dt.round('D')
        expected = Timestamp('20130101')
        self.assertEqual(result, expected)

        dt = Timestamp('20130101 19:10:11')
        result = dt.round('D')
        expected = Timestamp('20130102')
        self.assertEqual(result, expected)

        dt = Timestamp('20130201 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130202')
        self.assertEqual(result, expected)

        dt = Timestamp('20130104 12:00:00')
        result = dt.round('D')
        expected = Timestamp('20130105')
        self.assertEqual(result, expected)

        dt = Timestamp('20130104 12:32:00')
        result = dt.round('30Min')
        expected = Timestamp('20130104 12:30:00')
        self.assertEqual(result, expected)

        dti = date_range('20130101 09:10:11', periods=5)
        result = dti.round('D')
        expected = date_range('20130101', periods=5)
        tm.assert_index_equal(result, expected)

        # floor
        dt = Timestamp('20130101 09:10:11')
        result = dt.floor('D')
        expected = Timestamp('20130101')
        self.assertEqual(result, expected)

        # ceil
        dt = Timestamp('20130101 09:10:11')
        result = dt.ceil('D')
        expected = Timestamp('20130102')
        self.assertEqual(result, expected)

        # round with tz
        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('D')
        expected = Timestamp('20130101', tz='US/Eastern')
        self.assertEqual(result, expected)

        dt = Timestamp('20130101 09:10:11', tz='US/Eastern')
        result = dt.round('s')
        self.assertEqual(result, dt)

        dti = date_range('20130101 09:10:11',
                         periods=5).tz_localize('UTC').tz_convert('US/Eastern')
        result = dti.round('D')
        expected = date_range('20130101', periods=5).tz_localize('US/Eastern')
        tm.assert_index_equal(result, expected)

        result = dti.round('s')
        tm.assert_index_equal(result, dti)

        # invalid
        for freq in ['Y', 'M', 'foobar']:
            self.assertRaises(ValueError, lambda: dti.round(freq))