pola-rs / polars

Dataframes powered by a multithreaded, vectorized query engine, written in Rust
https://docs.pola.rs
Other
26.63k stars 1.63k forks source link

pl.format should be clear it will return null when one of the arguments is null #16026

Open ericvdtoorn opened 2 weeks ago

ericvdtoorn commented 2 weeks ago

Description

It was not clear to me that pl.format would make the entire column null when one of the arguments is null. i.e.

df = pl.DataFrame({
    "a": [1,2,3,4],
    "b": [5,6,None,8]
})
df.with_columns(
    ab=pl.format("{}_{}", c("a"), c("b"))
)
a b ab
0 1 5 1_5
1 2 6 2_6
2 3 null null
3 4 8 4_8

I originally expected a null to either a) throw an error or b) insert null. If this is intended behaviour, I believe that should be made explicit in the documentation to avoid tripping over this silent error.

Link

https://docs.pola.rs/py-polars/html/reference/expressions/api/polars.format.html#polars.format