Skip to main content

Time Series Extras (e.g. business day utilities) for Polars

Project description

polars-xdt

eXtra stuff for DateTimes

polars-xdt

PyPI version Read the docs!

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


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)

Uploaded Source

Built Distribution

polars_xdt-0.4.2-cp310-cp310-manylinux_2_34_x86_64.whl (3.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.34+ x86-64

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