Uh oh!
There was an error while loading. Please reload this page.
ARROW-16407: [R] Extend parse_date_time to cover hour, dates, and minutes components - #13196
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dragosmg
commented
May 23, 2022
@jonkeane I think this is ready for another look |
jonkeane
left a comment
There was a problem hiding this comment.
This is moving, still a few functionality rough edges that need work. A few general notes:
I'm still struggling a bit following some of the logic. More comments, especially with details about what's in some of the various variables would be helpful to follow what's going on. It's hard to know now what things are lists of expressions versus lists of characters like "Ym" versus lists of characters like "%Y-%m"
Should we test
build_formats()directly to detect some of the more bespoke | full set of order checks? This would make the tests a lot easier to reason about (what we're testing is more obvious + we wouldn't need to have a whole data frame + date setup in it) Take a look at the other helper functions to see if the same is true for them.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Edit: I opened ARROW-16653 Given this is a relatively large PR I propose I open a follow-up ticket to go with a fine-tooth comb and check for edge cases, formats , etc. I think we cover the vast majority of use cases, but I'd like to be able to spend some time looking at unit tests, helpers descriptions, error messages, messaging around unsupported orders (there shouldn't be any left) etc. |
It looks like combining the separator (e.g. Results table>results# A tibble: 2 × 13expressionminmedian`itr/sec`mem_alloc`gc/sec`n_itrn_gctotal_timeresultmemorytimegc<bch:expr><bch:tm><bch:tm><dbl><bch:byt><dbl><int><dbl><bch:tm><list><list><list><list>1separate6s6.03s0.16515.5MB0.02921731.72m<tibble><Rprofmem><bench_tm [20]><tibble>2combined3.36s3.37s0.29715.5MB0.03301821.01m<tibble><Rprofmem><bench_tm [20]><tibble>Codelibrary(dplyr)
library(lubridate)
library(ggplot2)
library(hrbrthemes)
load_all()
test_df<-tibble::tibble(
a= rep(c("20220614", "2022-06-14"), 1e6)
)
results<-bench::mark(
separate=test_df %>% arrow_table() %>% mutate(b= parse_date_time(a, orders="ymd")) %>% collect(),
combined=test_df %>% arrow_table() %>% mutate(b= parse_date_time_combined(a, orders="ymd")) %>% collect(), min_iterations=20
)
resultsggplot2::autoplot(results) +
theme_ipsum_rc(grid="XxY") +
labs(title="Comparison of format parsing",
subtitle="separate = formats with or without separator are tried separately\ncombined = formats are combined in a single vector and all are passed to `coalesce()`")DetailsI benchmarked 3 different versions of separate (using different formats for x with and without separator):
All 3 versions performed similarly, being slower than the version in which the formats were combined into a single vector. |
…()` returns both "-" separated and non-separated formats in a single vector
I think this is ready for another look @jonkeane. What changed since our last conversation?
|
paleolimbot
left a comment
There was a problem hiding this comment.
I can't speak to the completeness of testing/features or motivation since I haven't been following the discussion, but the code itself is easy to read and the approach seems reasonable.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
rok
left a comment
There was a problem hiding this comment.
This looks good to me (but I don't know the R codebase well)!
…inutes components (apache#13196) This PR improves `parse_date_time()` by: * adding support for orders with the hours, minutes, and seconds components * adding support for unseparated strings ([ARROW-16446](https://issues.apache.org/jira/browse/ARROW-16446)) * supporting the `exact` argument: * allows users to pass `exact = TRUE` in which case the `orders` are taken as they are (they are considered `formats` and passed to `strptime`) * `exact = FALSE` implies `formats` are derived from `orders` * allowing the `truncated` argument * denotes number of formats that might be missing. For example, passing an `order` like `ymd_HMS` and a value of 1 for `truncated` will attempt parsing with both `ymd_HMS` and `ymd_HM` orders * erroring when the user passes `quiet = FALSE` * improves the utility function used to generate `formats` (which are then passed on to `strptime`) from `orders` * less hard-coding and increased ability to deal with different orders and separators the `ymd HMS` orders (and variants) will parse correctly: ``` r library(dplyr, warn.conflicts = FALSE) library(lubridate, warn.conflicts = FALSE) library(arrow, warn.conflicts = FALSE) test_df <- tibble( x = c("2011-12-31 12:59:59", "2010-01-01 12:11", "2010-01-01 12", "2010-01-01") ) test_df %>% mutate( y = parse_date_time(x, "Ymd HMS", truncated = 3) ) #> # A tibble: 4 × 2 #> x y #> <chr> <dttm> #> 1 2011-12-31 12:59:59 2011-12-31 12:59:59 #> 2 2010-01-01 12:11 2010-01-01 12:11:00 #> 3 2010-01-01 12 2010-01-01 12:00:00 #> 4 2010-01-01 2010-01-01 00:00:00 test_df %>% arrow_table() %>% mutate( y = parse_date_time(x, "Ymd HMS", truncated = 3) ) %>% collect() #> # A tibble: 4 × 2 #> x y #> <chr> <dttm> #> 1 2011-12-31 12:59:59 2011-12-31 12:59:59 #> 2 2010-01-01 12:11 2010-01-01 12:11:00 #> 3 2010-01-01 12 2010-01-01 12:00:00 #> 4 2010-01-01 2010-01-01 00:00:00 ``` <sup>Created on 2022-05-19 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup> `exact = TRUE` can also be used: <details> ``` r library(arrow, warn.conflicts = FALSE) library(lubridate, warn.conflicts = FALSE) library(dplyr, warn.conflicts = FALSE) test_df <- tibble( x = c("11/23/1998 07:00:00", "6/18/1952 0135", "2/25/1974 0523", "9/07/1985 01", NA) ) test_df %>% mutate( parsed_x = parse_date_time( x, c("%m/%d/%Y %I:%M:%S", "%m/%d/%Y %H%M", "%m/%d/%Y %H"), exact = TRUE ) ) #> # A tibble: 5 × 2 #> x parsed_x #> <chr> <dttm> #> 1 11/23/1998 07:00:00 1998-11-23 07:00:00 #> 2 6/18/1952 0135 1952-06-18 01:35:00 #> 3 2/25/1974 0523 1974-02-25 05:23:00 #> 4 9/07/1985 01 1985-09-07 01:00:00 #> 5 <NA> NA test_df %>% arrow_table() %>% mutate( parsed_x = parse_date_time( x, c("%m/%d/%Y %I:%M:%S", "%m/%d/%Y %H%M", "%m/%d/%Y %H"), exact = TRUE ) ) %>% collect() #> # A tibble: 5 × 2 #> x parsed_x #> <chr> <dttm> #> 1 11/23/1998 07:00:00 1998-11-23 07:00:00 #> 2 6/18/1952 0135 1952-06-18 01:35:00 #> 3 2/25/1974 0523 1974-02-25 05:23:00 #> 4 9/07/1985 01 1985-09-07 01:00:00 #> 5 <NA> NA ``` <sup>Created on 2022-05-20 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)</sup> </details> Authored-by: Dragoș Moldovan-Grünfeld <dragos.mold@gmail.com> Signed-off-by: Alessandro Molina <amol@turbogears.org>
…Hub issue numbers (#34260) Rewrite the Jira issue numbers to the GitHub issue numbers, so that the GitHub issue numbers are automatically linked to the issues by pkgdown's auto-linking feature. Issue numbers have been rewritten based on the following correspondence. Also, the pkgdown settings have been changed and updated to link to GitHub. I generated the Changelog page using the `pkgdown::build_news()` function and verified that the links work correctly. --- ARROW-6338#5198ARROW-6364#5201ARROW-6323#5169ARROW-6278#5141ARROW-6360#5329ARROW-6533#5450ARROW-6348#5223ARROW-6337#5399ARROW-10850#9128ARROW-10624#9092ARROW-10386#8549ARROW-6994#23308ARROW-12774#10320ARROW-12670#10287ARROW-16828#13484ARROW-14989#13482ARROW-16977#13514ARROW-13404#10999ARROW-16887#13601ARROW-15906#13206ARROW-15280#13171ARROW-16144#13183ARROW-16511#13105ARROW-16085#13088ARROW-16715#13555ARROW-16268#13550ARROW-16700#13518ARROW-16807#13583ARROW-16871#13517ARROW-16415#13190ARROW-14821#12154ARROW-16439#13174ARROW-16394#13118ARROW-16516#13163ARROW-16395#13627ARROW-14848#12589ARROW-16407#13196ARROW-16653#13506ARROW-14575#13160ARROW-15271#13170ARROW-16703#13650ARROW-16444#13397ARROW-15016#13541ARROW-16776#13563ARROW-15622#13090ARROW-18131#14484ARROW-18305#14581ARROW-18285#14615 * Closes: #33631 Authored-by: SHIMA Tatsuya <ts1s1andn@gmail.com> Signed-off-by: Sutou Kouhei <kou@clear-code.com>

This PR improves
parse_date_time()by:exactargument:exact = TRUEin which case theordersare taken as they are (they are consideredformatsand passed tostrptime)exact = FALSEimpliesformatsare derived fromorderstruncatedargumentorderlikeymd_HMSand a value of 1 fortruncatedwill attempt parsing with bothymd_HMSandymd_HMordersquiet = FALSEformats(which are then passed on tostrptime) fromordersthe
ymd HMSorders (and variants) will parse correctly:Created on 2022-05-19 by the reprex package (v2.0.1)
exact = TRUEcan also be used:Details
Created on 2022-05-20 by the reprex package (v2.0.1)