Skip to content

Commit

Permalink
docs: Fix example of lazy schema verification (#19059)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao authored Oct 1, 2024
1 parent da8f358 commit e186c03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
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

0 comments on commit e186c03

Please sign in to comment.