Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/operations/test_profile.py
6939 views
1
import polars as pl
2
3
4
def test_profile_columns() -> None:
5
ldf = pl.LazyFrame({"a": [1, 2, 3], "b": [1.0, 2.0, 3.0]})
6
7
# profile lazyframe operation/plan
8
lazy = ldf.group_by("a").agg(pl.implode("b"))
9
profiling_info = lazy.profile()
10
# ┌──────────────┬───────┬─────┐
11
# │ node ┆ start ┆ end │
12
# │ --- ┆ --- ┆ --- │
13
# │ str ┆ u64 ┆ u64 │
14
# ╞══════════════╪═══════╪═════╡
15
# │ optimization ┆ 0 ┆ 69 │
16
# │ group_by(a) ┆ 69 ┆ 342 │
17
# └──────────────┴───────┴─────┘
18
assert len(profiling_info) == 2
19
assert profiling_info[1].columns == ["node", "start", "end"]
20
21
22
def test_profile_with_cse() -> None:
23
df = pl.DataFrame({"x": [], "y": []}, schema={"x": pl.Float32, "y": pl.Float32})
24
25
x = pl.col("x")
26
y = pl.col("y")
27
28
assert df.lazy().with_columns(
29
pl.when(x.is_null())
30
.then(None)
31
.otherwise(pl.when(y == 0).then(None).otherwise(x + y))
32
).profile(optimizations=pl.QueryOptFlags(comm_subexpr_elim=True))[1].shape == (2, 3)
33
34