Example #1
0
def test_timedelta_strings():
    inputs = [
        "1 day", "-2 hours", "3 seconds", "1 microsecond", "1003 milliseconds"
    ]
    for ts in inputs:
        assert discover(ts) == TimeDelta(unit=ts.split()[1])

    with pytest.raises(ValueError):
        TimeDelta(unit='buzz light-years')
Example #2
0
def test_timedelta():
    assert_dshape_equal(TimeDelta(), TimeDelta())
    assert_dshape_equal(TimeDelta('ns'), TimeDelta('ns'))

    with pytest.raises(AssertionError) as e:
        assert_dshape_equal(TimeDelta('us'), TimeDelta('ns'))
    assert "'us' != 'ns'" in str(e.value)
    assert '_.unit' in str(e.value)

    assert_dshape_equal(
        TimeDelta('us'),
        TimeDelta('ns'),
        check_timedelta_unit=False,
    )
def test_timedelta_str(unit):
    assert str(TimeDelta(unit=unit)) == 'timedelta[unit=%r]' % unit
def test_timedelta_repr(unit):
    assert repr(TimeDelta(unit=unit)) == 'TimeDelta(unit=%r)' % unit
def test_option_timedelta_to_numpy(unit):
    assert (Option(TimeDelta(unit=unit)).to_numpy_dtype() == np.dtype(
        'timedelta64[%s]' % unit))