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