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_show_graph.py
8430 views
1
import pytest
2
3
import polars as pl
4
5
6
@pytest.fixture
7
def query() -> pl.LazyFrame:
8
return (
9
pl.LazyFrame(
10
{
11
"a": ["a", "b", "a", "b", "b", "c"],
12
"b": [1, 2, 3, 4, 5, 6],
13
"c": [6, 5, 4, 3, 2, 1],
14
}
15
)
16
.group_by("a", maintain_order=True)
17
.agg(pl.all().sum())
18
.sort("a")
19
)
20
21
22
def test_show_graph_ir(query: pl.LazyFrame) -> None:
23
# only test raw output, otherwise we need graphviz and matplotlib
24
out = query.show_graph(raw_output=True, plan_stage="ir")
25
assert isinstance(out, str)
26
27
28
def test_show_graph_phys_streaming(query: pl.LazyFrame) -> None:
29
# only test raw output, otherwise we need graphviz and matplotlib
30
out = query.show_graph(raw_output=True, plan_stage="physical", engine="streaming")
31
assert isinstance(out, str)
32
33
34
def test_show_graph_phys_not_streaming(query: pl.LazyFrame) -> None:
35
# only test raw output, otherwise we need graphviz and matplotlib
36
out_ir = query.show_graph(raw_output=True, plan_stage="ir", engine="in-memory")
37
out_phys = query.show_graph(
38
raw_output=True, plan_stage="physical", engine="in-memory"
39
)
40
assert isinstance(out_ir, str)
41
assert isinstance(out_phys, str)
42
assert out_ir == out_phys
43
44
45
def test_show_graph_invalid_stage(query: pl.LazyFrame) -> None:
46
with pytest.raises(TypeError, match="invalid plan stage 'invalid-stage'"):
47
query.show_graph(raw_output=True, plan_stage="invalid-stage") # type: ignore[arg-type]
48
49