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

RecursionError: maximum recursion depth exceeded for large models #78

Closed
Osburg opened this issue May 17, 2022 · 4 comments · Fixed by #83
Closed

RecursionError: maximum recursion depth exceeded for large models #78

Osburg opened this issue May 17, 2022 · 4 comments · Fixed by #83
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Osburg
Copy link

Osburg commented May 17, 2022

Hi :)

I ran into the following error. When I try to create a Formula object with more than 246 model terms I get a RecursionError. One can fix this by simply setting the recursion limit to a higher value but I wanted to report this because I think it is potentially unwanted behaviour. This is a minimal example to reproduce the error:

from formulaic import Formula

expr = ""
for i in range(247):
    expr += f"x{i} + "
expr = expr[:-3]

f = Formula(expr)
@matthewwardrop matthewwardrop self-assigned this May 25, 2022
@matthewwardrop matthewwardrop added the enhancement New feature or request label May 25, 2022
@matthewwardrop matthewwardrop added this to the 0.4.0 milestone May 25, 2022
@matthewwardrop
Copy link
Owner

Thanks for reporting this @Osburg ! The threshold seems to be much higher for me (737), but I can reproduce this. The issue is that the AST generated for the formula is evaluated implicitly via recursion. Fixing this will require switching to a topological evaluation of the formula, and slightly less clean code. Nevertheless, you're right... this is something that really ought not to break, so I'll see if I can resolve it in 0.4.0.

@matthewwardrop
Copy link
Owner

The above PR should fix things. My plan is to get it in along with a few other fixes and call it 0.4.0 :).

@matthewwardrop
Copy link
Owner

@Osburg @DavidWalz Sorry for the delay! 0.4.0 has now been released :).

@DavidWalz
Copy link

Awesome, works like a charm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
3 participants