Date features are an essential part of time series analysis. This document introduces helpful classes (CountryHolidays and SpecialDates) for generating holiday flags, custom date markers, and adding them to TimeGPT.

Overview

CountryHolidays

Easily attach holiday flags for multiple countries based on a list of countries.

SpecialDates

Add flags for custom events or significant dates you define.

These classes help you enrich your time series datasets with relevant date-based signals. Use them alongside standard data preprocessing techniques to enhance your model’s understanding of seasonality and special events.

source

CountryHolidays

 CountryHolidays (countries:list[str])

Given a list of countries, returns a dataframe with holidays for each country.

import pandas as pd
US_New Year’s DayUS_Memorial DayUS_Independence DayUS_Labor DayUS_Veterans DayUS_Veterans Day (observed)US_ThanksgivingUS_Christmas DayUS_Martin Luther King Jr. DayUS_Washington’s BirthdayUS_Juneteenth National Independence Day (observed)US_Christmas Day (observed)MX_Año NuevoMX_Día de la ConstituciónMX_Natalicio de Benito JuárezMX_Día del TrabajoMX_Día de la IndependenciaMX_Día de la RevoluciónMX_Transmisión del Poder Ejecutivo FederalMX_Navidad
2018-09-0300010000000000000000
2018-09-0400000000000000000000
2018-09-0500000000000000000000
2018-09-0600000000000000000000
2018-09-0700000000000000000000
c_holidays = CountryHolidays(countries=['US', 'MX'])
periods = 365 * 5
dates = pd.date_range(end='2023-09-01', periods=periods)
holidays_df = c_holidays(dates)
holidays_df.head()

source

SpecialDates

 SpecialDates (special_dates:dict[str,list[str]])

Given a dictionary of categories and dates, returns a dataframe with the special dates.

special_dates = SpecialDates(
    special_dates={
        'Important Dates': ['2021-02-26', '2020-02-26'],
        'Very Important Dates': ['2021-01-26', '2020-01-26', '2019-01-26']
    }
)
periods = 365 * 5
dates = pd.date_range(end='2023-09-01', periods=periods)
holidays_df = special_dates(dates)
holidays_df.head()
Important DatesVery Important Dates
2018-09-0300
2018-09-0400
2018-09-0500
2018-09-0600
2018-09-0700