Time Series Extras (e.g. business day utilities) for Polars
Project description
polars-xdt
eXtra stuff for DateTimes
eXtra stuff for DateTimes in Polars.
- ✅ blazingly fast, written in Rust!
- ✅ seamless Polars integration!
- ✅ define your own custom holidays and weekends!
Installation
First, you need to install Polars.
Then, you'll need to install polars-xdt
:
pip install polars-xdt
Then, if you can run
from datetime import date
import polars_xdt as xdt
print(xdt.date_range(date(2023, 1, 1), date(2023, 1, 10), eager=True))
it means installation all worked correctly!
Read the documentation for a little tutorial and API reference.
Basic Example
Say we start with
from datetime import date
import polars as pl
import polars_xdt # noqa: F401
df = pl.DataFrame(
{"date": [date(2023, 4, 3), date(2023, 9, 1), date(2024, 1, 4)]}
)
Let's shift Date
forwards by 5 days, excluding Saturday and Sunday:
result = df.with_columns(
date_shifted=pl.col("date").xdt.offset_by(
'5bd',
weekend=('Sat', 'Sun'),
)
)
print(result)
shape: (3, 2)
┌────────────┬──────────────┐
│ date ┆ date_shifted │
│ --- ┆ --- │
│ date ┆ date │
╞════════════╪══════════════╡
│ 2023-04-03 ┆ 2023-04-10 │
│ 2023-09-01 ┆ 2023-09-08 │
│ 2024-01-04 ┆ 2024-01-11 │
└────────────┴──────────────┘
You can also count the number of business days between two given dates, specify a custom calendar holiday, and create a date range excluding workdays.
Read the documentation for more examples!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
polars_xdt-0.4.2.tar.gz
(966.9 kB
view hashes)
Built Distribution
Close
Hashes for polars_xdt-0.4.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5569bd1ac748ff01ab8617391c1fbad17ddd0d0f9c4f0842667e14c4e0a2e8c3 |
|
MD5 | c3546a42cddc2169635c5399b244ba66 |
|
BLAKE2b-256 | b453f9ff58771f1cb80268ecc9218cb875c96186159d010d5cdbd5c951f81d42 |