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

fix: evaluate Series methods in the correct environment #973

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

etiennebacher
Copy link
Collaborator

Close #970

@eitsupi
Copy link
Collaborator

eitsupi commented Mar 27, 2024

I was researching this as well. Please see this SO answer.
https://stackoverflow.com/questions/55813859/non-standard-evaluation-in-a-user-defined-function-with-lapply-or-with-in-r

As an important correction, we need to use match.call here, not sys.call.

f <- function(x, ..., y = 0) {x + y}

g1 <- function(x, y) {do.call(f, as.list(match.call()[-1]), envir = parent.frame())}
h1 <- function() {a <- 100; g1(1, a)}

g2 <- function(x, y) {do.call(f, as.list(sys.call()[-1]), envir = parent.frame())}
h2 <- function() {a <- 100; g2(1, a)}

h1()
#> [1] 101
h2()
#> [1] 1

Created on 2024-03-27 with reprex v2.1.0

@etiennebacher
Copy link
Collaborator Author

Seems like we use sys.call() in several other places, should those be replaced too?

Otherwise, I think this is good to go, failures are due to some CI stuff

@eitsupi
Copy link
Collaborator

eitsupi commented Mar 27, 2024

Seems like we use sys.call() in several other places, should those be replaced too?

I looked at it and it probably does not need to be updated.

I am thinking about tests that should be added. Once the tests are added, I merge this.

Comment on lines +162 to +163
"over",
"rolling",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have removed these as they are not directly related to this PR, but obviously they do not work on the Series.

Copy link
Collaborator

@eitsupi eitsupi left a comment

Choose a reason for hiding this comment

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

CI failure is unrelated to this change.

@eitsupi eitsupi merged commit d0b63d5 into main Mar 27, 2024
18 of 19 checks passed
@eitsupi eitsupi deleted the fix-series-functions branch March 27, 2024 14:13
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.

polars cannot identify the value in function
3 participants