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_collect_all.py
6939 views
1
from typing import cast
2
3
import pytest
4
5
import polars as pl
6
7
8
def test_collect_all_type_coercion_21805() -> None:
9
df = pl.LazyFrame({"A": [1.0, 2.0]})
10
df = df.with_columns(pl.col("A").shift().fill_null(2))
11
assert pl.collect_all([df])[0]["A"].to_list() == [2.0, 1.0]
12
13
14
@pytest.mark.parametrize("optimizations", [pl.QueryOptFlags(), pl.QueryOptFlags.none()])
15
def test_collect_all(df: pl.DataFrame, optimizations: pl.QueryOptFlags) -> None:
16
lf1 = df.lazy().select(pl.col("int").sum())
17
lf2 = df.lazy().select((pl.col("floats") * 2).sum())
18
out = pl.collect_all([lf1, lf2], optimizations=optimizations)
19
assert cast(int, out[0].item()) == 6
20
assert cast(float, out[1].item()) == 12.0
21
22