Beispiel #1
0
import re

import pytest

from pandas._libs.tslibs import Timedelta, offsets, to_offset


@pytest.mark.parametrize(
    "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):
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
Beispiel #3
0
        (("D", 1), (get_freq_code("D")[0], 1)),
        (("A", 3), (get_freq_code("A")[0], 3)),
        (("M", -2), (get_freq_code("M")[0], -2)),
        ((5, "T"), (FreqGroup.FR_MIN, 5)),
        # Numeric Tuple.
        ((1000, 1), (1000, 1)),
        # Offsets.
        (offsets.Day(), (get_freq_code("D")[0], 1)),
        (offsets.Day(3), (get_freq_code("D")[0], 3)),
        (offsets.Day(-2), (get_freq_code("D")[0], -2)),
        (offsets.MonthEnd(), (get_freq_code("M")[0], 1)),
        (offsets.MonthEnd(3), (get_freq_code("M")[0], 3)),
        (offsets.MonthEnd(-2), (get_freq_code("M")[0], -2)),
        (offsets.Week(), (get_freq_code("W")[0], 1)),
        (offsets.Week(3), (get_freq_code("W")[0], 3)),
        (offsets.Week(-2), (get_freq_code("W")[0], -2)),
        (offsets.Hour(), (FreqGroup.FR_HR, 1)),
        # Monday is weekday=0.
        (offsets.Week(weekday=1), (get_freq_code("W-TUE")[0], 1)),
        (offsets.Week(3, weekday=0), (get_freq_code("W-MON")[0], 3)),
        (offsets.Week(-2, weekday=4), (get_freq_code("W-FRI")[0], -2)),
    ],
)
def test_get_freq_code(freq_input, expected):
    assert get_freq_code(freq_input) == expected


def test_get_code_invalid():
    with pytest.raises(ValueError, match="Invalid frequency"):
        get_freq_code((5, "baz"))
import re

import pytest

from pandas._libs.tslibs import Timedelta, offsets, to_offset


@pytest.mark.parametrize(
    "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):