コード例 #1
0
from pandas import Timedelta

import pandas.tseries.frequencies as frequencies
import pandas.tseries.offsets as offsets


@pytest.mark.parametrize(
    "freq_input,expected",
    [
        (frequencies.to_offset("10us"), offsets.Micro(10)),
        (offsets.Hour(), offsets.Hour()),
        ((5, "T"), offsets.Minute(5)),
        ("2h30min", offsets.Minute(150)),
        ("2h 30min", offsets.Minute(150)),
        ("2h30min15s", offsets.Second(150 * 60 + 15)),
        ("2h 60min", offsets.Hour(3)),
        ("2h 20.5min", offsets.Second(8430)),
        ("1.5min", offsets.Second(90)),
        ("0.5S", offsets.Milli(500)),
        ("15l500u", offsets.Micro(15500)),
        ("10s75L", offsets.Milli(10075)),
        ("1s0.25ms", offsets.Micro(1000250)),
        ("1s0.25L", offsets.Micro(1000250)),
        ("2800N", offsets.Nano(2800)),
        ("2SM", offsets.SemiMonthEnd(2)),
        ("2SM-16", offsets.SemiMonthEnd(2, day_of_month=16)),
        ("2SMS-14", offsets.SemiMonthBegin(2, day_of_month=14)),
        ("2SMS-15", offsets.SemiMonthBegin(2)),
    ],
)
コード例 #2
0
    def test_to_offset_multiple(self):
        freqstr = '2h30min'
        freqstr2 = '2h 30min'

        result = frequencies.to_offset(freqstr)
        assert (result == frequencies.to_offset(freqstr2))
        expected = offsets.Minute(150)
        assert (result == expected)

        freqstr = '2h30min15s'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Second(150 * 60 + 15)
        assert (result == expected)

        freqstr = '2h 60min'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Hour(3)
        assert (result == expected)

        freqstr = '2h 20.5min'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Second(8430)
        assert (result == expected)

        freqstr = '1.5min'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Second(90)
        assert (result == expected)

        freqstr = '0.5S'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Milli(500)
        assert (result == expected)

        freqstr = '15l500u'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Micro(15500)
        assert (result == expected)

        freqstr = '10s75L'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Milli(10075)
        assert (result == expected)

        freqstr = '1s0.25ms'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Micro(1000250)
        assert (result == expected)

        freqstr = '1s0.25L'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Micro(1000250)
        assert (result == expected)

        freqstr = '2800N'
        result = frequencies.to_offset(freqstr)
        expected = offsets.Nano(2800)
        assert (result == expected)

        freqstr = '2SM'
        result = frequencies.to_offset(freqstr)
        expected = offsets.SemiMonthEnd(2)
        assert (result == expected)

        freqstr = '2SM-16'
        result = frequencies.to_offset(freqstr)
        expected = offsets.SemiMonthEnd(2, day_of_month=16)
        assert (result == expected)

        freqstr = '2SMS-14'
        result = frequencies.to_offset(freqstr)
        expected = offsets.SemiMonthBegin(2, day_of_month=14)
        assert (result == expected)

        freqstr = '2SMS-15'
        result = frequencies.to_offset(freqstr)
        expected = offsets.SemiMonthBegin(2)
        assert (result == expected)

        # malformed
        with tm.assertRaisesRegexp(ValueError, 'Invalid frequency: 2h20m'):
            frequencies.to_offset('2h20m')
コード例 #3
0
def test_period_str_to_code(obj, expected):
    assert _period_str_to_code(obj) == expected


@pytest.mark.parametrize(
    "p1,p2,expected",
    [
        # Input validation.
        (offsets.MonthEnd(), None, False),
        (offsets.YearEnd(), None, False),
        (None, offsets.YearEnd(), False),
        (None, offsets.MonthEnd(), False),
        (None, None, False),
        (offsets.YearEnd(), offsets.MonthEnd(), True),
        (offsets.Hour(), offsets.Minute(), True),
        (offsets.Second(), offsets.Milli(), True),
        (offsets.Milli(), offsets.Micro(), True),
        (offsets.Micro(), offsets.Nano(), True)
    ])
def test_super_sub_symmetry(p1, p2, expected):
    assert is_superperiod(p1, p2) is expected
    assert is_subperiod(p2, p1) is expected


@pytest.mark.parametrize("freq,expected,aliases", [
    ("D", 6000, ["DAY", "DLY", "DAILY"]),
    ("M", 3000, ["MTH", "MONTH", "MONTHLY"]),
    ("N", 12000, ["NANOSECOND", "NANOSECONDLY"]),
    ("H", 7000, ["HR", "HOUR", "HRLY", "HOURLY"]),
    ("T", 8000, ["minute", "MINUTE", "MINUTELY"]),
    ("L", 10000, ["MILLISECOND", "MILLISECONDLY"]),