Skip to content

stats: fit_clmm no longer raises ImportError when statsmodels is absent - #33

Open
ChrisW09 wants to merge 1 commit into
mainfrom
fix/fit-clmm-importerror
Open

stats: fit_clmm no longer raises ImportError when statsmodels is absent#33
ChrisW09 wants to merge 1 commit into
mainfrom
fix/fit-clmm-importerror

Conversation

@ChrisW09

Copy link
Copy Markdown
Collaborator

Fixes #9.

_design_rank_deficient (shared by fit_clmm and fit_logistic for the aliasing check) imported statsmodels.formula.api outside its try, so in a pandas-without-statsmodels environment — which fit_effects deliberately supports via its own ImportError fallback — fit_clmm on a ≥2-factor study with the default interactions=2 raised ImportError instead of returning its documented graceful CLMMResult. Single-factor or interactions=1 studies 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 via sys.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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stats: fit_clmm raises ImportError instead of returning CLMMResult when statsmodels is missing

1 participant