Skip to content

tests: add edge-case tests for chop()/unchop() with factors and dates - #1645

Closed
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/chop-unchop-factor-date-edge-cases
Closed

tests: add edge-case tests for chop()/unchop() with factors and dates#1645
LeonidasZhak wants to merge 1 commit into
tidyverse:mainfrom
LeonidasZhak:tests/chop-unchop-factor-date-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Adds edge-case tests for chop() and unchop() 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 order
  • unchop() merges factor levels from list elements
  • unchop() preserves ordered factor class
  • Round-trip chop()unchop() preserves factor properties
  • unchop() handles empty factors in list columns (with and without keep_empty)

Date/POSIXct tests:

  • chop() and unchop() preserve Date class
  • chop() and unchop() preserve POSIXct class

All 114 chop/unchop tests pass (89 existing + 25 new). Single test file changed.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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"
)

@LeonidasZhak

Copy link
Copy Markdown
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.

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.

1 participant