Repository navigation
GAM: dir() and the HTML display evaluate no computed property - #225
Merged
Merged
Conversation
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>
Merged
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.
Follows #224, whose new test
test_max_dense_designfails 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):BaseEstimator.__dir__keeps each attribute for whichhasattr()is true, andhasattrcatches onlyAttributeError.inspect.getmembers, which reads every attributedir()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_):max_dense_*limits, they formed the dense design and the P x P matrices;categorical()term, at any size,fixed_effects_raisesNotImplementedError, sodir()and the display failed;max_dense_designwith ans()term,fixed_effects_raisesValueErrorfrom_check_covariance, so they failed too.GAM.__dir__now leaves these properties out, so neitherdir()nor the display computes them. They're still there when asked for (G.design_). It keeps scikit-learn'shasattrfilter (foravailable_if) for the remaining names.Tests:
test_max_dense_designadds thes()case over the limit;test_display_forms_nothingchecks thatdir()andestimator_html_reprform 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/gam446 passed, 160 skipped;tests/gam/test_gam_sandwich.pywith R, 16 passed.Changelog bullet under Unreleased / Bug fixes.
🤖 Generated with Claude Code