tests: add edge-case tests for chop()/unchop() with factors and dates - #1645
Closed
LeonidasZhak wants to merge 1 commit into
Closed
tests: add edge-case tests for chop()/unchop() with factors and dates#1645LeonidasZhak wants to merge 1 commit into
LeonidasZhak wants to merge 1 commit into
Conversation
- Factor: chop preserves class/levels, unchop merges levels, ordered factors preserved, round-trip preserves properties, empty factors - Date/POSIXct: chop and unchop preserve temporal classes
| # factor edge cases ------------------------------------------------------- | ||
|
|
||
| test_that("chop() preserves factor class and levels", { | ||
| df <- tibble(x = c(1, 1, 2), y = factor(c("a", "b", "a"), levels = c("b", "a"))) |
Contributor
There was a problem hiding this comment.
[air] reported by reviewdog 🐶
Suggested change
| df <- tibble(x = c(1, 1, 2), y = factor(c("a", "b", "a"), levels = c("b", "a"))) | |
| df <- tibble( | |
| x = c(1, 1, 2), | |
| y = factor(c("a", "b", "a"), levels = c("b", "a")) | |
| ) |
| }) | ||
|
|
||
| test_that("chop/unchop round-trip preserves factor properties", { | ||
| df <- tibble(x = c(1, 1, 2), y = factor(c("a", "b", "c"), levels = c("c", "b", "a"))) |
Contributor
There was a problem hiding this comment.
[air] reported by reviewdog 🐶
Suggested change
| df <- tibble(x = c(1, 1, 2), y = factor(c("a", "b", "c"), levels = c("c", "b", "a"))) | |
| df <- tibble( | |
| x = c(1, 1, 2), | |
| y = factor(c("a", "b", "c"), levels = c("c", "b", "a")) | |
| ) |
| }) | ||
|
|
||
| test_that("chop() preserves POSIXct class", { | ||
| times <- as.POSIXct(c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), tz = "UTC") |
Contributor
There was a problem hiding this comment.
[air] reported by reviewdog 🐶
Suggested change
| times <- as.POSIXct(c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), tz = "UTC") | |
| times <- as.POSIXct( | |
| c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), | |
| tz = "UTC" | |
| ) |
| }) | ||
|
|
||
| test_that("unchop() preserves POSIXct class from list column", { | ||
| times <- as.POSIXct(c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), tz = "UTC") |
Contributor
There was a problem hiding this comment.
[air] reported by reviewdog 🐶
Suggested change
| times <- as.POSIXct(c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), tz = "UTC") | |
| times <- as.POSIXct( | |
| c("2020-01-01 10:00", "2020-01-01 11:00", "2020-01-02 12:00"), | |
| tz = "UTC" | |
| ) |
Author
|
Withdrawing this small automated PR while I consolidate an oversized batch of contributions and reduce maintainer review burden. Sorry for the noise, and thank you for maintaining the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds edge-case tests for
chop()andunchop()covering factor and date/time columns, which are common in data cleaning workflows but were not previously tested.Factor tests:
chop()preserves factor class and level orderunchop()merges factor levels from list elementsunchop()preserves ordered factor classchop()→unchop()preserves factor propertiesunchop()handles empty factors in list columns (with and withoutkeep_empty)Date/POSIXct tests:
chop()andunchop()preserve Date classchop()andunchop()preserve POSIXct classAll 114 chop/unchop tests pass (89 existing + 25 new). Single test file changed.