pyGAM
pyGAM copied to clipboard
fix(core): prevent get_params from mutating estimator state
Summary
This PR fixes an issue where Core.get_params(deep=True) could expose mutable estimator state.
Previously, the method could return references to internal attributes, which meant that modifying the returned dictionary could unintentionally mutate the estimator configuration.
Fix
The implementation now constructs the parameter dictionary exclusively from the estimator's _include parameters and returns a deep copy when deep=True. This ensures that external modifications to the returned dictionary do not affect the estimator state.
Changes
- Updated
get_params()implementation inpygam/core.py - Added a regression test to ensure returned parameters do not mutate estimator state
Test
Added:
def test_get_params_does_not_mutate_state():
from pygam import LinearGAM
gam = LinearGAM()
params = gam.get_params(deep=True)
params["max_iter"] = 999
assert gam.max_iter != 999
assert "max_iter" in params