bambinos / formulae

Formulas for mixed-effects models in Python

Home Page:https://bambinos.github.io/formulae/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested stateful transformations don't work

tomicapretto opened this issue · comments

We fail at parsing and resolving terms that are nested function calls. All the following alternatives work without any problem

design_matrices("y ~ f(x1)", data)
design_matrices("y ~ f(arg = x1)", data)
design_matrices("y ~ f(arg = 'blabla')", data)
design_matrices("y ~ f(arg1= a, arg2 = "blabla")", data)

But nested function calls, like the following, don't work

design_matrices("y ~ f(g(x1))", data)
design_matrices("y ~ f(arg = g(x1))", data)
# ...etc

To solve this we need to update the Resolver.visitCallExpr() method as well as how the call term handles Expr.Call() instances, and maybe something else that I'm missing now.

UPDATE

Actually, nested function calls work. But nested function calls that are stateful transformations don't work. For example, all the following work

design_matrices("y ~ np.exp(np.exp(x)))", data)
design_matrices("y ~ my_function(np.exp(x))", data)
design_matrices("y ~ scale(np.exp(x))", data) # scale() is a built-in stateful transformation

But the following does not work

design_matrices("y ~ scale(scale(x))", data)

Why would anyone do scale(scale())? Who knows... I just know that, for now, it does not work.