openmodels 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {openmodels-0.2.2 → openmodels-0.2.3}/PKG-INFO +7 -1
  2. {openmodels-0.2.2 → openmodels-0.2.3}/README.md +6 -0
  3. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/__init__.py +2 -2
  4. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/core.py +30 -7
  5. openmodels-0.2.3/openmodels/serializers/base.py +704 -0
  6. openmodels-0.2.3/openmodels/serializers/sklearn/_custom_estimator.py +100 -0
  7. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/serializers/sklearn/sklearn_serializer.py +615 -90
  8. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/test_helpers.py +93 -83
  9. {openmodels-0.2.2 → openmodels-0.2.3}/pyproject.toml +2 -1
  10. openmodels-0.2.2/openmodels/serializers/base.py +0 -329
  11. openmodels-0.2.2/openmodels/serializers/sklearn/_custom_estimator.py +0 -73
  12. {openmodels-0.2.2 → openmodels-0.2.3}/LICENSE +0 -0
  13. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/converters/__init__.py +0 -0
  14. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/converters/json_converter.py +0 -0
  15. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/converters/msgpack_converter.py +0 -0
  16. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/converters/pickle_converter.py +0 -0
  17. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/converters/yaml_converter.py +0 -0
  18. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/exceptions.py +0 -0
  19. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/format_registry.py +0 -0
  20. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/protocols.py +0 -0
  21. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/serializers/__init__.py +0 -0
  22. {openmodels-0.2.2 → openmodels-0.2.3}/openmodels/serializers/sklearn/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openmodels
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Export scikit-learn model files to JSON for sharing or deploying predictive models with peace of mind.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -160,6 +160,12 @@ for the full breakdown by category, and the
160
160
  [serialized format reference](https://gnpd.github.io/openmodels/format.html) for what actually
161
161
  gets written to disk.
162
162
 
163
+ Loaded models are meant for inference. Continuing to train one (`partial_fit`, `warm_start`)
164
+ works for most estimators, but not yet for a few (the MiniBatch estimators, MLP `partial_fit`,
165
+ gradient boosting `warm_start`) - see
166
+ [Resuming Training](https://gnpd.github.io/openmodels/supported_models.html#resuming-training).
167
+ Full support is planned for 0.3.
168
+
163
169
  You can also retrieve the list programmatically using the `SklearnSerializer.all_estimators()` method:
164
170
 
165
171
  ```python
@@ -127,6 +127,12 @@ for the full breakdown by category, and the
127
127
  [serialized format reference](https://gnpd.github.io/openmodels/format.html) for what actually
128
128
  gets written to disk.
129
129
 
130
+ Loaded models are meant for inference. Continuing to train one (`partial_fit`, `warm_start`)
131
+ works for most estimators, but not yet for a few (the MiniBatch estimators, MLP `partial_fit`,
132
+ gradient boosting `warm_start`) - see
133
+ [Resuming Training](https://gnpd.github.io/openmodels/supported_models.html#resuming-training).
134
+ Full support is planned for 0.3.
135
+
130
136
  You can also retrieve the list programmatically using the `SklearnSerializer.all_estimators()` method:
131
137
 
132
138
  ```python
@@ -24,10 +24,10 @@ Example usage:
24
24
  manager = SerializationManager(SklearnSerializer())
25
25
 
26
26
  # Serialize the model to JSON
27
- serialized_model = manager.serialize(model, format="json")
27
+ serialized_model = manager.serialize(model, format_name="json")
28
28
 
29
29
  # Deserialize the model from JSON
30
- deserialized_model = manager.deserialize(serialized_model, format="json")
30
+ deserialized_model = manager.deserialize(serialized_model, format_name="json")
31
31
 
32
32
  # Use the deserialized model
33
33
  predictions = deserialized_model.predict(X_test)
@@ -9,7 +9,7 @@ from typing import Any, Dict, Optional, Union
9
9
  from pathlib import Path
10
10
  from .protocols import ModelSerializer
11
11
  from .format_registry import FormatRegistry
12
- from .exceptions import SerializationError, DeserializationError
12
+ from .exceptions import OpenModelsError, SerializationError, DeserializationError
13
13
 
14
14
 
15
15
  class SerializationManager:
@@ -66,7 +66,8 @@ class SerializationManager:
66
66
  ------
67
67
  SerializationError
68
68
  If the model serializer doesn't return a dictionary or if there's an error during
69
- serialization.
69
+ serialization (e.g. the model isn't an estimator or holds a value the format can't
70
+ encode). The original exception, if any, is kept as ``__cause__``.
70
71
  UnsupportedFormatError
71
72
  If the specified format is not supported.
72
73
 
@@ -80,7 +81,12 @@ class SerializationManager:
80
81
  ... )
81
82
  """
82
83
  converter = FormatRegistry.get_converter(format_name)
83
- serialized_dict = self.model_serializer.serialize(model)
84
+ try:
85
+ serialized_dict = self.model_serializer.serialize(model)
86
+ except OpenModelsError:
87
+ raise
88
+ except Exception as e:
89
+ raise SerializationError(f"Error during serialization: {e}") from e
84
90
  if not isinstance(serialized_dict, dict):
85
91
  raise SerializationError(
86
92
  f"Model serializer must return a dict, got {type(serialized_dict)}"
@@ -90,7 +96,12 @@ class SerializationManager:
90
96
  **metadata,
91
97
  **serialized_dict.get("metadata", {}),
92
98
  }
93
- return converter.serialize_to_format(serialized_dict)
99
+ try:
100
+ return converter.serialize_to_format(serialized_dict)
101
+ except OpenModelsError:
102
+ raise
103
+ except Exception as e:
104
+ raise SerializationError(f"Error during serialization: {e}") from e
94
105
 
95
106
  def deserialize(self, serialized_model: Any, format_name: str = "json") -> Any:
96
107
  """
@@ -112,7 +123,10 @@ class SerializationManager:
112
123
  ------
113
124
  DeserializationError
114
125
  If the format converter doesn't return a dictionary or if there's an error during
115
- deserialization.
126
+ deserialization (e.g. malformed data). The original exception, if any, is kept as
127
+ ``__cause__``.
128
+ UnsupportedEstimatorError
129
+ If the data names an estimator class that is unknown or not supported.
116
130
  UnsupportedFormatError
117
131
  If the specified format_name is not supported.
118
132
 
@@ -125,13 +139,20 @@ class SerializationManager:
125
139
  converter = FormatRegistry.get_converter(format_name)
126
140
  try:
127
141
  deserialized_dict = converter.deserialize_from_format(serialized_model)
142
+ except OpenModelsError:
143
+ raise
128
144
  except Exception as e:
129
- raise DeserializationError(f"Error during deserialization: {e}")
145
+ raise DeserializationError(f"Error during deserialization: {e}") from e
130
146
  if not isinstance(deserialized_dict, dict):
131
147
  raise DeserializationError(
132
148
  f"Format converter must return a dict, got {type(deserialized_dict)}"
133
149
  )
134
- return self.model_serializer.deserialize(deserialized_dict)
150
+ try:
151
+ return self.model_serializer.deserialize(deserialized_dict)
152
+ except OpenModelsError:
153
+ raise
154
+ except Exception as e:
155
+ raise DeserializationError(f"Error during deserialization: {e}") from e
135
156
 
136
157
  def save(
137
158
  self,
@@ -204,6 +225,8 @@ class SerializationManager:
204
225
  ------
205
226
  DeserializationError
206
227
  If deserialization or file I/O fails.
228
+ UnsupportedEstimatorError
229
+ If the file names an estimator class that is unknown or not supported.
207
230
  UnsupportedFormatError
208
231
  If the specified format is not supported.
209
232