Skip to content
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

r_base::sum() handling na.rm = #75

Merged
merged 8 commits into from
Apr 24, 2024
Merged

r_base::sum() handling na.rm = #75

merged 8 commits into from
Apr 24, 2024

Conversation

romainfrancois
Copy link
Collaborator

@romainfrancois romainfrancois commented Apr 19, 2024

closes #70

@romainfrancois romainfrancois changed the title initial r_base::sum() passthrough r_base::sum() handling na.rm = Apr 19, 2024
unique_ptr<FunctionData> BindRSum(ClientContext &context, AggregateFunction &function, vector<unique_ptr<Expression>> &arguments) {
function = SumFun::GetFunctions().GetFunctionByArguments(context, {arguments[0]->return_type});
return nullptr;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: handle arguments[1] here, i.e. if it is TRUE go through the data and if we find a null, then bind to a function that returns a null somehow.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can assume a constant here, duckplyr won't let anything else through.

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

unique_ptr<FunctionData> BindRSum(ClientContext &context, AggregateFunction &function, vector<unique_ptr<Expression>> &arguments) {
function = SumFun::GetFunctions().GetFunctionByArguments(context, {arguments[0]->return_type});
return nullptr;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can assume a constant here, duckplyr won't let anything else through.

@romainfrancois
Copy link
Collaborator Author

handling na.rm = FALSE:

library(duckdbrfuns)

rfuns_sum(1:10)
#> [1] 55
rfuns_sum(c(1:10, NA))
#> [1] 55

rfuns_sum(c(1:10, NA), na.rm = TRUE)
#> [1] 55
rfuns_sum(c(1:10, NA), na.rm = FALSE)
#> [1] NA

rfuns_sum(integer(), na.rm = FALSE)
#> [1] 0
rfuns_sum(integer(), na.rm = TRUE)
#> [1] 0

rfuns_sum(NA_integer_, na.rm = TRUE)
#> [1] 0
rfuns_sum(NA_integer_, na.rm = FALSE)
#> [1] NA

Created on 2024-04-24 with reprex v2.1.0

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

Thanks. We also want sum(logical()), but this could be a separate PR.

@romainfrancois romainfrancois merged commit 5ca3a39 into main Apr 24, 2024
31 of 39 checks passed
@romainfrancois romainfrancois deleted the sum branch April 24, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extension sum() function
2 participants