-
Notifications
You must be signed in to change notification settings - Fork 7
fix: NULL in mutate() may cause error and incorrect columns order
#356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1451a12
4c54666
8e4d0fa
1e41e17
e4b7b1d
06469c3
3134f38
b5841a0
5f42c90
59f708a
f89be99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,17 @@ test_that("dropping columns works", { | |
| mutate(test_pl, Sepal.Length = 1, Species = NULL), | ||
| names(test_df)[1:4] | ||
| ) | ||
|
|
||
| expect_equal( | ||
| mutate(test_pl, missing = NULL), | ||
| mutate(test_df, missing = NULL) | ||
| ) | ||
|
|
||
| # Ensure correct column order, https://github.com/etiennebacher/tidypolars/issues/355 | ||
| expect_equal( | ||
| mutate(test_pl, Sepal.Length = NULL, Sepal.Length = Sepal.Width + 1), | ||
| mutate(test_df, Sepal.Length = NULL, Sepal.Length = Sepal.Width + 1) | ||
| ) | ||
| }) | ||
|
|
||
| test_that("operations on grouped data work", { | ||
|
|
@@ -193,6 +204,28 @@ test_that("operations on grouped data work", { | |
| attr("maintain_grp_order") | ||
| ) | ||
|
|
||
| expect_equal( | ||
| test_pl |> | ||
| mutate(Species = NULL, Species = Sepal.Width + 1, .by = Species), | ||
| test_df |> | ||
| mutate(Species = NULL, Species = Sepal.Width + 1, .by = Species) | ||
| ) | ||
|
|
||
| expect_equal( | ||
| test_pl |> | ||
| mutate( | ||
| Species = Sepal.Width + 1, | ||
| foo = mean(Sepal.Length), | ||
| .by = Species, | ||
| ), | ||
| test_df |> | ||
| mutate( | ||
| Species = Sepal.Width + 1, | ||
| foo = mean(Sepal.Length), | ||
| .by = Species, | ||
| ) | ||
| ) | ||
|
Comment on lines
+214
to
+227
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this test add compared to the existing tests?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a regression prevention test that tests the behavior when the grouping variable is modified. You can delete it if you feel it is not necessary. The test in that comment below was really unnecessary and I've deleted it. |
||
|
|
||
| test_df <- as_tibble(mtcars) | ||
| test_pl <- as_polars_df(test_df) | ||
|
|
||
|
|
@@ -208,6 +241,30 @@ test_that("operations on grouped data work", { | |
| tolerance = 1e-5 | ||
| ) | ||
|
|
||
| expect_equal( | ||
| test_pl |> | ||
| group_by(cyl, am) |> | ||
| mutate( | ||
| cyl = NULL, | ||
| cyl = disp + 1, | ||
| hp2 = mean(hp), | ||
| am = NULL, | ||
| am = gear + 1 | ||
| ) |> | ||
| ungroup(), | ||
| test_df |> | ||
| group_by(cyl, am) |> | ||
| mutate( | ||
| cyl = NULL, | ||
| cyl = disp + 1, | ||
| hp2 = mean(hp), | ||
| am = NULL, | ||
| am = gear + 1 | ||
| ) |> | ||
| ungroup(), | ||
| tolerance = 1e-5 | ||
| ) | ||
|
|
||
| test_df <- as_tibble(iris) | ||
| test_pl <- as_polars_df(test_df) | ||
|
|
||
|
|
@@ -216,6 +273,17 @@ test_that("operations on grouped data work", { | |
| names(test_df)[2:5] | ||
| ) | ||
|
|
||
| expect_equal( | ||
| test_pl |> | ||
| group_by(Species) |> | ||
| mutate(Species = NULL, Species = Sepal.Width + 1) |> | ||
| ungroup(), | ||
| test_df |> | ||
| group_by(Species) |> | ||
| mutate(Species = NULL, Species = Sepal.Width + 1) |> | ||
| ungroup() | ||
| ) | ||
|
|
||
| test_df <- as_tibble(mtcars) | ||
| test_pl <- as_polars_df(test_df) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.