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

[ENH] improve Polars' LazyFrame complete #1378

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

samukweku
Copy link
Collaborator

PR Description

Please describe the changes proposed in the pull request:

  • Ensure lazyframe is lazy for as long as possible - avoid collect
import polars as pl
import janitor.polars

df.shape
(40000, 5)

# dev 
In [39]: %%timeit
    ...: df.lazy().janitor.complete(
    ...:         "group",
    ...:         pl.struct("item_id", "item_name").alias("rar").unique().sort(),
    ...:         fill_value={"value1": 0, "value2": 99},
    ...:         explicit=False,
    ...:         sort=True,
    ...:     )
    ...: 
6.21 ms ± 175 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [40]: %%timeit
    ...: df.lazy().janitor.complete(
    ...:         "group",
    ...:         pl.struct("item_id", "item_name").alias("rar").unique().sort(),
    ...:         fill_value={"value1": 0, "value2": 99},
    ...:         explicit=False,
    ...:         sort=True,
    ...:     ).collect()
    ...: 
11.9 ms ± 35.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


# this PR
In [37]: %%timeit
    ...: df.lazy().janitor.complete(
    ...:         "group",
    ...:         pl.struct("item_id", "item_name").alias("rar").unique().sort(),
    ...:         fill_value={"value1": 0, "value2": 99},
    ...:         explicit=False,
    ...:         sort=True,
    ...:     )
    ...: 
111 µs ± 753 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [38]: %%timeit
    ...: df.lazy().janitor.complete(
    ...:         "group",
    ...:         pl.struct("item_id", "item_name").alias("rar").unique().sort(),
    ...:         fill_value={"value1": 0, "value2": 99},
    ...:         explicit=False,
    ...:         sort=True,
    ...:     ).collect()
    ...: 
5.91 ms ± 56.9 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

This PR relates to #1352 .

@samukweku samukweku requested review from ericmjl, Zeroto521, thatlittleboy and a team June 18, 2024 12:04
@samukweku samukweku self-assigned this Jun 18, 2024
@ericmjl
Copy link
Member

ericmjl commented Jun 18, 2024

@ericmjl
Copy link
Member

ericmjl commented Jun 18, 2024

This one is an easy merge. Thank you, @samukweku!

@ericmjl ericmjl merged commit 93314e7 into dev Jun 18, 2024
4 checks passed
@samukweku samukweku deleted the samuweku/polars_complete_improve branch June 18, 2024 23:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants