Commit 98b8201
Address PR #346 CI review round 10: P1 sklearn-compatible get/set_params
**P1 (Code Quality): sklearn parameter contract**
The class docstring advertises `sklearn.base.clone(est)` compatibility,
but the actual methods did not match sklearn's
`BaseEstimator.get_params(deep=True)` / `set_params(**params)` surface:
- `get_params()` did not accept a `deep` keyword. sklearn's `clone`
calls `get_params(deep=False)`, so any integration would have
failed with a TypeError on the missing kwarg.
- `set_params()` validated keys with `hasattr(self, key)`. That would
silently accept non-constructor attribute names like `fit`, and a
typo or malicious kwargs dict could overwrite estimator methods.
Fix:
- `get_params(self, deep: bool = True)` matches sklearn's signature.
`deep` is accepted for compat; this estimator has no nested
sub-estimators, so `deep=True` and `deep=False` return the same
dict. `del deep` documents the no-op explicitly and silences
unused-arg linters.
- `set_params(**params)` now restricts to keys from `get_params()`.
Non-constructor attribute names (including method names like `fit`
and dunder/private attrs) raise `ValueError`.
**Tests (+4 regression):**
- test_set_params_rejects_method_names: `set_params(fit=...)` raises
and `est.fit` stays callable.
- test_set_params_rejects_private_attrs: `_internal=42` raises.
- test_get_params_accepts_deep_keyword: `deep=True`, `deep=False`, and
no-arg all return the same dict.
- test_sklearn_clone_round_trip_if_available: `sklearn.base.clone`
round-trips the estimator; gated on `pytest.importorskip("sklearn")`
so it skips cleanly when sklearn is not in the test matrix.
Targeted regression: 155 HAD tests (+ 1 skipped) + 534 total (+1
skipped) across Phase 1 and adjacent surfaces, all green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent a3553ed commit 98b8201
2 files changed
Lines changed: 64 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
994 | 994 | | |
995 | 995 | | |
996 | 996 | | |
997 | | - | |
| 997 | + | |
998 | 998 | | |
999 | 999 | | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
1003 | 1012 | | |
| 1013 | + | |
1004 | 1014 | | |
1005 | 1015 | | |
1006 | 1016 | | |
| |||
1012 | 1022 | | |
1013 | 1023 | | |
1014 | 1024 | | |
1015 | | - | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1016 | 1033 | | |
1017 | | - | |
| 1034 | + | |
1018 | 1035 | | |
1019 | | - | |
1020 | | - | |
| 1036 | + | |
1021 | 1037 | | |
1022 | 1038 | | |
1023 | 1039 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
849 | 849 | | |
850 | 850 | | |
851 | 851 | | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
852 | 892 | | |
853 | 893 | | |
854 | 894 | | |
| |||
0 commit comments