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(python): Fix LazyFrame fetch method references #18033

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 docs/source/src/python/user-guide/lazy/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
# --8<-- [start:partial]
q9 = (
pl.scan_csv(f"docs/assets/data/reddit.csv")
.head(10)
.with_columns(pl.col("name").str.to_uppercase())
.filter(pl.col("comment_karma") > 0)
.fetch(n_rows=int(100))
.collect()
)
# --8<-- [end:partial]
"""
30 changes: 10 additions & 20 deletions docs/source/user-guide/lazy/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,17 @@ We look at [streaming in more detail here](streaming.md).

While you're writing, optimizing or checking your query on a large dataset, querying all available data may lead to a slow development process.

You can instead execute the query with the `.fetch` method. The `.fetch` method takes a parameter `n_rows` and tries to 'fetch' that number of rows at the data source. The number of rows cannot be guaranteed, however, as the lazy API does not count how many rows there are at each stage of the query.
You can instead limit the number of scanned partitions or use .head early in the query when testing. Keep in mind that aggregations and filters may behave unpredictably on subsets of data.
edwinvehmaanpera marked this conversation as resolved.
Show resolved Hide resolved

Here we "fetch" 100 rows from the source file and apply the predicates.

{{code_block('user-guide/lazy/execution','partial',['scan_csv','collect','fetch'])}}
{{code_block('user-guide/lazy/execution','partial',['scan_csv','collect','head'])}}

```text
shape: (27, 6)
┌───────┬───────────────────────────┬─────────────┬────────────┬───────────────┬────────────┐
│ id ┆ name ┆ created_utc ┆ updated_on ┆ comment_karma ┆ link_karma │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═══════╪═══════════════════════════╪═════════════╪════════════╪═══════════════╪════════════╡
│ 6 ┆ TAOJIANLONG_JASONBROKEN ┆ 1397113510 ┆ 1536527864 ┆ 4 ┆ 0 │
│ 17 ┆ SSAIG_JASONBROKEN ┆ 1397113544 ┆ 1536527864 ┆ 1 ┆ 0 │
│ 19 ┆ FDBVFDSSDGFDS_JASONBROKEN ┆ 1397113552 ┆ 1536527864 ┆ 3 ┆ 0 │
│ 37 ┆ IHATEWHOWEARE_JASONBROKEN ┆ 1397113636 ┆ 1536527864 ┆ 61 ┆ 0 │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 77763 ┆ LUNCHY ┆ 1137599510 ┆ 1536528275 ┆ 65 ┆ 0 │
│ 77765 ┆ COMPOSTELLAS ┆ 1137474000 ┆ 1536528276 ┆ 6 ┆ 0 │
│ 77766 ┆ GENERICBOB ┆ 1137474000 ┆ 1536528276 ┆ 291 ┆ 14 │
│ 77768 ┆ TINHEADNED ┆ 1139665457 ┆ 1536497404 ┆ 4434 ┆ 103 │
└───────┴───────────────────────────┴─────────────┴────────────┴───────────────┴────────────┘
shape: (1, 6)
┌─────┬─────────────────────────┬─────────────┬────────────┬───────────────┬────────────┐
│ id ┆ name ┆ created_utc ┆ updated_on ┆ comment_karma ┆ link_karma │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ str ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞═════╪═════════════════════════╪═════════════╪════════════╪═══════════════╪════════════╡
│ 6 ┆ TAOJIANLONG_JASONBROKEN ┆ 1397113510 ┆ 1536527864 ┆ 4 ┆ 0 │
└─────┴─────────────────────────┴─────────────┴────────────┴───────────────┴────────────┘
```
13 changes: 0 additions & 13 deletions py-polars/polars/lazyframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,6 @@ def collect(

See Also
--------
fetch: Run the query on the first `n` rows only for debugging purposes.
explain : Print the query plan that is evaluated with collect.
profile : Collect the LazyFrame and time each node in the computation graph.
polars.collect_all : Collect multiple LazyFrames at the same time.
Expand Down Expand Up @@ -5188,12 +5187,6 @@ def limit(self, n: int = 5) -> LazyFrame:
n
Number of rows to return.

Notes
-----
Consider using the :func:`fetch` operation if you only want to test your
query. The :func:`fetch` operation will load the first `n` rows at the scan
level, whereas the :func:`head`/:func:`limit` are applied at the end.

Examples
--------
>>> lf = pl.LazyFrame(
Expand Down Expand Up @@ -5237,12 +5230,6 @@ def head(self, n: int = 5) -> LazyFrame:
n
Number of rows to return.

Notes
-----
Consider using the :func:`fetch` operation if you only want to test your
query. The :func:`fetch` operation will load the first `n` rows at the scan
level, whereas the :func:`head`/:func:`limit` are applied at the end.

Examples
--------
>>> lf = pl.LazyFrame(
Expand Down
Loading