test_date_features.py 925 Bytes
Newer Older
bailuo's avatar
readme  
bailuo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pandas as pd
import pytest

from nixtla.date_features import CountryHolidays, SpecialDates


@pytest.fixture
def periods():
    return 365 * 5


@pytest.fixture
def dates(periods):
    return pd.date_range(end="2023-09-01", periods=periods)


@pytest.fixture
def country_holidays():
    return CountryHolidays(countries=["US", "MX"])


@pytest.fixture
def special_dates():
    return SpecialDates(
        special_dates={
            "Important Dates": ["2021-02-26", "2020-02-26"],
            "Very Important Dates": ["2021-01-26", "2020-01-26", "2019-01-26"],
        }
    )


def test_country_holidays_shape(country_holidays, dates, periods):
    holidays_df = country_holidays(dates)
    assert len(holidays_df) == periods


def test_special_dates_shape_and_sum(special_dates, dates, periods):
    holidays_df = special_dates(dates)
    assert len(holidays_df) == periods
    assert holidays_df.sum().sum() == 5