-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
depr(python): Deprecate
tree_format
parameter for `LazyFrame.explai…
…n` in favor of `format` (#16486)
- Loading branch information
Showing
3 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import polars as pl | ||
|
||
|
||
def test_lf_explain() -> None: | ||
lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}) | ||
plan = lf.select("a").select(pl.col("a").sum() + pl.len()) | ||
|
||
result = plan.explain() | ||
|
||
expected = """\ | ||
SELECT [[(col("a").sum()) + (len().cast(Int64))]] FROM | ||
DF ["a", "b"]; PROJECT 1/2 COLUMNS; SELECTION: None\ | ||
""" | ||
assert result == expected | ||
|
||
|
||
def test_lf_explain_format_tree() -> None: | ||
lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}) | ||
plan = lf.select("a").select(pl.col("a").sum() + pl.len()) | ||
|
||
result = plan.explain(format="tree") | ||
|
||
expected = """\ | ||
0 1 | ||
┌───────────────────────────────────────────────── | ||
│ | ||
│ ╭────────╮ | ||
0 │ │ SELECT │ | ||
│ ╰───┬┬───╯ | ||
│ ││ | ||
│ │╰───────────────────────╮ | ||
│ │ │ | ||
│ ╭─────────┴──────────╮ │ | ||
│ │ expression: │ ╭──────────┴──────────╮ | ||
│ │ [(col("a") │ │ FROM: │ | ||
1 │ │ .sum()) + (len() │ │ DF ["a", "b"] │ | ||
│ │ .cast(Int64))] │ │ PROJECT 1/2 COLUMNS │ | ||
│ ╰────────────────────╯ ╰─────────────────────╯ | ||
\ | ||
""" | ||
assert result == expected | ||
|
||
|
||
def test_lf_explain_tree_format_deprecated() -> None: | ||
lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]}) | ||
|
||
with pytest.deprecated_call(): | ||
lf.explain(tree_format=True) |