From fb1f1de0166310f003e5397171e70b65c308af81 Mon Sep 17 00:00:00 2001 From: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:01:12 +0200 Subject: [PATCH 1/3] init --- src/rust/src/lazy/dsl.rs | 2 +- tests/testthat/test-expr_expr.R | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rust/src/lazy/dsl.rs b/src/rust/src/lazy/dsl.rs index fee626b35..08ab91759 100644 --- a/src/rust/src/lazy/dsl.rs +++ b/src/rust/src/lazy/dsl.rs @@ -1727,7 +1727,7 @@ impl RPolarsExpr { } pub fn len(&self) -> Self { - self.0.clone().count().into() + self.0.clone().len().into() } pub fn slice(&self, offset: &RPolarsExpr, length: Nullable<&RPolarsExpr>) -> Self { diff --git a/tests/testthat/test-expr_expr.R b/tests/testthat/test-expr_expr.R index 0b55cc156..326fd5345 100644 --- a/tests/testthat/test-expr_expr.R +++ b/tests/testthat/test-expr_expr.R @@ -139,6 +139,17 @@ test_that("count + unique + n_unique", { ) }) +test_that("$len() and $count() don't have the same behavior for nulls", { + expect_equal( + pl$DataFrame(x = c(1, 2, NA))$select(pl$col("x")$len())$to_list(), + list(x = 3) + ) + expect_equal( + pl$DataFrame(x = c(1, 2, NA))$select(pl$col("x")$count())$to_list(), + list(x = 2) + ) +}) + test_that("drop_nans drop_nulls", { x = c(1.0, 2.0, NaN, NA) From 62ad79145026f223793faa203524891f12fa2997 Mon Sep 17 00:00:00 2001 From: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:02:14 +0200 Subject: [PATCH 2/3] news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 76fc062e9..1916a5a70 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,10 @@ ## polars (development version) +### Bug fixes + +* `$len()` now correctly counts `null` values (#1044). + ## Polars R Package 0.16.0 ### Breaking changes From be60ae41c5d95e135dede86fa69e225ee8e0fef3 Mon Sep 17 00:00:00 2001 From: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> Date: Tue, 16 Apr 2024 13:04:40 +0200 Subject: [PATCH 3/3] typo --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 1916a5a70..155ea985c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ ### Bug fixes -* `$len()` now correctly counts `null` values (#1044). +* `$len()` now correctly includes `null` values in the count (#1044). ## Polars R Package 0.16.0