Locale scoped holiday flag

From wenmin-wu/ds-skills · View interactive version

Locale scoped holiday flag is an AI agent skill from the GitHub repository wenmin-wu/ds-skills. Build a single per-row "day off" boolean from a holidays table with National/Regional/Local locale hierarchy and Work Day overrides that flip make-up working weekends back to working days

How to use this skill

Skill file

Overview

Retail and transaction datasets ship with holidays tables that carry locale (National/Regional/Local) and type (Holiday/Event/Work Day/Transfer) columns. A naive .merge double-counts regional holidays, ignores make-up working days, and misses the fact that "Event" rows are not days off at all. The right recipe is a deterministic rule pass: seed dayoff from weekday, then apply National holidays globally, Regional by state match, Local by city match, and finally flip Work Day rows back to working so make-up Saturdays are modeled correctly. One clean boolean feeds your forecaster. Used in the Favorita Grocery Sales Forecasting top kernels.

Quick Start

sales['dayoff'] = sales['day'].isin([6, 7])  # Sat/Sun seed

holidays = holidays[holidays['type'] != 'Event']  # events are not days off

for d, t, locale, name in zip(holidays.date, holidays.type,
                              holidays.locale, holidays.locale_name):
    mask = (sales.date == d)
    if t != 'Work Day':
        if locale == 'National':
            sales.loc[mask, 'dayoff'] = True
        elif locale == 'Regional':
            sales.loc[mask & (sales.state == name), 'dayoff'] = True
        else:  # Local
            sales.loc[mask & (sales.city == name), 'dayoff'] = True
    else:
        sales.loc[mask, 'dayoff'] = False  # make-up working day

Workflow

  1. Seed dayoff from day_of_week in {Sat, Sun}
  2. Drop rows where type == 'Event' — events are not days off
  3. Walk each remaining holiday row and apply National globally, Regional by state, Local by city
  4. Apply Work Day rows last so they override any previously-set dayoff (the precedence matters)
  5. Use the resulting boolean as a direct feature or as a segmentation key for per-day models

Key Decisions

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.