Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Add a note on reusing LazyFrames #370

Merged
merged 3 commits into from
Jul 18, 2023
Merged

Add a note on reusing LazyFrames #370

merged 3 commits into from
Jul 18, 2023

Conversation

avimallu
Copy link
Contributor

@cmdlineluser
Copy link

Thanks for this.

Just thought I'd add that maybe it would be helpful to also have a code example demonstrating this?

Copying the code from pola-rs/polars#9786 (comment)

df_a = pl.LazyFrame({"col": ["A", "B", "C", "D"]})
df_b = pl.LazyFrame({"col": ["A", "B", "C", "D"]})

df_b = df_b.groupby("col").all().with_row_count()

df_a.join(df_b, on="col", how="left").collect()

# shape: (4, 2)
# ┌─────┬────────┐
# │ col ┆ row_nr │
# │ --- ┆ ---    │
# │ str ┆ u32    │
# ╞═════╪════════╡
# │ A   ┆ 0      │
# │ B   ┆ 2      │
# │ C   ┆ 3      │
# │ D   ┆ 1      │
# └─────┴────────┘

df_a.join(df_b, on="col", how="left").collect()

# shape: (4, 2)
# ┌─────┬────────┐
# │ col ┆ row_nr │
# │ --- ┆ ---    │
# │ str ┆ u32    │
# ╞═════╪════════╡
# │ A   ┆ 1      │
# │ B   ┆ 3      │
# │ C   ┆ 0      │
# │ D   ┆ 2      │
# └─────┴────────┘

A better example could be made, but seeing this behaviour was what helped me understand what exactly was happening.

@avimallu
Copy link
Contributor Author

avimallu commented Jul 14, 2023

I'd love to @cmdlineluser, but at some point it might just happen that during a compilation of the user guide, the outputs will be the same and will leave new users very thoroughly confused. Any ideas (other than adding a special condition) to make sure that they're different?

I remembered that there is an option of running code but not displaying it on screen. I can just run a while loop to make sure that the results are always different for the sake of illustration, and not show it in the user guide. Any thoughts @ritchie46?

@ritchie46
Copy link
Member

I am not familiar with md-book. It seems possible to me?

@ritchie46
Copy link
Member

Let's first merge the note and see if we can improve with a code example later. 👍

@ritchie46 ritchie46 merged commit c2b59ab into pola-rs:master Jul 18, 2023
5 checks passed
@avimallu avimallu deleted the add_lazy_computation_note branch July 18, 2023 12:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants