Skip to content

Conversation

@tanmaydimriGSOC
Copy link

Summary

This PR adds a focused, high-value test to ensure that parse_date() behaves correctly when given mixed date formats while an explicit format is supplied. The test verifies that:

  • Strings matching the format are parsed successfully.
  • Strings not matching the format are returned as NA.
  • A warning is issued for mismatched formats.

This scenario was not previously covered in the test suite and improves coverage for real-world edge cases.


Rationale

When users provide an explicit format, parse_date() should consistently:

  1. Parse valid inputs matching the format.
  2. Fail gracefully with NA for mismatched or invalid inputs.
  3. Emit a clear, informative warning.

Adding this test ensures that these expectations remain stable and prevents future regressions around mixed-format date parsing — a common source of issues when working with heterogeneous datasets.


What this test covers

The added test checks a small vector containing:

  • A valid date matching the supplied format
  • A date in a different format
  • A completely invalid date

It then asserts that:

  • Matching entries parse correctly
  • Non-matching entries return NA
  • A warning is produced

The test fits neatly within the existing structure of test-parsing-datetime.R.


Files changed

  • tests/testthat/test-parsing-datetime.R (new test block only)

No source code or snapshot changes.


How to test

Run either:

testthat::test_file("tests/testthat/test-parsing-datetime.R")

or

devtools::test()

Both will execute the new unit test.


This PR strengthens the reliability of date parsing in readr and adds coverage for a meaningful edge case that was previously untested.

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