Beispiel #1
0
def test_concat_str() -> None:
    df = pl.DataFrame({"a": ["a", "b", "c"], "b": [1, 2, 3]})

    out = df[[pl.concat_str(["a", "b"], sep="-")]]
    assert out["a"] == ["a-1", "a-2", "a-3"]

    out = df.select([pl.format("foo_{}_bar_{}", pl.col("a"), "b").alias("fmt")])

    assert out["fmt"].to_list() == ["foo_a_bar_1", "foo_b_bar_2", "foo_c_bar_3"]
Beispiel #2
0
def test_format_empty_df() -> None:
    df = pl.DataFrame([
        pl.Series("val1", [], dtype=pl.Categorical),
        pl.Series("val2", [], dtype=pl.Categorical),
    ]).select([
        pl.format("{}:{}", pl.col("val1"), pl.col("val2")).alias("cat"),
    ])
    assert df.shape == (0, 1)
    assert df.dtypes == [pl.Utf8]