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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file python-long-weekends-0.1.1.tar.gz.

File metadata

  • Download URL: python-long-weekends-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.10

File hashes

Hashes for python-long-weekends-0.1.1.tar.gz
Algorithm Hash digest
SHA256 732aab795abced315f968d4f0d03826911ec7d092f48d1e392e362807c5a85ea
MD5 2b9dd3f008c4ebc2bf3179b2fb00266b
BLAKE2b-256 b10762a0fa1ce737b9d3ff622bb350e3414bcc19c5ebe33c71f9a09c129f22df

See more details on using hashes here.

File details

Details for the file python_long_weekends-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: python_long_weekends-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.8.10

File hashes

Hashes for python_long_weekends-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 16ed32e631e7b1c2bbec579701d706bf2592e749bb6ac54f36f04e63469c3560
MD5 1cbd0e91730702c01d4e2422aea229ec
BLAKE2b-256 2d67d57232abc499ca1b2aac5a4ec907dd92481c8af90bde6edcd093a771de37

See more details on using hashes here.

Supported by

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