Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the sklearn serializer into a subdirectory structure and adds support for custom estimators. The main changes include reorganizing the codebase to use openmodels.serializers.sklearn.sklearn_serializer instead of the flat openmodels.serializers.sklearn_serializer, implementing a new custom estimator loading mechanism, and updating the sklearn version compatibility.
- Refactored sklearn serializer into a subdirectory structure (
sklearn/) - Added support for custom estimators via a new
_custom_estimatormodule and constructor parameter - Updated tested sklearn version from "1.7.1" to "1.7.2"
Reviewed Changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| openmodels/serializers/sklearn/sklearn_serializer.py | Added __init__ method with custom_estimators parameter, updated documentation, changed from module-level ALL_ESTIMATORS to instance-level _all_estimators, updated TESTED_VERSIONS and producer_version logic |
| openmodels/serializers/sklearn/_custom_estimator.py | New module implementing custom estimator validation, normalization, and loading logic |
| test/test_custom_estimator.py | New comprehensive test suite for the _custom_estimator module |
| openmodels/serializers/init.py | Updated import path from flat to nested structure |
| openmodels/protocols.py | Added __init__ method to ModelSerializer protocol to allow serializers to accept constructor parameters |
| test/*.py | Updated all import statements to use new nested module structure |
| openmodels/test_helpers.py | Updated import statement to use new nested module structure |
Comments suppressed due to low confidence (2)
openmodels/serializers/sklearn/sklearn_serializer.py:305
- The comment references version '1.7.1' but TESTED_VERSIONS was updated to include '1.7.2'. This docstring should be updated to reflect the current tested versions or remove the specific version reference to avoid future inconsistency.
openmodels/serializers/sklearn/sklearn_serializer.py:225 - This class does not call ModelSerializer.init during initialization. (SklearnSerializer.init may be missing a call to a base class init)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request introduces support for custom scikit-learn-compatible estimators in the
SklearnSerializer, refactors the internal organization of sklearn-related serializers, and adds comprehensive tests for the new custom estimator logic. The changes improve extensibility, maintainability, and test coverage, allowing users to serialize and deserialize third-party or custom estimators alongside built-in ones.Support for custom estimators in serialization:
SklearnSerializervia a newcustom_estimatorsparameter. These are merged into the serializer's internal registry for the instance, enabling seamless serialization/deserialization of external classes.is_valid_estimator,normalize_estimators, andload_custom_estimatorsinopenmodels/serializers/sklearn/_custom_estimator.pyto validate, normalize, and load custom estimators.SklearnSerializerto use the instance-specific registry (self._all_estimators) instead of the global one, ensuring custom estimators are recognized during (de)serialization.Refactoring and reorganization:
sklearn_serializer.pyinto a dedicatedsklearnsubpackage and updated all imports accordingly, improving codebase organization and clarity.Solves #41
SklearnSerializerto clarify the new extensibility features and provide developer guidance for third-party package maintainers.Testing improvements:
test/test_custom_estimator.pycovering all branches and edge cases of the custom estimator loading logic, including validation, normalization, error handling, and conflict resolution.Other updates:
SklearnSerializer.Protocol and interface changes:
ModelSerializerprotocol to allow arbitrary constructor arguments, supporting the new extensibility pattern.