Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/functions/test_horizontal.py
6939 views
1
import pytest
2
3
import polars as pl
4
5
6
@pytest.mark.parametrize(
7
"f",
8
[
9
"min",
10
"max",
11
"sum",
12
"mean",
13
],
14
)
15
def test_shape_mismatch_19336(f: str) -> None:
16
a = pl.Series([1, 2, 3])
17
b = pl.Series([1, 2])
18
fn = getattr(pl, f"{f}_horizontal")
19
20
with pytest.raises(pl.exceptions.ShapeError):
21
pl.select((fn)(a, b))
22
23
24
def test_fold_reduce_output_dtype_24011() -> None:
25
df = pl.DataFrame(
26
{
27
"x": [0, 1, 2],
28
"y": [1.1, 2.2, 3.3],
29
}
30
)
31
32
def f(acc: pl.Series, x: pl.Series) -> pl.Series:
33
return acc + x
34
35
q = df.lazy().select(
36
fold=pl.fold(acc=pl.lit(0), function=f, exprs=pl.col("*")),
37
reduce=pl.reduce(function=f, exprs=pl.col("*")),
38
cum_fold=pl.cum_fold(acc=pl.lit(0), function=f, exprs=pl.col("*")),
39
cum_reduce=pl.cum_reduce(function=f, exprs=pl.col("*")),
40
)
41
42
assert q.collect_schema() == q.collect().schema
43
44