Path: blob/main/py-polars/tests/unit/operations/test_profile.py
6939 views
import polars as pl123def test_profile_columns() -> None:4ldf = pl.LazyFrame({"a": [1, 2, 3], "b": [1.0, 2.0, 3.0]})56# profile lazyframe operation/plan7lazy = ldf.group_by("a").agg(pl.implode("b"))8profiling_info = lazy.profile()9# ┌──────────────┬───────┬─────┐10# │ node ┆ start ┆ end │11# │ --- ┆ --- ┆ --- │12# │ str ┆ u64 ┆ u64 │13# ╞══════════════╪═══════╪═════╡14# │ optimization ┆ 0 ┆ 69 │15# │ group_by(a) ┆ 69 ┆ 342 │16# └──────────────┴───────┴─────┘17assert len(profiling_info) == 218assert profiling_info[1].columns == ["node", "start", "end"]192021def test_profile_with_cse() -> None:22df = pl.DataFrame({"x": [], "y": []}, schema={"x": pl.Float32, "y": pl.Float32})2324x = pl.col("x")25y = pl.col("y")2627assert df.lazy().with_columns(28pl.when(x.is_null())29.then(None)30.otherwise(pl.when(y == 0).then(None).otherwise(x + y))31).profile(optimizations=pl.QueryOptFlags(comm_subexpr_elim=True))[1].shape == (2, 3)323334