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
It's not a bother at all! Happy to guide if you've got a specific bit you were stuck at, or if you'd rather not, that's totally fine, but mind sharing the bigger problem, so if I (or someone else) has time to pick this up, I can use that as a starting point?
I've not had the chance to look into it at all myself yet, so you're ahead of me on this right now.
Honestly, this stuff can be tricky, and that's coming from someone who's been working on this stuff for 2 years and still gets tripped up all the time!
Right now I do that ugly thing to compute weighted medians :
library(arrow)
#> Some features are not enabled in this build of Arrow. Run `arrow_info()` for more information.#> #> Attachement du package : 'arrow'#> L'objet suivant est masqué depuis 'package:utils':#> #> timestamp
library(dplyr)
#> #> Attachement du package : 'dplyr'#> Les objets suivants sont masqués depuis 'package:stats':#> #> filter, lag#> Les objets suivants sont masqués depuis 'package:base':#> #> intersect, setdiff, setequal, uniontf<- tempfile()
dir.create(tf)
write_dataset(mtcars, tf, partitioning="cyl")
ds<- open_dataset(tf)
# weighted median of gross horspower by weightget_median<-function(arrow, var, wt) {
var<- ensym(var)
wt<- ensym(wt)
sel<-arrow %>%
filter(! is.na(!!var) &! is.na(!!wt)) %>%
mutate(!!var:= as.double(!!var),
!!wt:= as.double(!!wt)) %>%
arrange(!!var)
sel_wt<-sel %>% pull(!!wt, as_vector=FALSE)
sel_val<-sel %>% pull(!!var, as_vector=FALSE)
sel_cum_poids<- call_function("cumulative_sum_checked",sel_wt)
sel_sum_wt<-Scalar$create(sel_cum_poids[sel_cum_poids$length()])
sel_val[sel_cum_poids>sel_sum_wt/2][1L]$as_vector()
}
get_median(ds, hp, wt)
#> [1] 175
This isn't very pretty. That's why I searched for a direct binding.
I tried to find a place for Array functions, but I realise that there are none (for the moment). Only summarising or scalar functions.
Thanks for all the effort there trying to make this work, I can see you've delved right into the deep end of things!
I tried to find a place for Array functions, but I realise that there are none
So this isn't super well-documented, which is most likely why you didn't find it, but there's an R6 class in the package called ArrowDatum. It's the base class for Array, ChunkedArray, and Scalar objects, and the point of it is basically to allow developers to write a function e.g. my_fun.ArrowDatum(), which will run on object of this class.
For example, the S3 method for the unique() function (which has an identically named C++ equivalent function) looks like this:
I reckon you could probably take a similar approach for the cumsum function. It might end up being simpler than you thought (but it's the surrounding complexity, and things being hidden away which make it, reasonably, look complex).
@thisisnic I have put the binding for cumsum. As for the datasets, as far as I understand this isn't possible since we use Scalar Expressions.
Thank you for your help.
Activity
thisisnic commentedon Apr 24, 2023
Would you be interested in submitting a PR to add this, @arnaud-feldmann ?
[-]r cumsum[/-][+][R] Implement bindings for cumsum function[/+]arnaud-feldmann commentedon Apr 24, 2023
@thisisnic Ok I'm doing that
thisisnic commentedon Apr 24, 2023
Wonderful, thanks! Let us know if you have any issues, or anything we can help with.
arnaud-feldmann commentedon Apr 24, 2023
Tried all the afternoon, seems like it is above my level. Thought it was just a lacking binding, now I understand there's a bigger problem.
Sorry for the bother @thisisnic . Thanks for your work
thisisnic commentedon Apr 24, 2023
It's not a bother at all! Happy to guide if you've got a specific bit you were stuck at, or if you'd rather not, that's totally fine, but mind sharing the bigger problem, so if I (or someone else) has time to pick this up, I can use that as a starting point?
I've not had the chance to look into it at all myself yet, so you're ahead of me on this right now.
Honestly, this stuff can be tricky, and that's coming from someone who's been working on this stuff for 2 years and still gets tripped up all the time!
arnaud-feldmann commentedon Apr 24, 2023
Right now I do that ugly thing to compute weighted medians :
This isn't very pretty. That's why I searched for a direct binding.
I tried to find a place for Array functions, but I realise that there are none (for the moment). Only summarising or scalar functions.
And, even, cheating, using the UDF interface :
I realised that things starts again at each chunk. Hence that's more complicated than I thought.
But anyway, thanks for your awesome package, I use it everyday.
thisisnic commentedon Apr 25, 2023
Thanks for all the effort there trying to make this work, I can see you've delved right into the deep end of things!
So this isn't super well-documented, which is most likely why you didn't find it, but there's an R6 class in the package called ArrowDatum. It's the base class for Array, ChunkedArray, and Scalar objects, and the point of it is basically to allow developers to write a function e.g.
my_fun.ArrowDatum(), which will run on object of this class.For example, the S3 method for the
unique()function (which has an identically named C++ equivalent function) looks like this:There's a PR here which shows someone implementing
expandsqrtboth for Tables and for ArrowDatum objects.https://github.com/apache/arrow/pull/13517/files
I reckon you could probably take a similar approach for the cumsum function. It might end up being simpler than you thought (but it's the surrounding complexity, and things being hidden away which make it, reasonably, look complex).
arnaud-feldmann commentedon Apr 25, 2023
@thisisnic I have put the binding for cumsum. As for the datasets, as far as I understand this isn't possible since we use Scalar Expressions.
Thank you for your help.
GH-35180: [R] Implement bindings for cumsum function (#35339)
apacheGH-35180: [R] Implement bindings for cumsum function (apache#35339
apacheGH-35180: [R] Implement bindings for cumsum function (apache#35339