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
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
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"
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")
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
def test_round_frequencies(self, timestamp, freq, expected): dt = Timestamp(timestamp) result = dt.round(freq) expected = Timestamp(expected) assert result == expected