Skip to content

Conversation

@dragosmg
Copy link
Contributor

@dragosmg dragosmg commented Feb 11, 2022

This PR aligns arrow's binding to strptime() to base::strptime() when the value passed to the format argument does not match the data. Currently arrow errors, when it should return NA.

library(lubridate)
library(arrow)
library(dplyr)

df <- tibble(x = "2022-02-11")

df %>% 
  mutate(z = strptime(x, format = "%Y-%m %d"))
#> # A tibble: 1 × 2
#>   x          z     
#>   <chr>      <dttm>
#> 1 2022-02-11 NA

df %>% 
  record_batch() %>% 
  mutate(z = strptime(x, format = "%Y-%m %d")) %>% 
  collect()
#> Error: Invalid: Failed to parse string: '2022-02-11' as a scalar of type timestamp[ms]

Created on 2022-02-11 by the reprex package (v2.0.1)

@github-actions
Copy link

@github-actions
Copy link

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

@dragosmg dragosmg force-pushed the strptime_return_na_vs_error branch from 7a2700d to d7fefa7 Compare March 24, 2022 16:00
@dragosmg
Copy link
Contributor Author

dragosmg commented Mar 25, 2022

I think several things are needed:

  • new unit tests to show similar behaviour (returning NA in the same circumstances)
  • update existing unit tests. These are not using compare_dplyr_binding() and are not catching the fact that Arrow's strptime binding returns an object of a different class (POSIXct, a double vector) that base::strptime() (POSIXlt, a list)

waldo::compare() does ignore class when ignore_attr = TRUE, but it can't ignore typeof. I'm not sure we want to change the type of object Arrow's strptime binding returns.

@dragosmg
Copy link
Contributor Author

@jonkeane what do you think? Is the type of the object returned by strptime of concern? base::strptime() returns a list (POSIXlt), while the Arrow one returns an atomic vector. We hadn't caught this before as the unit tests for strptime did not compare the {dplyr} and {arrow} pipelines.

@jonkeane
Copy link
Member

@jonkeane what do you think? Is the type of the object returned by strptime of concern? base::strptime() returns a list (POSIXlt), while the Arrow one returns an atomic vector. We hadn't caught this before as the unit tests for strptime did not compare the {dplyr} and {arrow} pipelines.

There are a few comments about this in the tests that reference this — I don't think it was unknown. POSIXlt is pretty unique to R (I'm sure there were other languages that have similar types), but they aren't super wide-spread, and Arrow doesn't support them directly (though you can see in the R package we make a (pseudo)-extension class for them).

@dragosmg
Copy link
Contributor Author

This needs a rebase once #12732 gets merged.

@dragosmg dragosmg force-pushed the strptime_return_na_vs_error branch from 0a1b35f to 727efbd Compare March 29, 2022 09:24
@dragosmg dragosmg marked this pull request as ready for review March 29, 2022 12:21
Copy link
Member

@jonkeane jonkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions about the tests

@dragosmg dragosmg requested a review from jonkeane March 29, 2022 19:52
@dragosmg dragosmg force-pushed the strptime_return_na_vs_error branch from 25863ef to f669be7 Compare March 30, 2022 11:33
@jonkeane jonkeane closed this in ba04e7f Mar 30, 2022
@ursabot
Copy link

ursabot commented Mar 30, 2022

Benchmark runs are scheduled for baseline = 64560af and contender = ba04e7f. ba04e7f is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.21% ⬆️0.04%] test-mac-arm
[Failed ⬇️0.0% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.04% ⬆️0.0%] ursa-thinkcentre-m75q
Buildkite builds:
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/419| ba04e7f8 ec2-t3-xlarge-us-east-2>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/405| ba04e7f8 test-mac-arm>
[Failed] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/405| ba04e7f8 ursa-i9-9960x>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/415| ba04e7f8 ursa-thinkcentre-m75q>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ec2-t3-xlarge-us-east-2/builds/418| 64560af6 ec2-t3-xlarge-us-east-2>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-test-mac-arm/builds/404| 64560af6 test-mac-arm>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-i9-9960x/builds/404| 64560af6 ursa-i9-9960x>
[Finished] <https://buildkite.com/apache-arrow/arrow-bci-benchmark-on-ursa-thinkcentre-m75q/builds/414| 64560af6 ursa-thinkcentre-m75q>
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

@dragosmg dragosmg deleted the strptime_return_na_vs_error branch April 26, 2022 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants