stats: fit_clmm no longer raises ImportError when statsmodels is absent - #33
Open
ChrisW09 wants to merge 1 commit into
Open
stats: fit_clmm no longer raises ImportError when statsmodels is absent#33ChrisW09 wants to merge 1 commit into
ChrisW09 wants to merge 1 commit into
Conversation
fit_clmm/fit_logistic are documented to always return a result object with available=False and a reason instead of raising, and the codebase deliberately supports pandas-without-statsmodels environments (fit_effects catches ImportError and falls back to one-way ANOVA). But _design_rank_deficient imported statsmodels outside its try block, so fit_clmm on a >=2-factor study with the default interactions=2 crashed with ImportError in exactly those environments. Fixes #9 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9.
_design_rank_deficient(shared byfit_clmmandfit_logisticfor the aliasing check) importedstatsmodels.formula.apioutside itstry, so in a pandas-without-statsmodels environment — whichfit_effectsdeliberately supports via its ownImportErrorfallback —fit_clmmon a ≥2-factor study with the defaultinteractions=2raisedImportErrorinstead of returning its documented gracefulCLMMResult. Single-factor orinteractions=1studies dodged it via the early return, making the crash data-shape dependent.The import is now guarded; without statsmodels the aliasing check is simply skipped (
return False), matching the function's existing "can't determine → False" behavior. Regression test simulates the missing module viasys.modules.Test:
pytest packages/cafe-core/tests/test_stats.py— 19 passed (the one failure is pre-existing #4, fixed in a separate PR).🤖 Generated with Claude Code