Skip to content

Commit

Permalink
chore: Adds test to validate factor enum consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
andyquinterom committed Oct 9, 2024
1 parent 9eadb26 commit 7c78dc0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/testthat/test-datatype.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,18 @@ test_that("contains_* functions for datatype work", {
})

test_that("Enum", {
expect_identical(
as_polars_series(c("z", "z", "k", "a"))$
cast(pl$Enum(c("z", "k", "a")))$
to_r(),
factor(c("z", "z", "k", "a"))
)
# 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)
)
}

expect_grepl_error(pl$Enum(), "missing")
expect_grepl_error(pl$Enum(1), "invalid series dtype")
Expand Down

0 comments on commit 7c78dc0

Please sign in to comment.