https://github.com/mrjsj/polars-holidays
A polars plugin for determining if a date is a holiday
https://github.com/mrjsj/polars-holidays
calendar date datetime holidays polars
Last synced: 8 months ago
JSON representation
A polars plugin for determining if a date is a holiday
- Host: GitHub
- URL: https://github.com/mrjsj/polars-holidays
- Owner: mrjsj
- License: mit
- Created: 2025-01-07T15:04:09.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-01-09T11:41:48.000Z (10 months ago)
- Last Synced: 2025-01-19T05:41:36.250Z (10 months ago)
- Topics: calendar, date, datetime, holidays, polars
- Language: Rust
- Homepage:
- Size: 572 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-polars - polars-holidays - Polars plugin for determining if a date is a holiday by [@mrjsj](https://github.com/mrjsj). (Libraries/Packages/Scripts / Polars plugins)
README
# Polars Holidays
Plugin for the polars dataframe library to work with holidays.
## Installation
```bash
pip install polars-holidays
```
## Usage
To use the is_holiday and get_holiday functions in Polars, follow the examples below.
Importing the Library
```python
import polars as pl
import polars_holidays as plh
```
### Check if a Date is a Holiday
You can check if a specific date is a holiday for a given country using the is_holiday function.
Use ISO-2 Country code in lowercase.
```python
df = pl.DataFrame(
{
"date": ["2023-01-01", "2023-12-25"],
"country": ["us", "us"]
}
)
df = df.with_columns(
is_holiday=plh.is_holiday("date", "country")
)
```
### Get the name of the holiday(s)
To retrieve the name of the holiday for a specific date and country, use the get_holiday function. If there are multiple holidays on the same day, it will return as a semi-colon separated list of holidays.
```python
df = df.with_columns(
holiday_name=plh.get_holiday("date", "country")
)
```
### Single country
If you don't have a column with country code, and just want to specify a single country, you can use `pl.Lit("us")`:
df = df.with_columns(
holiday_name=plh.get_holiday("date", pl.Lit("us"))
)