Repository navigation
Release 0.2.3: format v4, security hardening and round-trip fixes - #60
Merged
Merged
Conversation
… allowlisted function loading
…ncs, array functions)
…adiusNeighborsTransformer data
…and sample weights
…nel hyperparameters
…form and get_feature_names_out
…esn't restore — test_helpers.py, test_test_helpers.py, test_estimator_conformance.py
…stead of an envelope
…f objects at save
…1.6 ColumnTransformers can be saved
…setup to satisfy flake8
…ample-weight equivalence checks
…ibility test isn't flaky
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.
Release 0.2.3: format v4, security hardening and round-trip fixes
Summary
This PR prepares openmodels 0.2.3. It has three main themes:
predict,transformor refit, or quietly behaved differently from the original. These are fixed.The full list of changes is in
CHANGELOG.md. The format reference is indocs/format.md.Function allowlist. Functions referenced by a file (
FunctionTransformer.func,SelectKBest.score_func, ...) are no longer imported from whatever module the file names. A function is accepted only if:__module__) is one of those too. This blocks re-exports such assklearn.datasets._base.makedirs, which isos.makedirs.Private names and
__main__are always refused. To load files that use your own functions, passSklearnSerializer(trusted_function_modules=["mypkg"]).Builtins such as
absnow raiseDeserializationErrorunless"builtins"is trusted.Bound methods of an object (e.g. a fitted estimator's
fit_transform) now raiseSerializationErrorat save. Saving them by name lost the object they belong to.Clearer errors.
SerializationManagernow raisesSerializationError/DeserializationError, with the original exception as__cause__, where it used to leakKeyError,AttributeErrororTypeError.🔒 Security
__import__.kernel_typemust name a concreteKernelclass. Before, any callable insklearn.gaussian_process.kernelscould be called with the file's parameters.scipy.statsdistribution generator. Before, any publicscipy.statsfunction could be called.ast.literal_eval, nevereval.SECURITY.mdhas a new section, "Functions referenced by a model".📦 Wire format v4
estimator_packagenext toestimator_class. Classes are looked up by package and class name, so a custom class can share a scikit-learn class's name (e.g. chemotools'MinMaxScaler) without replacing it. v1–v3 files are still looked up by bare name, now with a warning when the name is ambiguous.class_weight={0: 1.0}) are saved as text, with their types stored next to the value types.🐛 Notable fixes
leaf_size. Non-euclideankd_tree/ball_treemodels returned wrong neighbors before.BallTreemodels can now be saved, andKNeighborsRegressor/RadiusNeighborsRegressorcan predict after load.KernelDensity: now round-trips exactly, including its metric and sample weights.Matern,RationalQuadratic,CompoundKernel, anisotropicRBF, ...).ColumnTransformer:make_column_selector;_RemainderColsListerror).Pipeline,FeatureUnion,Voting*,Stacking*) load as estimators instead of raw dicts.dtype=np.int64), NumPy scalars (np.float32(0.5)), ufuncs,scipy.specialfunctions and NumPy array functions (np.std,np.linalg.norm) now load as the original objects instead of floats or raw dicts.param_distributions.predict_proba,staged_predict*,transform,get_feature_names_outandscoreis now saved or rebuilt for HistGradientBoosting, LDA, KNNImputer, OneClassSVM, NMF, HDBSCAN,GridSearchCV/RandomizedSearchCV, and 24 estimators that useget_feature_names_out.MinMaxScaler,CountVectorizer, ... can be refitted.custom_estimators: a list of(name, class)pairs now registers its classes. Before, it silently registered nothing.Some fixes only apply to files saved with 0.2.3 (the changelog marks them "re-save older files"). Others also repair files written by earlier versions.
🧪 Testing
test_inference_parity.py, which compares every inference method of the original and loaded models;test_resume_training.py, which records which estimators can resume training after load;test_format_v4.py;roundtrip_fitandrun_test_modeltest helpers now check more strictly, so state that isn't saved can no longer go unnoticed.11189 passed, 551 skipped, 95 xfailedmypy openmodels: clean.flake8/blackare clean onopenmodels/.