Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite all as toplevel funcs #58

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ rust-toolchain.toml
*.bat
*.js
docs/_build
*.so
docs/api/*
*.so
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install-release: venv
pre-commit: venv
cargo fmt --all && cargo clippy --all-features
venv/bin/python -m ruff check . --fix --exit-non-zero-on-fix
venv/bin/python -m ruff format
venv/bin/python -m ruff format polars_xdt tests
venv/bin/python -m mypy polars_xdt tests

test: venv
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ Then, you'll need to install `polars-xdt`:
pip install polars-xdt
```

Then, if you can run
```python
import polars as pl
import polars_xdt # noqa: F401

print(pl.col('a').xdt)
```
and see something like `<polars_xdt.ExprXDTNamespace at 0x7f5bc943fc10>`,
it means installation all worked correctly!

Read the [documentation](https://marcogorelli.github.io/polars-xdt-docs/) for a little tutorial and API reference.

Basic Example
Expand All @@ -49,7 +39,7 @@ Say we start with
from datetime import date

import polars as pl
import polars_xdt # noqa: F401
import polars_xdt as xdt


df = pl.DataFrame(
Expand All @@ -61,7 +51,8 @@ Let's shift `Date` forwards by 5 days, excluding Saturday and Sunday:

```python
result = df.with_columns(
date_shifted=pl.col("date").xdt.offset_by(
date_shifted=xdt.offset_by(
'date',
'5bd',
weekend=('Sat', 'Sun'),
)
Expand All @@ -80,6 +71,9 @@ shape: (3, 2)
│ 2024-01-04 ┆ 2024-01-11 │
└────────────┴──────────────┘
```
Note that `polars-xdt` also registers a `xdt` namespace in the `Expression` class, so you
could equivalently write the above using `pl.col('date').xdt.offset_by('5bd')` (but note
that then type-checking would not recognise the `xdt` attribute).

Read the [documentation](https://marcogorelli.github.io/polars-xdt-docs/) for more examples!

Expand Down
20 changes: 9 additions & 11 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ API

polars_xdt.date_range
polars_xdt.workday_count
polars_xdt.ExprXDTNamespace.base_utc_offset
polars_xdt.ExprXDTNamespace.ceil
polars_xdt.ExprXDTNamespace.day_name
polars_xdt.ExprXDTNamespace.dst_offset
polars_xdt.ExprXDTNamespace.format_localized
polars_xdt.ExprXDTNamespace.from_local_datetime
polars_xdt.ExprXDTNamespace.is_workday
polars_xdt.ExprXDTNamespace.month_name
polars_xdt.ExprXDTNamespace.offset_by
polars_xdt.ExprXDTNamespace.to_local_datetime
polars_xdt.ExprXDTNamespace.to_julian_date
polars_xdt.ceil
polars_xdt.day_name
polars_xdt.format_localized
polars_xdt.from_local_datetime
polars_xdt.is_workday
polars_xdt.month_name
polars_xdt.offset_by
polars_xdt.to_local_datetime
polars_xdt.to_julian_date
6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.ceil.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.format_localized.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.from_local_datetime.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.is_workday.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.offset_by.rst

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/polars_xdt.ExprXDTNamespace.to_local_datetime.rst

This file was deleted.

16 changes: 7 additions & 9 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Say we start with
from datetime import date

import polars as pl
import polars_xdt # noqa: F401
import polars_xdt as xdt


df = pl.DataFrame(
Expand All @@ -21,10 +21,7 @@ Let's shift `Date` forwards by 5 days, excluding Saturday and Sunday:
.. code-block:: python

result = df.with_columns(
date_shifted=pl.col("date").xdt.offset_by(
'5bd',
weekend=('Sat', 'Sun'),
)
date_shifted=xdt.offset_by('date', '5bd', weekend=('Sat', 'Sun'))
)
print(result)

Expand Down Expand Up @@ -52,10 +49,11 @@ for 2023 and 2024 (note: you'll need to install the
england_holidays = holidays.country_holidays("UK", subdiv='ENG', years=[2023, 2024])

result = df.with_columns(
date_shifted=pl.col("date").xdt.offset_by(
by='5bd',
weekend=('Sat', 'Sun'),
holidays=england_holidays,
date_shifted=xdt.offset_by(
'date',
by='5bd',
weekend=('Sat', 'Sun'),
holidays=england_holidays,
)
)
print(result)
Expand Down
Loading