Path: blob/main/py-polars/tests/unit/lazyframe/test_explain.py
6939 views
from __future__ import annotations12import pytest34import polars as pl567def test_lf_explain_format_tree() -> None:8lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})9plan = lf.select("a").select(pl.col("a").sum() + pl.len())1011result = plan.explain(format="tree")1213expected = """\140 115┌─────────────────────────────────────────────────────────16│17│ ╭────────╮180 │ │ SELECT │19│ ╰───┬┬───╯20│ ││21│ │╰───────────────────────────╮22│ │ │23│ ╭─────────┴──────────╮ │24│ │ expression: │ ╭──────────────┴──────────────╮25│ │ [(col("a") │ │ FROM: │261 │ │ .sum()) + (len() │ │ DF ["a", "b"] │27│ │ .cast(Int64))] │ │ PROJECT: ["a"]; 1/2 COLUMNS │28│ ╰────────────────────╯ ╰─────────────────────────────╯29\30"""31assert result == expected323334def test_lf_explain_tree_format_deprecated() -> None:35lf = pl.LazyFrame({"a": [1, 2, 3, 4], "b": [5, 6, 7, 8]})3637with pytest.deprecated_call():38lf.explain(tree_format=True)394041