Skip to content

tests: add edge-case tests for fill() and drop_na() with Date, POSIXct, factor, and empty data frames#1642

Closed
LeonidasZhak wants to merge 2 commits into
tidyverse:mainfrom
LeonidasZhak:tests/fill-drop-na-edge-cases
Closed

tests: add edge-case tests for fill() and drop_na() with Date, POSIXct, factor, and empty data frames#1642
LeonidasZhak wants to merge 2 commits into
tidyverse:mainfrom
LeonidasZhak:tests/fill-drop-na-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

Adds edge-case tests for two core data-cleaning functions: fill() and drop_na(). These cover common data types (Date, POSIXct, factor) and boundary conditions (0-row, all-NA) that had no test coverage.

fill() tests added (6 blocks)

Test What it covers
can fill Date columns Date NA replacement, down and up directions
can fill POSIXct columns POSIXct NA replacement preserves class
fill preserves factor levels Levels retained after fill (down and up) — the existing test only checked attributes
fill with .by respects group boundaries on Date columns Grouped fill doesn't leak across group boundaries on Date
works with 0-row data frame 0-row Date df returns unchanged

drop_na() tests added (6 blocks)

Test What it covers
can drop NAs in factor columns Factor levels preserved after dropping rows
can drop NAs in Date columns Date column NA removal
can drop NAs in POSIXct columns POSIXct column NA removal
works with 0-row data frame 0-row df returns unchanged
works with 0-row grouped data frame 0-row grouped df preserves groups
all-NA data frame returns 0 rows All-NA df fully dropped

Validation

test-fill.R:    0 failures, 41 passes, 4 skips (snapshot)
test-drop-na.R: 0 failures, 22 passes, 1 skip (snapshot)

Diff: 100 lines added across 2 files.

…empty data

Add 7 new test blocks covering:
- Factor columns and vectors preserving levels after NA replacement
- Empty data frame returns unchanged
- All-NA data frame fully replaced
- Date column NA replacement
- POSIXct column NA replacement
…t, factor, and empty data frames

fill():
- Date columns (down and up)
- POSIXct columns
- Factor level preservation (not just attributes)
- .by group boundaries on Date columns
- 0-row data frames

drop_na():
- Factor columns (levels preserved)
- Date columns
- POSIXct columns
- 0-row data frames (grouped and ungrouped)
- All-NA data frames
df <- tibble(x = as.Date(c("2020-01-01", NA, "2020-01-03", NA)))

out <- fill(df, x)
expect_equal(out$x, as.Date(c("2020-01-01", "2020-01-01", "2020-01-03", "2020-01-03")))

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
expect_equal(out$x, as.Date(c("2020-01-01", "2020-01-01", "2020-01-03", "2020-01-03")))
expect_equal(
out$x,
as.Date(c("2020-01-01", "2020-01-01", "2020-01-03", "2020-01-03"))
)

out <- fill(df, x)
expect_equal(
out$x,
as.POSIXct(c("2020-01-01 10:00", "2020-01-01 10:00", "2020-01-03 12:00", "2020-01-03 12:00"))

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
as.POSIXct(c("2020-01-01 10:00", "2020-01-01 10:00", "2020-01-03 12:00", "2020-01-03 12:00"))
as.POSIXct(c(
"2020-01-01 10:00",
"2020-01-01 10:00",
"2020-01-03 12:00",
"2020-01-03 12:00"
))

@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