statsmodels icon indicating copy to clipboard operation
statsmodels copied to clipboard

BUG: Adjust eval environment for stack depth

Open rob-sil opened this issue 2 years ago • 3 comments

  • [x] closes #9037
  • [x] tests added / passed.
  • [x] properly formatted commit message. See NumPy's guide.

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

rob-sil avatar Oct 28 '23 20:10 rob-sil

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

bashtage avatar Oct 29 '23 16:10 bashtage

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

bashtage avatar Oct 29 '23 16:10 bashtage

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.

rob-sil avatar Oct 29 '23 20:10 rob-sil