Path: blob/main/py-polars/tests/unit/lazyframe/test_show_graph.py
8430 views
import pytest12import polars as pl345@pytest.fixture6def query() -> pl.LazyFrame:7return (8pl.LazyFrame(9{10"a": ["a", "b", "a", "b", "b", "c"],11"b": [1, 2, 3, 4, 5, 6],12"c": [6, 5, 4, 3, 2, 1],13}14)15.group_by("a", maintain_order=True)16.agg(pl.all().sum())17.sort("a")18)192021def test_show_graph_ir(query: pl.LazyFrame) -> None:22# only test raw output, otherwise we need graphviz and matplotlib23out = query.show_graph(raw_output=True, plan_stage="ir")24assert isinstance(out, str)252627def test_show_graph_phys_streaming(query: pl.LazyFrame) -> None:28# only test raw output, otherwise we need graphviz and matplotlib29out = query.show_graph(raw_output=True, plan_stage="physical", engine="streaming")30assert isinstance(out, str)313233def test_show_graph_phys_not_streaming(query: pl.LazyFrame) -> None:34# only test raw output, otherwise we need graphviz and matplotlib35out_ir = query.show_graph(raw_output=True, plan_stage="ir", engine="in-memory")36out_phys = query.show_graph(37raw_output=True, plan_stage="physical", engine="in-memory"38)39assert isinstance(out_ir, str)40assert isinstance(out_phys, str)41assert out_ir == out_phys424344def test_show_graph_invalid_stage(query: pl.LazyFrame) -> None:45with pytest.raises(TypeError, match="invalid plan stage 'invalid-stage'"):46query.show_graph(raw_output=True, plan_stage="invalid-stage") # type: ignore[arg-type]474849