Fetches holiday information from https://github.com/vacanza/holidays and applies reverse lagging (that is, future indicators) for time series training.
Project description
holiday-rlag
Fetches holiday information using the holidays library and applies reverse lagging (future indicators) for time series training.
Features
- Fetches holidays for a given date range and country
- Adds reverse lag markers for holidays using one column per holiday type
- Flags for Easter, Christmas, and bank holidays
Installation
pip install holiday-rlag
# or, if using uv:
uv pip install .
Requirements
- Python 3.11+
- holidays
Usage
from holiday_rlag.laggedholidays import fetch_holidays
import datetime
date_start = datetime.date(2023, 1, 1)
date_end = datetime.date(2023, 12, 31)
holidays = fetch_holidays(date_start, date_end, country_code="DE", reverse_lag=7)
df = pd.DataFrame(holidays)
API
fetch_holidays(...)
Fetches holidays for a given date range and country, with optional reverse lagging.
Parameters:
date_start(datetime.date): Start datedate_end(datetime.date): End datecountry_code(str): Country code (default: "DE")reverse_lag(int): Number of days to look back for reverse lagging (default: 7)lag_peak_on_holiday(bool): IfTrue, the holiday date gets the maximum marker; otherwise the day before does (default:False)col_is_easter,col_is_christmas,col_is_bank_holiday: Column names for flagscol_lag_prefix,col_lag_suffix: Prefix/suffix for lag marker columns
Returns:
list[dict]: List of dictionaries with holiday flags and lag marker values
Note: The result is not a complete date list. Fill all dates you need and apply fillna(0) if converting to a DataFrame.
For each holiday type, the reverse lag output uses a single column such as is_easter_in_next_days. If a matching holiday occurs within the configured lag window, the column contains an approach counter that increases toward the holiday. By default, the highest value is on the day before the holiday. Set lag_peak_on_holiday=True if the holiday date itself should receive the maximum value. Otherwise it stays empty and can be filled with 0 after conversion to a DataFrame.
Example Output
[
{
"date": "2023-04-07",
"is_easter": 0,
"is_christmas": 0,
"is_bank_holiday": 1,
"is_easter_in_next_days": 2,
"is_bank_holiday_in_next_days": 2
},
{
"date": "2023-04-09",
"is_easter": 1,
"is_christmas": 0,
"is_bank_holiday": 1
},
...
]
License
MIT License. See LICENSE file.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file holiday_rlag-1.1.0.tar.gz.
File metadata
- Download URL: holiday_rlag-1.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfd20b5df5743b5ac1a51fd0b174a2aeb7cd5e8380bfea492fa5224cfda4432b
|
|
| MD5 |
2f4af047c3e932a1f82cd31726360603
|
|
| BLAKE2b-256 |
ffaab31014bf80740b2514b6960fcbfa9cf6065b3a6e91c404c875b9ca6a6837
|
File details
Details for the file holiday_rlag-1.1.0-py3-none-any.whl.
File metadata
- Download URL: holiday_rlag-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5694d8d7fc9397bf0d7731a87316956600d1cf30134a8162b4850b1fe3329e02
|
|
| MD5 |
6a2c2523bdd26ed4b0b87f6d128ce549
|
|
| BLAKE2b-256 |
3dc1f5c35a19464121c604487e9935697a37e0da6f3c2d743ff4306f765bc551
|