Skip to content

Commit

Permalink
Bump version to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Oct 27, 2023
1 parent a57c7ba commit a3d45ce
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
53 changes: 30 additions & 23 deletions polars_business/polars_business/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<img
width="400"
alt="polars-business"
src="https://github.com/MarcoGorelli/polars-business/blob/d38b5a68ae7aa8d5bacacb16359dc851f2c1e637/assets/polars-business.png">
src="https://github.com/MarcoGorelli/polars-business/assets/33491632/25fc2f26-8097-4b86-85c6-c40c75c30f38">
</h1>

[![PyPI version](https://badge.fury.io/py/polars-business.svg)](https://badge.fury.io/py/polars-business)
Expand Down Expand Up @@ -52,6 +52,7 @@ Supported functions are:
- `holidays` argument, for passing custom holidays
- `weekend` argument, for passing custom a weekend (default is ('Sat', 'Sun'))
- `plb.datetime_range`: same as above, but the output will be `Datetime` dtype.
- `Expr.bdt.sub`: subtract two `Date`s and count the number of business dates between them!

See `Examples` below!

Expand All @@ -74,7 +75,10 @@ Let's shift `Date` forwards by 5 days, excluding Saturday and Sunday:

```python
result = df.with_columns(
date_shifted=plb.col("date").bdt.offset_by('5bd')
date_shifted=plb.col("date").bdt.offset_by(
'5bd',
weekend=('Sat', 'Sun'),
)
)
print(result)
```
Expand All @@ -91,17 +95,18 @@ shape: (3, 2)
└────────────┴──────────────┘
```

Let's shift `Date` forwards by 5 days, excluding Saturday and Sunday and UK holidays
Let's shift `Date` forwards by 5 days, excluding Friday, Saturday, and England holidays
for 2023 and 2024:

```python
import holidays

uk_holidays = holidays.country_holidays("UK", years=[2023, 2024])
uk_holidays = holidays.country_holidays("UK", subdiv='England', years=[2023, 2024])

result = df.with_columns(
date_shifted=plb.col("date").bdt.advance_n_days(
date_shifted=plb.col("date").bdt.offset_by(
by='5bd',
weekend=('Sat', 'Sun'),
holidays=uk_holidays,
)
)
Expand All @@ -114,33 +119,34 @@ shape: (3, 2)
│ --- ┆ --- │
│ date ┆ date │
╞════════════╪══════════════╡
│ 2023-04-03 ┆ 2023-04-11
│ 2023-04-03 ┆ 2023-04-12
│ 2023-09-01 ┆ 2023-09-08 │
│ 2024-01-04 ┆ 2024-01-11 │
└────────────┴──────────────┘
```

Let's shift `Date` forwards by 5 days, excluding only Sunday:
Count the number of business dates between two columns:
```python
result = df.with_columns(
date_shifted=plb.col("date").bdt.offset_by(
by='5bd',
weekend=['Sun'],
)
df = pl.DataFrame(
{
"start": [date(2023, 1, 4), date(2023, 5, 1), date(2023, 9, 9)],
"end": [date(2023, 2, 8), date(2023, 5, 2), date(2023, 12, 30)],
}
)
result = df.with_columns(n_business_days=plb.col("end").bdt.sub("start"))
print(result)
```
```
shape: (3, 2)
┌────────────┬──────────────┐
date ┆ date_shifted
│ --- ┆ --- │
│ date ┆ date │
╞════════════╪══════════════╡
│ 2023-04-03 ┆ 2023-04-08 │
│ 2023-09-01 ┆ 2023-09-07
2024-01-042024-01-10
└────────────┴──────────────┘
shape: (3, 3)
┌────────────┬────────────┬─────────────────┐
start ┆ end ┆ n_business_days
│ --- ┆ --- ┆ ---
│ date ┆ date ┆ i32
╞════════════╪════════════╪═════════════════╡
│ 2023-01-04 ┆ 2023-02-08 ┆ 25
│ 2023-05-01 ┆ 2023-05-02 ┆ 1
2023-09-092023-12-30 ┆ 80
└────────────┴────────────┴─────────────────┘
```

Benchmarks
Expand All @@ -150,6 +156,7 @@ Single-threaded performance is:
- about on par with NumPy
- at least an order of magnitude faster than pandas.

but note that Polars will take care of parallelisation for you.
but note that Polars will take care of parallelisation for you, and that this plugin
will fit in with Polars lazy execution.

Check out https://www.kaggle.com/code/marcogorelli/polars-business for some comparisons.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

lib = _get_shared_lib_location(__file__)

__version__ = "0.1.29"
__version__ = "0.2.0"

mapping = {"Mon": 1, "Tue": 2, "Wed": 3, "Thu": 4, "Fri": 5, "Sat": 6, "Sun": 7}

Expand Down
2 changes: 1 addition & 1 deletion polars_business/polars_business/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
version = "0.1.29"
version = "0.2.0"
requires-python = ">=3.8"

0 comments on commit a3d45ce

Please sign in to comment.