-
Notifications
You must be signed in to change notification settings - Fork 35
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
fix: Keeps Enum order when converting to R #1252
Conversation
Hi, thanks for opening the issue and the corresponding PR, can you add a test and a bullet point in NEWS? |
I'll get on the tests asap |
@etiennebacher I added a test to validate many cases. # Generate 100 random data frames with random
# orders for levels. They should always match
for (i in 1:100) {
expected_levels = sample(letters, length(letters))
expected_values = sample(letters, length(letters))
expect_identical(
as_polars_series(expected_values)$
cast(pl$Enum(expected_levels))$
to_r(),
factor(expected_values, levels = expected_levels)
)
} |
@etiennebacher Everything seems to pass except for R CMD check due to Non-api calls, but I think that's out of the scope of this pull request |
Yes this is out of scope. I agree with @eitsupi about using property-based testing on this. I think something like this would do the job (but I haven't tested yet): test_that("reversing twice returns the original input", {
for_all(
values = any_atomic(any_na = TRUE),
levels = any_atomic(any_na = TRUE),
property = function(values, levels) {
expect_identical(
as_polars_series(values)$
cast(pl$Enum(levels))$
to_r(),
factor(values, levels = levels)
)
}
)
}) Please also add a bullet point in news with the PR number and your username (if you want). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates!
Could you bump the Rust lib version and please remove the lib-sums.tsv.
Please check the document for details.
https://github.com/pola-rs/r-polars/blob/8ecb1a358c5bf0c6c6e6c9527904bb798f07a101/DEVELOPMENT.md
I just ran the task and see that nothing has changed. Am I doing something wrong? |
We should update lib version by hand first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @andyquinterom
@eitsupi I can't merge, I need you to approve
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost looks good.
A few comments.
to_r(), | ||
factor(c("z", "z", "k", "a")) | ||
quickcheck::for_all( | ||
factors = quickcheck::factor_(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about including NA
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but there is an issue about that.
armcn/quickcheck#22
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Closes #1251