import pytest from pandas._libs.tslibs import offsets from pandas.tseries.frequencies import is_subperiod, is_superperiod @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
"freq_input,expected", [ (to_offset("10us"), offsets.Micro(10)), (offsets.Hour(), offsets.Hour()), ("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)), ], ) def test_to_offset(freq_input, expected): result = to_offset(freq_input) assert result == expected @pytest.mark.parametrize("freqstr,expected", [("-1S", -1), ("-2SM", -2), ("-1SMS", -1), ("-5min10s", -310)]) def test_to_offset_negative(freqstr, expected):