Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/lazyframe/test_explain.py
6939 views
1
from __future__ import annotations
2
3
import pytest
4
5
import polars as pl
6
7
8
def test_lf_explain_format_tree() -> None:
9
lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})
10
plan = lf.select("a").select(pl.col("a").sum() + pl.len())
11
12
result = plan.explain(format="tree")
13
14
expected = """\
15
0 1
16
┌─────────────────────────────────────────────────────────
17
18
│ ╭────────╮
19
0 │ │ SELECT │
20
│ ╰───┬┬───╯
21
│ ││
22
│ │╰───────────────────────────╮
23
│ │ │
24
│ ╭─────────┴──────────╮ │
25
│ │ expression: │ ╭──────────────┴──────────────╮
26
│ │ [(col("a") │ │ FROM: │
27
1 │ │ .sum()) + (len() │ │ DF ["a", "b"] │
28
│ │ .cast(Int64))] │ │ PROJECT: ["a"]; 1/2 COLUMNS │
29
│ ╰────────────────────╯ ╰─────────────────────────────╯
30
\
31
"""
32
assert result == expected
33
34
35
def test_lf_explain_tree_format_deprecated() -> None:
36
lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})
37
38
with pytest.deprecated_call():
39
lf.explain(tree_format=True)
40
41