-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-15701 [R] month() should allow integer inputs #12482
Conversation
2965c21
to
c6daf89
Compare
r/R/dplyr-funcs-datetime.R
Outdated
call_binding("between", x, 1, 12), | ||
x, | ||
NA_integer_) | ||
x <- build_expr("cast", x * 28L, options = cast_options(to_type = date32())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a cheeky implementation, but it works. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could actually short-circuit here and return the expression with simply if_else
when label = FALSE
, since that will return an integer itself, yeah?
I agree that this is a little bit unorthodox, but I think it works. An alternative would be to put this value into a date string with a call to the paste
binding and then doing strptime
on that. Both aren't super ideal — but I suspect that this integer multiplication is going to be more performant (though if we are basing a decision on that, we probably should measure it!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't done any benchmarking yet.
3273d94
to
ce79b61
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good — a few comments about the structure of the function body.
Also, there's at least one call to Expression$create()
that probably could be build_expr()
, what do you think?
r/R/dplyr-funcs-datetime.R
Outdated
call_binding("between", x, 1, 12), | ||
x, | ||
NA_integer_) | ||
x <- build_expr("cast", x * 28L, options = cast_options(to_type = date32())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could actually short-circuit here and return the expression with simply if_else
when label = FALSE
, since that will return an integer itself, yeah?
I agree that this is a little bit unorthodox, but I think it works. An alternative would be to put this value into a date string with a call to the paste
binding and then doing strptime
on that. Both aren't super ideal — but I suspect that this integer multiplication is going to be more performant (though if we are basing a decision on that, we probably should measure it!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two very minor, more stylistic nit-picky comments that you can take or leave
…er is outside the 1:12 range
71e9f4e
to
75e8b0a
Compare
Benchmark runs are scheduled for baseline = a76794c and contender = 1b77e6d. 1b77e6d is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
Once this PR is merge the {arrow} binding for
month()
will be able to accept integer inputs. This also impact thesemester()
which now will be able to extract semesters from integer inputs.Created on 2022-03-02 by the reprex package (v2.0.1)