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

docs: Fix example of lazy schema verification #19059

Merged
merged 1 commit into from
Oct 1, 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
6 changes: 2 additions & 4 deletions docs/source/src/python/user-guide/lazy/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
# --8<-- [end:schema]

# --8<-- [start:lazyround]
lf = pl.LazyFrame({"foo": ["a", "b", "c"], "bar": [0, 1, 2]}).with_columns(
pl.col("bar").round(0)
)
lf = pl.LazyFrame({"foo": ["a", "b", "c"]}).with_columns(pl.col("foo").round(2))
# --8<-- [end:lazyround]

# --8<-- [start:typecheck]
try:
print(lf.collect())
except Exception as e:
print(e)
print(f"{type(e).__name__}: {e}")
# --8<-- [end:typecheck]

# --8<-- [start:lazyeager]
Expand Down
4 changes: 2 additions & 2 deletions docs/source/user-guide/lazy/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ The schema plays an important role in the lazy API.

One advantage of the lazy API is that Polars will check the schema before any data is processed. This check happens when you execute your lazy query.

We see how this works in the following simple example where we call the `.round` expression on the integer `bar` column.
We see how this works in the following simple example where we call the `.round` expression on the string column `foo`.

{{code_block('user-guide/lazy/schema','lazyround',['with_columns'])}}

The `.round` expression is only valid for columns with a floating point dtype. Calling `.round` on an integer column means the operation will raise an `InvalidOperationError` when we evaluate the query with `collect`. This schema check happens before the data is processed when we call `collect`.
The `.round` expression is only valid for columns with a numeric data type. Calling `.round` on a string column means the operation will raise an `InvalidOperationError` when we evaluate the query with `collect`. This schema check happens before the data is processed when we call `collect`.

{{code_block('user-guide/lazy/schema','typecheck',[])}}

Expand Down
Loading