Skip to content

GAM: dir() and the HTML display evaluate no computed property - #225

Merged
jonathan-taylor merged 1 commit into
mainfrom
gam-dir-computed
Oct 27, 2026
Merged

jonathan-taylor merged 1 commit into
mainfrom
gam-dir-computed

Conversation

@jonathan-taylor

Copy link
Copy Markdown
Owner

Follows #224, whose new test test_max_dense_design fails on main.

The guard in #224 works (the covariances are None above max_dense_design, and the standard errors raise). The test fails at the next line, dir(G):

  • scikit-learn's BaseEstimator.__dir__ keeps each attribute for which hasattr() is true, and hasattr catches only AttributeError.
  • Its HTML display (a notebook's) calls inspect.getmembers, which reads every attribute dir() lists.

So dir() and displaying a fitted GAM evaluated all seven computed properties (design_, posterior_covariance_, frequentist_covariance_, edf_influence_, penalty_matrix_, fixed_effects_, fixed_effects_covariance_):

  • below the max_dense_* limits, they formed the dense design and the P x P matrices;
  • with a categorical() term, at any size, fixed_effects_ raises NotImplementedError, so dir() and the display failed;
  • above max_dense_design with an s() term, fixed_effects_ raises ValueError from _check_covariance, so they failed too.

GAM.__dir__ now leaves these properties out, so neither dir() nor the display computes them. They're still there when asked for (G.design_). It keeps scikit-learn's hasattr filter (for available_if) for the remaining names.

Tests:

  • test_max_dense_design adds the s() case over the limit;
  • a new test_display_forms_nothing checks that dir() and estimator_html_repr form no covariance, list none of the computed properties, and that they still evaluate when asked for.

Run locally (glmstar 0.7.0 wheel with this branch's estimator.py, whose C++ is unchanged since): tests/gam 446 passed, 160 skipped; tests/gam/test_gam_sandwich.py with R, 16 passed.

Changelog bullet under Unreleased / Bug fixes.

🤖 Generated with Claude Code

scikit-learn's BaseEstimator.__dir__ keeps each attribute for which
hasattr() is true, and its HTML display reads every attribute dir()
lists (inspect.getmembers). So displaying a fitted GAM evaluated
design_, the covariances, penalty_matrix_ and fixed_effects_: dense
matrices below the max_dense_* limits, and errors that broke dir() and
the display above them, or with a categorical() term (fixed_effects_
raises NotImplementedError, which hasattr does not catch). This is what
failed test_max_dense_design in #224.

GAM.__dir__ now leaves these properties out; they are computed only
when asked for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jonathan-taylor
jonathan-taylor merged commit 3446521 into main Oct 27, 2026
3 checks passed
@jonathan-taylor
jonathan-taylor deleted the gam-dir-computed branch October 27, 2026 22:58
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.

1 participant