You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently lubridates ymd, dmy etc. parsing functions work by guessing the best matching date format using a subset of the input data (see.get_train_set for the algorithm which is currently based on primes):
Current behaviour
If the subset contains only invalid or no dates this warning is thrown even if the date format could be derived from other correct dates that are not contained in the subset:
# https://github.com/tidyverse/lubridate/blob/f9f36a09f5d02b3fedf478bd93e7f547cac65752/R/parse.r#L630
warning("All formats failed to parse. No formats found.", call. = FALSE)
Impact
Since warnings do not stop the program execution in R
wrong results can be overlooked easily (the results of subsequent logic may be wrong without seeing an error)
errors in other parts of the user's R code due to non-parsed dates are harder to track-back to the real reason (failed parsing of dates earlier).
Also note: Unit tests may not discover parsing errors with given predefined test data but in production just a different number of elements to be parsed may cause problems (= no formats found) due to the "sampling" (subsetting) logic to recognize the date format. This has the same impact as 1, but with a "good unit test feeling", that everything is working.
Suggestions
Throw an error instead of a warning and
add an option to configure if you want to get an error or a warning (with an error as default value)
I also suggest to improve the warning message to indicate a solution for the problem.
This may possibly reduce the number of questions for this on SO and here ;-)
warning("All formats failed to parse. No formats found. Use parse_date_time with exact=TRUE instead.", call. = FALSE)
I also want to highlight the suggested change to the message. It always takes me a few moments to say 'aha I recognize that warning as a date parsing error from previous experience'
Regarding the message, having an error would at least make it possible to use traceback() to find the cause.
But I think a more specific warning (or error) could help debugging if it printed the string/number that wasn't recognized and the function name like
warning("lubridate function ymd couldn't convert '11 22 3' to a date")
I'll also point out that the current behavior of throwing a warning is inconsistent with documentation that indicates failure to parse should be an error
Context
Currently
lubridate
symd
,dmy
etc. parsing functions work by guessing the best matching date format using a subset of the input data (see.get_train_set
for the algorithm which is currently based on primes):Current behaviour
If the subset contains only invalid or no dates this warning is thrown even if the date format could be derived from other correct dates that are not contained in the subset:
Impact
Since warnings do not stop the program execution in R
Suggestions
I also suggest to improve the warning message to indicate a solution for the problem.
This may possibly reduce the number of questions for this on SO and here ;-)
See also
#897
The text was updated successfully, but these errors were encountered: