pola-rs / r-polars

Bring polars to R
https://pola-rs.github.io/r-polars/
Other
398 stars 35 forks source link

`$len()` doesn't count `null` but it should #1043

Closed etiennebacher closed 1 month ago

etiennebacher commented 1 month ago
import polars as pl
pl.DataFrame({"x": [1, 2, None]}).with_columns(y=pl.col("x").len())

shape: (3, 2)
┌──────┬─────┐
│ x    ┆ y   │
│ ---  ┆ --- │
│ i64  ┆ u32 │
╞══════╪═════╡
│ 1    ┆ 3   │
│ 2    ┆ 3   │
│ null ┆ 3   │
└──────┴─────┘
library(polars)
pl$DataFrame(x = c(1, 2, NA))$with_columns(y = pl$col("x")$len())

shape: (3, 2)
┌──────┬─────┐
│ x    ┆ y   │
│ ---  ┆ --- │
│ f64  ┆ u32 │
╞══════╪═════╡
│ 1.0  ┆ 2   │
│ 2.0  ┆ 2   │
│ null ┆ 2   │
└──────┴─────┘