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
{{ message }}
Repository navigation
[C++] strptime rolls-over dates not in range for current month #31374
I noticed some potentially unexpected behaviour when converting from string to date. Days that are out of bounds for the given month are rolled over into the following month.
I think the expected behaviour would be to either error (Python) or return NULL/NA (R), but not to roll over dates in the following month.
library(arrow, warn.conflicts=FALSE)
library(lubridate, warn.conflicts=FALSE)
library(dplyr, warn.conflicts=FALSE)
df<-tibble::tibble(string_date="1999-02-30")
# base R returns NAdf %>%
mutate(date= strptime(string_date, format="%Y-%m-%d"))
#> # A tibble: 1 × 2#> string_date date #> <chr> <dttm>#> 1 1999-02-30 NA# arrow rolls over the 30th of February into the 2nd of Marchdf %>%
arrow_table() %>%
mutate(date= strptime(string_date, format="%Y-%m-%d")) %>%
collect()
#> # A tibble: 1 × 2#> string_date date #> <chr> <dttm> #> 1 1999-02-30 1999-03-02 00:00:00
Thanks Alenka, Joris and Rok for helping me with the Python examples:
pandas:
Joris Van den Bossche / @jorisvandenbossche:
Copying my comment from the other issue: personally, I don't like that behaviour, but I suppose we get this from the system strptime? (so that might even depend on your OS?)
It might be interesting to check what date.h's version of strptime does.
I think the expected behaviour would be to either error (Python) or return NULL/NA (R),
I would say it is both: by default error, and optionally return null (after ARROW-15665)
Activity
asfimport commentedon Mar 16, 2022
Joris Van den Bossche / @jorisvandenbossche:
Copying my comment from the other issue: personally, I don't like that behaviour, but I suppose we get this from the system strptime? (so that might even depend on your OS?)
It might be interesting to check what date.h's version of strptime does.
I would say it is both: by default error, and optionally return null (after ARROW-15665)
asfimport commentedon Mar 16, 2022
Rok Mihevc / @rok:
Two notes:
Perhaps system strptimes have an option to disable this behaviour?
Switching from system to date.h strptime might have performance implications so we should probably benchmark as we change this.
asfimport commentedon Jun 29, 2022
Antoine Pitrou / @pitrou:
Does date.h have a strptime? We use a vendored implementation from musl on Windows.
asfimport commentedon Jun 29, 2022
Rok Mihevc / @rok:
It does, but there's this comment: https://github.com/apache/arrow/blob/master/cpp/src/arrow/util/value_parsing.h#L784
asfimport commentedon Jun 29, 2022
Antoine Pitrou / @pitrou:
Ah, well, let's not use it, then :)
asfimport commentedon Jun 29, 2022
Rok Mihevc / @rok:
But maybe it's nice to dates? :D
thisisnic commentedon Jul 30, 2026
Still an issue as of 25.0.0 - potential fix is to call the
.ok()method to check.apacheGH-31374: [C++] Reject invalid calendar dates parsed by strptime
apacheGH-31374: [C++] Prevent strptime from normalizing invalid dates
apacheGH-31374: [C++] Prevent strptime from normalizing invalid dates