Skip to content

Commit 353e7e6

Browse files
authored
Merge pull request #296 from bbopen/fix/0.9-sklearn-estimator-dispatch
fix(codec): dispatch user-defined sklearn estimators to the estimator serializer
2 parents 2acf270 + 9f2a4be commit 353e7e6

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

runtime/tywrap_bridge_core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,12 @@ def serialize(obj, *, force_json_markers, torch_allow_copy=False):
758758
return serialize_torch_tensor(
759759
obj, force_json_markers=force_json_markers, torch_allow_copy=torch_allow_copy
760760
)
761-
elif package == 'sklearn' and 'sklearn.base' in sys.modules:
762-
if is_sklearn_estimator(obj):
763-
return serialize_sklearn_estimator(obj)
761+
elif 'sklearn.base' in sys.modules and is_sklearn_estimator(obj):
762+
# No package gate here, unlike the branches above: subclassing
763+
# BaseEstimator is sklearn's documented extension point, so user-defined
764+
# estimators live outside the 'sklearn' package and must still get the
765+
# estimator serializer (and its param-naming errors).
766+
return serialize_sklearn_estimator(obj)
764767

765768
if isinstance(obj, (type(None), bool, int, float, str, dict, list, tuple)):
766769
return obj

0 commit comments

Comments
 (0)