CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-prophet

Automatic forecasting procedure for time series data with strong seasonal effects and multiple seasons of historical data

Pending
Overview
Eval results
Files

holidays.mddocs/

Holiday Support

Built-in holiday calendars for multiple countries and functionality for creating custom holiday definitions with flexible windows and effects. Supports automatic holiday detection and custom holiday DataFrame creation.

Capabilities

Country Holiday Functions

Built-in support for holidays from multiple countries.

def get_holiday_names(country):
    """
    Get all possible holiday names for a specific country.

    Parameters:
    - country: str, country name (e.g., 'US', 'UK', 'Germany', 'France', 'Italy')

    Returns:
    - list, list of holiday names available for the country
    """

def make_holidays_df(year_list, country, province=None, state=None):
    """
    Create a holidays DataFrame for specified years and country.

    Parameters:
    - year_list: list, list of years to include holidays for
    - country: str, country name for holiday calendar  
    - province: str, province/region name for location-specific holidays (optional)
    - state: str, state name for location-specific holidays (optional)

    Returns:
    - DataFrame with columns: 'ds' (date), 'holiday' (name), and optional
      'lower_window', 'upper_window', 'prior_scale' columns
    """

def get_country_holidays_class(country):
    """
    Get the holidays class for a specific country.

    Parameters:
    - country: str, country name

    Returns:
    - class, holidays class for the country (from holidays library)
    """

Usage Examples

Basic Country Holidays

from prophet import Prophet
from prophet.make_holidays import make_holidays_df, get_holiday_names

# See available holidays for US
us_holidays = get_holiday_names('US')
print("US Holidays:", us_holidays)

# Create holidays DataFrame for multiple years
holidays_df = make_holidays_df(
    year_list=[2019, 2020, 2021, 2022], 
    country='US'
)
print(holidays_df.head())

# Use holidays in Prophet model
model = Prophet(holidays=holidays_df)
model.fit(df)

# Or add using built-in method
model = Prophet()
model.add_country_holidays('US')
model.fit(df)

State/Province Specific Holidays

# Get holidays for specific US state
california_holidays = make_holidays_df(
    year_list=[2020, 2021, 2022],
    country='US',
    state='CA'
)

# Get holidays for Canadian province  
ontario_holidays = make_holidays_df(
    year_list=[2020, 2021, 2022],
    country='Canada',
    province='ON'
)

# Use in model
model = Prophet(holidays=california_holidays)
model.fit(df)

Custom Holiday Effects

import pandas as pd

# Create custom holidays DataFrame with custom effects
custom_holidays = pd.DataFrame({
    'ds': pd.to_datetime(['2020-07-04', '2020-12-25', '2021-07-04', '2021-12-25']),
    'holiday': ['july_4th', 'christmas', 'july_4th', 'christmas'],
    'lower_window': [-1, -2, -1, -2],  # Days before holiday
    'upper_window': [1, 1, 1, 1],      # Days after holiday
    'prior_scale': [15, 20, 15, 20]    # Custom prior scales
})

# Use custom holidays
model = Prophet(holidays=custom_holidays)
model.fit(df)

# Combine built-in and custom holidays
builtin_holidays = make_holidays_df([2020, 2021], 'US')
all_holidays = pd.concat([builtin_holidays, custom_holidays], ignore_index=True)

model = Prophet(holidays=all_holidays)
model.fit(df)

International Holiday Support

# Various country examples
countries = ['US', 'UK', 'Germany', 'France', 'Italy', 'Japan', 'India']

for country in countries:
    try:
        holidays = get_holiday_names(country)
        print(f"{country}: {len(holidays)} holidays available")
        
        # Create sample holidays DataFrame
        country_holidays = make_holidays_df([2021, 2022], country)
        print(f"  Sample holidays for {country}:")
        print(f"  {country_holidays['holiday'].unique()[:5]}")  # First 5 holidays
        print()
    except Exception as e:
        print(f"Error getting holidays for {country}: {e}")

Holiday Effect Analysis

# After fitting model with holidays, analyze their effects
model = Prophet()
model.add_country_holidays('US')
model.fit(df)

forecast = model.predict(future)

# Check if holiday components are in forecast
holiday_columns = [col for col in forecast.columns if 'holiday' in col.lower()]
print("Holiday effect columns:", holiday_columns)

# Plot holiday effects if using plot functions
from prophet.plot import plot_components
fig = plot_components(model, forecast)
# This will show individual holiday effects if present

Install with Tessl CLI

npx tessl i tessl/pypi-prophet

docs

core-forecasting.md

diagnostics.md

holidays.md

index.md

plotting.md

serialization.md

utilities.md

tile.json