Skip to main content

Spot holiday "bridges" and long weekends

Project description

https://img.shields.io/pypi/l/python-long-weekends.svg??style=plastic&logo=appveyor https://img.shields.io/pypi/v/python-long-weekends.svg??style=plastic&logo=appveyor https://github.com/kryptonite0/python-long-weekends/workflows/CI/badge.svg https://img.shields.io/badge/Used%20by-HIVE%20POWER-orange?color=fca311

pip install python-long-weekends

https://github.com/kryptonite0/python-long-weekends/blob/main/img/calendar.png

A simple python library to spot holiday “bridges” and long weekends. When a public holiday falls on a Tuesday or a Thursday, people typically take Monday or Friday off work to enjoy long vacations. Italians call those days “ponti” (“bridges”). To the best of my knowledge, there is no English translation for this term apart from a generic “long weekend”.

This library spots single working days that are preceded and followed by a weekend and/or a public holiday, and classifies them as “bridges”. Based on the identified “bridges”, this library also labels “long weekends”, here defined as a series of 3 or more days that are either weekend, holidays, or holiday “bridges”.

This library is intended to help generate informative features for energy consumption prediction models.

Inspired by https://stackoverflow.com/a/57865434/7059626 (thank you @jezrael).

Example Usage

Simply invoke spot_holiday_bridges and pass start and end dates, plus a list of public holiday dates. If a public holiday falls on the day before start or the day after end, it is important to include it in the list of holidays to make sure that the algorithm works correctly at the borders.

This notebook uses the example below and shows how to generate a colored calendar.

>>> import holidays as holidays_api
>>> from long_weekends.long_weekends import spot_holiday_bridges

>>> start = '2021-01-01'
>>> end = '2021-12-31'
>>> holidays = holidays_api.CH(prov='TI', years=[2020, 2021, 2022])
>>> bridges, long_weekends = spot_holiday_bridges(
        start=start, end=end, holidays=holidays)

>>> bridges
[Timestamp('2021-05-14 00:00:00'),
 Timestamp('2021-06-04 00:00:00'),
 Timestamp('2021-06-28 00:00:00')]

>>> long_weekends
[Timestamp('2021-01-01 00:00:00'),
 Timestamp('2021-01-02 00:00:00'),
 Timestamp('2021-01-03 00:00:00'),
 Timestamp('2021-03-19 00:00:00'),
 Timestamp('2021-03-20 00:00:00'),
 Timestamp('2021-03-21 00:00:00'),
 Timestamp('2021-04-02 00:00:00'),
 Timestamp('2021-04-03 00:00:00'),
 Timestamp('2021-04-04 00:00:00'),
 Timestamp('2021-04-05 00:00:00'),
 Timestamp('2021-05-13 00:00:00'),
 Timestamp('2021-05-14 00:00:00'),
 Timestamp('2021-05-15 00:00:00'),
 Timestamp('2021-05-16 00:00:00'),
 Timestamp('2021-05-22 00:00:00'),
 Timestamp('2021-05-23 00:00:00'),
 Timestamp('2021-05-24 00:00:00'),
 Timestamp('2021-06-03 00:00:00'),
 Timestamp('2021-06-04 00:00:00'),
 Timestamp('2021-06-05 00:00:00'),
 Timestamp('2021-06-06 00:00:00'),
 Timestamp('2021-06-26 00:00:00'),
 Timestamp('2021-06-27 00:00:00'),
 Timestamp('2021-06-28 00:00:00'),
 Timestamp('2021-06-29 00:00:00'),
 Timestamp('2021-10-30 00:00:00'),
 Timestamp('2021-10-31 00:00:00'),
 Timestamp('2021-11-01 00:00:00')]

License

Code and documentation are available according to the MIT License (see LICENSE).

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

python-long-weekends-0.1.1.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distribution

python_long_weekends-0.1.1-py3-none-any.whl (6.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page