Skip to content

tests: add factor edge-case tests for unite() and separate()#1639

Closed
LeonidasZhak wants to merge 5 commits into
tidyverse:mainfrom
LeonidasZhak:tests/unite-separate-factor-edge-cases
Closed

tests: add factor edge-case tests for unite() and separate()#1639
LeonidasZhak wants to merge 5 commits into
tidyverse:mainfrom
LeonidasZhak:tests/unite-separate-factor-edge-cases

Conversation

@LeonidasZhak

Copy link
Copy Markdown

Summary

Adds edge-case tests for unite() and separate() with factor column input. Both functions convert factor input to character output, but this behavior had zero test coverage.

Changes

  • test-unite.R: +33 lines — 3 tests for factor→character conversion, na.rm with factors, unused factor levels
  • test-separate.R: +26 lines — 3 tests for factor→character conversion, NA preservation, convert = TRUE with factors

Why

Factor columns are ubiquitous in data cleaning workflows. unite() and separate() are commonly used with categorical variables. These tests document the expected factor-handling behavior.

Tests run

devtools::test(filter = "unite|separate")
# [ FAIL 0 | WARN 0 | SKIP 0 | PASS 196 ]

Filter out infinite values before computing range in full_seq.numeric().
This prevents the cryptic 'missing value where TRUE/FALSE needed' error
when input contains Inf or -Inf values.

Fixes tidyverse#1496
…idyverse#1509)

- Add clear error message when trying to expand or complete on a grouping column
- Error now says 'Can't expand/complete on a grouping column' instead of cryptic 'object not found'
- Suggests using ungroup() or working with non-grouping columns
- Updated tests to use snapshot testing for error messages
…ep and cols_remove = FALSE (tidyverse#1499, tidyverse#1588)

When using names_sep with cols_remove = FALSE, the original column was
being renamed by unpack() (e.g., x -> x_x). This fix detects when the
original column is present in the packed data and restores it after unpacking.

Fixes tidyverse#1499
Fixes tidyverse#1588
- unite(): factor→character conversion, unused levels, na.rm with factors
- separate(): factor→character conversion, NA preservation, convert = TRUE with factors

These functions are commonly used in data cleaning workflows with factor
columns but lacked explicit test coverage for factor input behavior.
@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