Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/py-polars/tests/unit/operations/arithmetic/test_pow.py
6940 views
1
import polars as pl
2
3
4
def test_pow_dtype() -> None:
5
df = pl.DataFrame(
6
{
7
"foo": [1, 2, 3, 4, 5],
8
"a": [1, 2, 3, 4, 5],
9
"b": [1, 2, 3, 4, 5],
10
"c": [1, 2, 3, 4, 5],
11
"d": [1, 2, 3, 4, 5],
12
"e": [1, 2, 3, 4, 5],
13
"f": [1, 2, 3, 4, 5],
14
"g": [1, 2, 1, 2, 1],
15
"h": [1, 2, 1, 2, 1],
16
},
17
schema_overrides={
18
"a": pl.Int64,
19
"b": pl.UInt64,
20
"c": pl.Int32,
21
"d": pl.UInt32,
22
"e": pl.Int16,
23
"f": pl.UInt16,
24
"g": pl.Int8,
25
"h": pl.UInt8,
26
},
27
).lazy()
28
29
df = (
30
df.with_columns([pl.col("foo").cast(pl.UInt32)])
31
.with_columns(
32
(pl.col("foo") * 2**2).alias("scaled_foo"),
33
(pl.col("foo") * 2**2.1).alias("scaled_foo2"),
34
(pl.col("a") ** pl.col("h")).alias("a_pow_h"),
35
(pl.col("b") ** pl.col("h")).alias("b_pow_h"),
36
(pl.col("c") ** pl.col("h")).alias("c_pow_h"),
37
(pl.col("d") ** pl.col("h")).alias("d_pow_h"),
38
(pl.col("e") ** pl.col("h")).alias("e_pow_h"),
39
(pl.col("f") ** pl.col("h")).alias("f_pow_h"),
40
(pl.col("g") ** pl.col("h")).alias("g_pow_h"),
41
(pl.col("h") ** pl.col("h")).alias("h_pow_h"),
42
)
43
.drop(["a", "b", "c", "d", "e", "f", "g", "h"])
44
)
45
expected = [
46
pl.UInt32,
47
pl.UInt32,
48
pl.Float64,
49
pl.Int64,
50
pl.UInt64,
51
pl.Int32,
52
pl.UInt32,
53
pl.Int16,
54
pl.UInt16,
55
pl.Int8,
56
pl.UInt8,
57
]
58
assert df.collect().dtypes == expected
59
assert df.collect_schema().dtypes() == expected
60
61