Skip to content

BUG: Adjust eval environment for stack depth - #9047

Closed
rob-sil wants to merge 2 commits into
statsmodels:mainfrom
rob-sil:eval-depth-from-formula
Closed

rob-sil wants to merge 2 commits into
statsmodels:mainfrom
rob-sil:eval-depth-from-formula

Conversation

@rob-sil

@rob-sil rob-sil commented Oct 28, 2023

Copy link
Copy Markdown
Contributor

This PR fixes the formula environment for the conditional logit and Poisson, the proportional hazards model, GEE, and QIF.

@bashtage

Copy link
Copy Markdown
Member

Overall PR looks good. Do you know if other formulas suffer, or is this the full extent fo the problem?

@bashtage

Copy link
Copy Markdown
Member

There are a few linting issues that need to be fixed. You can ignore MICE errors (needs a deep dive).

@rob-sil

rob-sil commented Oct 29, 2023

Copy link
Copy Markdown
Contributor Author

The problem appears in several other from_formulas, but gets more complicated because multiple formulas are used. For example, BetaModel takes both the main formula and an optional exog_precision_formula. That second formula isn't parsed with an eval environment, so I expect that it would similarly grab the environment from a statsmodels file rather than the user's environment.

I was trying to sidestep those cases for my first contribution (sorry about the linting error) but I just noticed GEE.from_formula has an optional second formula too. If you don't mind a longer PR, I can extend the fix to those other implementations and their other formulas.

What do you think about putting eval_env into the method signatures directly? I'm not sure if it would have to be a keyword-only argument to avoid breaking possible uses.

@josef-pkt josef-pkt added this to the 0.15 milestone Feb 9, 2024
@josef-pkt josef-pkt mentioned this pull request Jun 17, 2024
6 tasks
@josef-pkt

Copy link
Copy Markdown
Member

I guess this conflicts with formulaic merge

@bashtage
Is there anything left in this PR that needs to be merged?

@bashtage

bashtage commented Jan 6, 2025

Copy link
Copy Markdown
Member

Leave it to me. I'll add the test and see if it causes any problems.

bashtage added a commit to bashtage/statsmodels that referenced this pull request Jan 7, 2025
Ensure eval env depth is increased when using super to
build model formulas

closes statsmodels#9047
closes statsmodels#9037
@bashtage bashtage mentioned this pull request Jan 7, 2025
5 tasks done
@bashtage

bashtage commented Jan 7, 2025

Copy link
Copy Markdown
Member

Updated fix in #9471 Found a few more cases where this fix matters. Thanks for the PR. Very helpful.

bashtage added a commit to bashtage/statsmodels that referenced this pull request Jan 7, 2025
Ensure eval env depth is increased when using super to
build model formulas

closes statsmodels#9047
closes statsmodels#9037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Cox Model from formula doesn't grab the correct environment

3 participants