Skip to content
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

Merged
merged 11 commits into from
Oct 19, 2024
Merged

Conversation

andyquinterom
Copy link
Contributor

Closes #1251

@etiennebacher
Copy link
Collaborator

Hi, thanks for opening the issue and the corresponding PR, can you add a test and a bullet point in NEWS?

@andyquinterom
Copy link
Contributor Author

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

@andyquinterom
Copy link
Contributor Author

@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)
    )
  }

@andyquinterom
Copy link
Contributor Author

@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

tests/testthat/test-datatype.R Outdated Show resolved Hide resolved
@etiennebacher
Copy link
Collaborator

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).

Copy link
Collaborator

@eitsupi eitsupi left a 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

DESCRIPTION Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
@andyquinterom
Copy link
Contributor Author

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?

@eitsupi
Copy link
Collaborator

eitsupi commented Oct 18, 2024

We should update lib version by hand first.
https://github.com/pola-rs/r-polars/blob/main/src%2Frust%2FCargo.toml#L3-L3

Copy link
Collaborator

@etiennebacher etiennebacher left a 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

Copy link
Collaborator

@eitsupi eitsupi left a 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_(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about including NA?

Copy link
Collaborator

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

src/rust/Cargo.toml Outdated Show resolved Hide resolved
DESCRIPTION Outdated Show resolved Hide resolved
Copy link
Collaborator

@eitsupi eitsupi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@eitsupi eitsupi merged commit 206d6a4 into pola-rs:main Oct 19, 2024
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keep Enum order when convertir to R dataframe
3 participants