mlrun 1.7.1rc10__py3-none-any.whl → 1.8.0rc11__py3-none-any.whl

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.

Potentially problematic release.


This version of mlrun might be problematic. Click here for more details.

Files changed (259) hide show
  1. mlrun/__init__.py +23 -21
  2. mlrun/__main__.py +3 -3
  3. mlrun/alerts/alert.py +148 -14
  4. mlrun/artifacts/__init__.py +2 -3
  5. mlrun/artifacts/base.py +55 -12
  6. mlrun/artifacts/dataset.py +16 -16
  7. mlrun/artifacts/document.py +378 -0
  8. mlrun/artifacts/manager.py +26 -17
  9. mlrun/artifacts/model.py +66 -53
  10. mlrun/common/constants.py +8 -0
  11. mlrun/common/formatters/__init__.py +1 -0
  12. mlrun/common/formatters/feature_set.py +1 -0
  13. mlrun/common/formatters/function.py +1 -0
  14. mlrun/{model_monitoring/db/stores/base/__init__.py → common/formatters/model_endpoint.py} +16 -1
  15. mlrun/common/formatters/pipeline.py +1 -2
  16. mlrun/common/formatters/project.py +9 -0
  17. mlrun/common/model_monitoring/__init__.py +0 -5
  18. mlrun/common/model_monitoring/helpers.py +1 -29
  19. mlrun/common/runtimes/constants.py +1 -2
  20. mlrun/common/schemas/__init__.py +6 -2
  21. mlrun/common/schemas/alert.py +111 -19
  22. mlrun/common/schemas/api_gateway.py +3 -3
  23. mlrun/common/schemas/artifact.py +11 -7
  24. mlrun/common/schemas/auth.py +6 -4
  25. mlrun/common/schemas/background_task.py +7 -7
  26. mlrun/common/schemas/client_spec.py +2 -3
  27. mlrun/common/schemas/clusterization_spec.py +2 -2
  28. mlrun/common/schemas/common.py +53 -3
  29. mlrun/common/schemas/constants.py +15 -0
  30. mlrun/common/schemas/datastore_profile.py +1 -1
  31. mlrun/common/schemas/feature_store.py +9 -9
  32. mlrun/common/schemas/frontend_spec.py +4 -4
  33. mlrun/common/schemas/function.py +10 -10
  34. mlrun/common/schemas/hub.py +1 -1
  35. mlrun/common/schemas/k8s.py +3 -3
  36. mlrun/common/schemas/memory_reports.py +3 -3
  37. mlrun/common/schemas/model_monitoring/__init__.py +2 -1
  38. mlrun/common/schemas/model_monitoring/constants.py +67 -14
  39. mlrun/common/schemas/model_monitoring/grafana.py +1 -1
  40. mlrun/common/schemas/model_monitoring/model_endpoints.py +92 -147
  41. mlrun/common/schemas/notification.py +24 -3
  42. mlrun/common/schemas/object.py +1 -1
  43. mlrun/common/schemas/pagination.py +4 -4
  44. mlrun/common/schemas/partition.py +137 -0
  45. mlrun/common/schemas/pipeline.py +2 -2
  46. mlrun/common/schemas/project.py +25 -17
  47. mlrun/common/schemas/runs.py +2 -2
  48. mlrun/common/schemas/runtime_resource.py +5 -5
  49. mlrun/common/schemas/schedule.py +1 -1
  50. mlrun/common/schemas/secret.py +1 -1
  51. mlrun/common/schemas/tag.py +3 -3
  52. mlrun/common/schemas/workflow.py +5 -5
  53. mlrun/config.py +68 -10
  54. mlrun/data_types/__init__.py +0 -2
  55. mlrun/data_types/data_types.py +1 -0
  56. mlrun/data_types/infer.py +3 -1
  57. mlrun/data_types/spark.py +5 -3
  58. mlrun/data_types/to_pandas.py +11 -2
  59. mlrun/datastore/__init__.py +2 -2
  60. mlrun/datastore/alibaba_oss.py +4 -1
  61. mlrun/datastore/azure_blob.py +4 -1
  62. mlrun/datastore/base.py +12 -4
  63. mlrun/datastore/datastore.py +9 -3
  64. mlrun/datastore/datastore_profile.py +79 -20
  65. mlrun/datastore/dbfs_store.py +4 -1
  66. mlrun/datastore/filestore.py +4 -1
  67. mlrun/datastore/google_cloud_storage.py +4 -1
  68. mlrun/datastore/hdfs.py +4 -1
  69. mlrun/datastore/inmem.py +4 -1
  70. mlrun/datastore/redis.py +4 -1
  71. mlrun/datastore/s3.py +4 -1
  72. mlrun/datastore/sources.py +52 -51
  73. mlrun/datastore/store_resources.py +7 -4
  74. mlrun/datastore/targets.py +23 -22
  75. mlrun/datastore/utils.py +2 -2
  76. mlrun/datastore/v3io.py +4 -1
  77. mlrun/datastore/vectorstore.py +229 -0
  78. mlrun/datastore/wasbfs/fs.py +13 -12
  79. mlrun/db/base.py +213 -83
  80. mlrun/db/factory.py +0 -3
  81. mlrun/db/httpdb.py +1265 -387
  82. mlrun/db/nopdb.py +205 -74
  83. mlrun/errors.py +2 -2
  84. mlrun/execution.py +136 -50
  85. mlrun/feature_store/__init__.py +0 -2
  86. mlrun/feature_store/api.py +41 -40
  87. mlrun/feature_store/common.py +9 -9
  88. mlrun/feature_store/feature_set.py +20 -18
  89. mlrun/feature_store/feature_vector.py +27 -24
  90. mlrun/feature_store/retrieval/base.py +14 -9
  91. mlrun/feature_store/retrieval/job.py +2 -1
  92. mlrun/feature_store/steps.py +2 -2
  93. mlrun/features.py +30 -13
  94. mlrun/frameworks/__init__.py +1 -2
  95. mlrun/frameworks/_common/__init__.py +1 -2
  96. mlrun/frameworks/_common/artifacts_library.py +2 -2
  97. mlrun/frameworks/_common/mlrun_interface.py +10 -6
  98. mlrun/frameworks/_common/model_handler.py +29 -27
  99. mlrun/frameworks/_common/producer.py +3 -1
  100. mlrun/frameworks/_dl_common/__init__.py +1 -2
  101. mlrun/frameworks/_dl_common/loggers/__init__.py +1 -2
  102. mlrun/frameworks/_dl_common/loggers/mlrun_logger.py +4 -4
  103. mlrun/frameworks/_dl_common/loggers/tensorboard_logger.py +3 -3
  104. mlrun/frameworks/_ml_common/__init__.py +1 -2
  105. mlrun/frameworks/_ml_common/loggers/__init__.py +1 -2
  106. mlrun/frameworks/_ml_common/model_handler.py +21 -21
  107. mlrun/frameworks/_ml_common/plans/__init__.py +1 -2
  108. mlrun/frameworks/_ml_common/plans/confusion_matrix_plan.py +3 -1
  109. mlrun/frameworks/_ml_common/plans/dataset_plan.py +3 -3
  110. mlrun/frameworks/_ml_common/plans/roc_curve_plan.py +4 -4
  111. mlrun/frameworks/auto_mlrun/__init__.py +1 -2
  112. mlrun/frameworks/auto_mlrun/auto_mlrun.py +22 -15
  113. mlrun/frameworks/huggingface/__init__.py +1 -2
  114. mlrun/frameworks/huggingface/model_server.py +9 -9
  115. mlrun/frameworks/lgbm/__init__.py +47 -44
  116. mlrun/frameworks/lgbm/callbacks/__init__.py +1 -2
  117. mlrun/frameworks/lgbm/callbacks/logging_callback.py +4 -2
  118. mlrun/frameworks/lgbm/callbacks/mlrun_logging_callback.py +4 -2
  119. mlrun/frameworks/lgbm/mlrun_interfaces/__init__.py +1 -2
  120. mlrun/frameworks/lgbm/mlrun_interfaces/mlrun_interface.py +5 -5
  121. mlrun/frameworks/lgbm/model_handler.py +15 -11
  122. mlrun/frameworks/lgbm/model_server.py +11 -7
  123. mlrun/frameworks/lgbm/utils.py +2 -2
  124. mlrun/frameworks/onnx/__init__.py +1 -2
  125. mlrun/frameworks/onnx/dataset.py +3 -3
  126. mlrun/frameworks/onnx/mlrun_interface.py +2 -2
  127. mlrun/frameworks/onnx/model_handler.py +7 -5
  128. mlrun/frameworks/onnx/model_server.py +8 -6
  129. mlrun/frameworks/parallel_coordinates.py +11 -11
  130. mlrun/frameworks/pytorch/__init__.py +22 -23
  131. mlrun/frameworks/pytorch/callbacks/__init__.py +1 -2
  132. mlrun/frameworks/pytorch/callbacks/callback.py +2 -1
  133. mlrun/frameworks/pytorch/callbacks/logging_callback.py +15 -8
  134. mlrun/frameworks/pytorch/callbacks/mlrun_logging_callback.py +19 -12
  135. mlrun/frameworks/pytorch/callbacks/tensorboard_logging_callback.py +22 -15
  136. mlrun/frameworks/pytorch/callbacks_handler.py +36 -30
  137. mlrun/frameworks/pytorch/mlrun_interface.py +17 -17
  138. mlrun/frameworks/pytorch/model_handler.py +21 -17
  139. mlrun/frameworks/pytorch/model_server.py +13 -9
  140. mlrun/frameworks/sklearn/__init__.py +19 -18
  141. mlrun/frameworks/sklearn/estimator.py +2 -2
  142. mlrun/frameworks/sklearn/metric.py +3 -3
  143. mlrun/frameworks/sklearn/metrics_library.py +8 -6
  144. mlrun/frameworks/sklearn/mlrun_interface.py +3 -2
  145. mlrun/frameworks/sklearn/model_handler.py +4 -3
  146. mlrun/frameworks/tf_keras/__init__.py +11 -12
  147. mlrun/frameworks/tf_keras/callbacks/__init__.py +1 -2
  148. mlrun/frameworks/tf_keras/callbacks/logging_callback.py +17 -14
  149. mlrun/frameworks/tf_keras/callbacks/mlrun_logging_callback.py +15 -12
  150. mlrun/frameworks/tf_keras/callbacks/tensorboard_logging_callback.py +21 -18
  151. mlrun/frameworks/tf_keras/model_handler.py +17 -13
  152. mlrun/frameworks/tf_keras/model_server.py +12 -8
  153. mlrun/frameworks/xgboost/__init__.py +19 -18
  154. mlrun/frameworks/xgboost/model_handler.py +13 -9
  155. mlrun/launcher/base.py +3 -4
  156. mlrun/launcher/local.py +1 -1
  157. mlrun/launcher/remote.py +1 -1
  158. mlrun/lists.py +4 -3
  159. mlrun/model.py +117 -46
  160. mlrun/model_monitoring/__init__.py +4 -4
  161. mlrun/model_monitoring/api.py +72 -59
  162. mlrun/model_monitoring/applications/_application_steps.py +17 -17
  163. mlrun/model_monitoring/applications/base.py +165 -6
  164. mlrun/model_monitoring/applications/context.py +88 -37
  165. mlrun/model_monitoring/applications/evidently_base.py +0 -1
  166. mlrun/model_monitoring/applications/histogram_data_drift.py +43 -21
  167. mlrun/model_monitoring/applications/results.py +55 -3
  168. mlrun/model_monitoring/controller.py +207 -239
  169. mlrun/model_monitoring/db/__init__.py +0 -2
  170. mlrun/model_monitoring/db/_schedules.py +156 -0
  171. mlrun/model_monitoring/db/_stats.py +189 -0
  172. mlrun/model_monitoring/db/tsdb/base.py +78 -25
  173. mlrun/model_monitoring/db/tsdb/tdengine/schemas.py +61 -6
  174. mlrun/model_monitoring/db/tsdb/tdengine/stream_graph_steps.py +33 -0
  175. mlrun/model_monitoring/db/tsdb/tdengine/tdengine_connector.py +255 -29
  176. mlrun/model_monitoring/db/tsdb/v3io/stream_graph_steps.py +1 -0
  177. mlrun/model_monitoring/db/tsdb/v3io/v3io_connector.py +78 -17
  178. mlrun/model_monitoring/helpers.py +151 -49
  179. mlrun/model_monitoring/stream_processing.py +99 -283
  180. mlrun/model_monitoring/tracking_policy.py +10 -3
  181. mlrun/model_monitoring/writer.py +48 -36
  182. mlrun/package/__init__.py +3 -6
  183. mlrun/package/context_handler.py +1 -1
  184. mlrun/package/packager.py +12 -9
  185. mlrun/package/packagers/__init__.py +0 -2
  186. mlrun/package/packagers/default_packager.py +14 -11
  187. mlrun/package/packagers/numpy_packagers.py +16 -7
  188. mlrun/package/packagers/pandas_packagers.py +18 -18
  189. mlrun/package/packagers/python_standard_library_packagers.py +25 -11
  190. mlrun/package/packagers_manager.py +31 -14
  191. mlrun/package/utils/__init__.py +0 -3
  192. mlrun/package/utils/_pickler.py +6 -6
  193. mlrun/platforms/__init__.py +47 -16
  194. mlrun/platforms/iguazio.py +4 -1
  195. mlrun/projects/operations.py +27 -27
  196. mlrun/projects/pipelines.py +71 -36
  197. mlrun/projects/project.py +890 -220
  198. mlrun/run.py +53 -10
  199. mlrun/runtimes/__init__.py +1 -3
  200. mlrun/runtimes/base.py +15 -11
  201. mlrun/runtimes/daskjob.py +9 -9
  202. mlrun/runtimes/generators.py +2 -1
  203. mlrun/runtimes/kubejob.py +4 -5
  204. mlrun/runtimes/mounts.py +572 -0
  205. mlrun/runtimes/mpijob/__init__.py +0 -2
  206. mlrun/runtimes/mpijob/abstract.py +7 -6
  207. mlrun/runtimes/nuclio/api_gateway.py +7 -7
  208. mlrun/runtimes/nuclio/application/application.py +11 -11
  209. mlrun/runtimes/nuclio/function.py +19 -17
  210. mlrun/runtimes/nuclio/serving.py +18 -13
  211. mlrun/runtimes/pod.py +154 -45
  212. mlrun/runtimes/remotesparkjob.py +3 -2
  213. mlrun/runtimes/sparkjob/__init__.py +0 -2
  214. mlrun/runtimes/sparkjob/spark3job.py +21 -11
  215. mlrun/runtimes/utils.py +6 -5
  216. mlrun/serving/merger.py +6 -4
  217. mlrun/serving/remote.py +18 -17
  218. mlrun/serving/routers.py +185 -172
  219. mlrun/serving/server.py +7 -1
  220. mlrun/serving/states.py +97 -78
  221. mlrun/serving/utils.py +13 -2
  222. mlrun/serving/v1_serving.py +3 -2
  223. mlrun/serving/v2_serving.py +105 -72
  224. mlrun/track/__init__.py +1 -1
  225. mlrun/track/tracker.py +2 -2
  226. mlrun/track/trackers/mlflow_tracker.py +6 -5
  227. mlrun/utils/async_http.py +1 -1
  228. mlrun/utils/clones.py +1 -1
  229. mlrun/utils/helpers.py +63 -19
  230. mlrun/utils/logger.py +106 -4
  231. mlrun/utils/notifications/notification/__init__.py +22 -19
  232. mlrun/utils/notifications/notification/base.py +33 -14
  233. mlrun/utils/notifications/notification/console.py +6 -6
  234. mlrun/utils/notifications/notification/git.py +11 -11
  235. mlrun/utils/notifications/notification/ipython.py +10 -9
  236. mlrun/utils/notifications/notification/mail.py +176 -0
  237. mlrun/utils/notifications/notification/slack.py +6 -6
  238. mlrun/utils/notifications/notification/webhook.py +6 -6
  239. mlrun/utils/notifications/notification_pusher.py +86 -44
  240. mlrun/utils/regex.py +11 -2
  241. mlrun/utils/version/version.json +2 -2
  242. {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/METADATA +29 -24
  243. mlrun-1.8.0rc11.dist-info/RECORD +347 -0
  244. mlrun/model_monitoring/db/stores/__init__.py +0 -136
  245. mlrun/model_monitoring/db/stores/base/store.py +0 -213
  246. mlrun/model_monitoring/db/stores/sqldb/__init__.py +0 -13
  247. mlrun/model_monitoring/db/stores/sqldb/models/__init__.py +0 -71
  248. mlrun/model_monitoring/db/stores/sqldb/models/base.py +0 -190
  249. mlrun/model_monitoring/db/stores/sqldb/models/mysql.py +0 -103
  250. mlrun/model_monitoring/db/stores/sqldb/models/sqlite.py +0 -40
  251. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +0 -659
  252. mlrun/model_monitoring/db/stores/v3io_kv/__init__.py +0 -13
  253. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +0 -726
  254. mlrun/model_monitoring/model_endpoint.py +0 -118
  255. mlrun-1.7.1rc10.dist-info/RECORD +0 -351
  256. {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/LICENSE +0 -0
  257. {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/WHEEL +0 -0
  258. {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/entry_points.txt +0 -0
  259. {mlrun-1.7.1rc10.dist-info → mlrun-1.8.0rc11.dist-info}/top_level.txt +0 -0
@@ -13,23 +13,29 @@
13
13
  # limitations under the License.
14
14
 
15
15
  import json
16
- from typing import Any, Callable, NewType
16
+ from datetime import datetime, timezone
17
+ from typing import Any, Callable, NewType, Optional
17
18
 
18
19
  import mlrun.common.model_monitoring
19
20
  import mlrun.common.schemas
20
21
  import mlrun.common.schemas.alert as alert_objects
21
22
  import mlrun.model_monitoring
22
23
  from mlrun.common.schemas.model_monitoring.constants import (
23
- EventFieldType,
24
24
  HistogramDataDriftApplicationConstants,
25
25
  MetricData,
26
26
  ResultData,
27
27
  ResultKindApp,
28
28
  ResultStatusApp,
29
+ StatsData,
30
+ StatsKind,
29
31
  WriterEvent,
30
32
  WriterEventKind,
31
33
  )
32
34
  from mlrun.common.schemas.notification import NotificationKind, NotificationSeverity
35
+ from mlrun.model_monitoring.db._stats import (
36
+ ModelMonitoringCurrentStatsFile,
37
+ ModelMonitoringDriftMeasuresFile,
38
+ )
33
39
  from mlrun.model_monitoring.helpers import get_result_instance_fqn
34
40
  from mlrun.serving.utils import StepToDict
35
41
  from mlrun.utils import logger
@@ -105,7 +111,7 @@ class ModelMonitoringWriter(StepToDict):
105
111
  def __init__(
106
112
  self,
107
113
  project: str,
108
- secret_provider: Callable = None,
114
+ secret_provider: Optional[Callable] = None,
109
115
  ) -> None:
110
116
  self.project = project
111
117
  self.name = project # required for the deployment process
@@ -114,9 +120,6 @@ class ModelMonitoringWriter(StepToDict):
114
120
  notification_types=[NotificationKind.slack]
115
121
  )
116
122
 
117
- self._app_result_store = mlrun.model_monitoring.get_store_object(
118
- project=self.project, secret_provider=secret_provider
119
- )
120
123
  self._tsdb_connector = mlrun.model_monitoring.get_tsdb_connector(
121
124
  project=self.project, secret_provider=secret_provider
122
125
  )
@@ -190,6 +193,8 @@ class ModelMonitoringWriter(StepToDict):
190
193
  expected_keys.extend(MetricData.list())
191
194
  elif kind == WriterEventKind.RESULT:
192
195
  expected_keys.extend(ResultData.list())
196
+ elif kind == WriterEventKind.STATS:
197
+ expected_keys.extend(StatsData.list())
193
198
  else:
194
199
  raise _WriterEventValueError(
195
200
  f"Unknown event kind: {kind}, expected one of: {WriterEventKind.list()}"
@@ -198,16 +203,50 @@ class ModelMonitoringWriter(StepToDict):
198
203
  if missing_keys:
199
204
  raise _WriterEventValueError(
200
205
  f"The received event misses some keys compared to the expected "
201
- f"monitoring application event schema: {missing_keys}"
206
+ f"monitoring application event schema: {missing_keys} for event kind {kind}"
202
207
  )
203
208
 
204
209
  return result_event, kind
205
210
 
211
+ def write_stats(self, event: _AppResultEvent) -> None:
212
+ """
213
+ Write to file the application stats event
214
+ :param event: application stats event
215
+ """
216
+ endpoint_id = event[WriterEvent.ENDPOINT_ID]
217
+ logger.debug(
218
+ "Updating the model endpoint with stats",
219
+ endpoint_id=endpoint_id,
220
+ )
221
+ stat_kind = event.get(StatsData.STATS_NAME)
222
+ data, timestamp_str = event.get(StatsData.STATS), event.get(StatsData.TIMESTAMP)
223
+ timestamp = datetime.fromisoformat(timestamp_str).astimezone(tz=timezone.utc)
224
+ if stat_kind == StatsKind.CURRENT_STATS.value:
225
+ ModelMonitoringCurrentStatsFile(self.project, endpoint_id).write(
226
+ data, timestamp
227
+ )
228
+ elif stat_kind == StatsKind.DRIFT_MEASURES.value:
229
+ ModelMonitoringDriftMeasuresFile(self.project, endpoint_id).write(
230
+ data, timestamp
231
+ )
232
+ logger.info(
233
+ "Updating the model endpoint statistics",
234
+ endpoint_id=endpoint_id,
235
+ stats_kind=stat_kind,
236
+ )
237
+
206
238
  def do(self, event: _RawEvent) -> None:
207
239
  event, kind = self._reconstruct_event(event)
208
240
  logger.info("Starting to write event", event=event)
241
+ if (
242
+ kind == WriterEventKind.STATS
243
+ and event[WriterEvent.APPLICATION_NAME]
244
+ == HistogramDataDriftApplicationConstants.NAME
245
+ ):
246
+ self.write_stats(event)
247
+ logger.info("Model monitoring writer finished handling event")
248
+ return
209
249
  self._tsdb_connector.write_application_event(event=event.copy(), kind=kind)
210
- self._app_result_store.write_application_event(event=event.copy(), kind=kind)
211
250
 
212
251
  logger.info("Completed event DB writes")
213
252
 
@@ -223,14 +262,9 @@ class ModelMonitoringWriter(StepToDict):
223
262
  == ResultStatusApp.potential_detection.value
224
263
  )
225
264
  ):
226
- endpoint_id = event[WriterEvent.ENDPOINT_ID]
227
- endpoint_record = self._endpoints_records.setdefault(
228
- endpoint_id,
229
- self._app_result_store.get_model_endpoint(endpoint_id=endpoint_id),
230
- )
231
265
  event_value = {
232
266
  "app_name": event[WriterEvent.APPLICATION_NAME],
233
- "model": endpoint_record.get(EventFieldType.MODEL),
267
+ "model": event[WriterEvent.ENDPOINT_NAME],
234
268
  "model_endpoint_id": event[WriterEvent.ENDPOINT_ID],
235
269
  "result_name": event[ResultData.RESULT_NAME],
236
270
  "result_value": event[ResultData.RESULT_VALUE],
@@ -247,26 +281,4 @@ class ModelMonitoringWriter(StepToDict):
247
281
  result_kind=event[ResultData.RESULT_KIND],
248
282
  )
249
283
 
250
- if (
251
- kind == WriterEventKind.RESULT
252
- and event[WriterEvent.APPLICATION_NAME]
253
- == HistogramDataDriftApplicationConstants.NAME
254
- and event[ResultData.RESULT_NAME]
255
- == HistogramDataDriftApplicationConstants.GENERAL_RESULT_NAME
256
- ):
257
- endpoint_id = event[WriterEvent.ENDPOINT_ID]
258
- logger.info(
259
- "Updating the model endpoint with metadata specific to the histogram "
260
- "data drift app",
261
- endpoint_id=endpoint_id,
262
- )
263
- attributes = json.loads(event[ResultData.RESULT_EXTRA_DATA])
264
- attributes[EventFieldType.DRIFT_STATUS] = str(
265
- attributes[EventFieldType.DRIFT_STATUS]
266
- )
267
- self._app_result_store.update_model_endpoint(
268
- endpoint_id=endpoint_id,
269
- attributes=attributes,
270
- )
271
-
272
284
  logger.info("Model monitoring writer finished handling event")
mlrun/package/__init__.py CHANGED
@@ -11,14 +11,11 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- #
15
-
16
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
17
14
 
18
15
  import functools
19
16
  import inspect
20
17
  from collections import OrderedDict
21
- from typing import Callable, Union
18
+ from typing import Callable, Optional, Union
22
19
 
23
20
  from ..config import config
24
21
  from .context_handler import ContextHandler
@@ -40,8 +37,8 @@ from .utils import (
40
37
 
41
38
 
42
39
  def handler(
43
- labels: dict[str, str] = None,
44
- outputs: list[Union[str, dict[str, str]]] = None,
40
+ labels: Optional[dict[str, str]] = None,
41
+ outputs: Optional[list[Union[str, dict[str, str]]]] = None,
45
42
  inputs: Union[bool, dict[str, Union[str, type]]] = True,
46
43
  ):
47
44
  """
@@ -216,7 +216,7 @@ class ContextHandler:
216
216
  )
217
217
  # Link packages:
218
218
  self._packagers_manager.link_packages(
219
- additional_artifacts=self._context.artifacts,
219
+ additional_artifact_uris=self._context.artifact_uris,
220
220
  additional_results=self._context.results,
221
221
  )
222
222
  # Log the packed results and artifacts:
mlrun/package/packager.py CHANGED
@@ -14,7 +14,7 @@
14
14
  #
15
15
  from abc import ABC, abstractmethod
16
16
  from pathlib import Path
17
- from typing import Any, Union
17
+ from typing import Any, Optional, Union
18
18
 
19
19
  from mlrun.artifacts import Artifact
20
20
  from mlrun.datastore import DataItem
@@ -144,9 +144,9 @@ class Packager(ABC):
144
144
  def pack(
145
145
  self,
146
146
  obj: Any,
147
- key: str = None,
148
- artifact_type: str = None,
149
- configurations: dict = None,
147
+ key: Optional[str] = None,
148
+ artifact_type: Optional[str] = None,
149
+ configurations: Optional[dict] = None,
150
150
  ) -> Union[tuple[Artifact, dict], dict]:
151
151
  """
152
152
  Pack an object as the given artifact type using the provided configurations.
@@ -165,8 +165,8 @@ class Packager(ABC):
165
165
  def unpack(
166
166
  self,
167
167
  data_item: DataItem,
168
- artifact_type: str = None,
169
- instructions: dict = None,
168
+ artifact_type: Optional[str] = None,
169
+ instructions: Optional[dict] = None,
170
170
  ) -> Any:
171
171
  """
172
172
  Unpack the data item's artifact by the provided type using the given instructions.
@@ -180,7 +180,10 @@ class Packager(ABC):
180
180
  pass
181
181
 
182
182
  def is_packable(
183
- self, obj: Any, artifact_type: str = None, configurations: dict = None
183
+ self,
184
+ obj: Any,
185
+ artifact_type: Optional[str] = None,
186
+ configurations: Optional[dict] = None,
184
187
  ) -> bool:
185
188
  """
186
189
  Check if this packager can pack an object of the provided type as the provided artifact type.
@@ -212,7 +215,7 @@ class Packager(ABC):
212
215
  return True
213
216
 
214
217
  def is_unpackable(
215
- self, data_item: DataItem, type_hint: type, artifact_type: str = None
218
+ self, data_item: DataItem, type_hint: type, artifact_type: Optional[str] = None
216
219
  ) -> bool:
217
220
  """
218
221
  Check if this packager can unpack an input according to the user-given type hint and the provided artifact type.
@@ -315,7 +318,7 @@ class Packager(ABC):
315
318
  )
316
319
 
317
320
  def get_data_item_local_path(
318
- self, data_item: DataItem, add_to_future_clearing_path: bool = None
321
+ self, data_item: DataItem, add_to_future_clearing_path: Optional[bool] = None
319
322
  ) -> str:
320
323
  """
321
324
  Get the local path to the item handled by the data item provided. The local path can be the same as the data
@@ -11,8 +11,6 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
- #
15
14
 
16
- # flake8: noqa - this is until we take care of the F401 violations with respect to __all__ & sphinx
17
15
  from .default_packager import DefaultPackager
18
16
  from .numpy_packagers import NumPySupportedFormat
@@ -15,7 +15,7 @@
15
15
  import inspect
16
16
  from abc import ABCMeta
17
17
  from types import MethodType
18
- from typing import Any, Union
18
+ from typing import Any, Optional, Union
19
19
 
20
20
  import docstring_parser
21
21
 
@@ -323,9 +323,9 @@ class DefaultPackager(Packager, metaclass=_DefaultPackagerMeta):
323
323
  def pack(
324
324
  self,
325
325
  obj: Any,
326
- key: str = None,
327
- artifact_type: str = None,
328
- configurations: dict = None,
326
+ key: Optional[str] = None,
327
+ artifact_type: Optional[str] = None,
328
+ configurations: Optional[dict] = None,
329
329
  ) -> Union[tuple[Artifact, dict], dict]:
330
330
  """
331
331
  Pack an object as the given artifact type using the provided configurations.
@@ -361,8 +361,8 @@ class DefaultPackager(Packager, metaclass=_DefaultPackagerMeta):
361
361
  def unpack(
362
362
  self,
363
363
  data_item: DataItem,
364
- artifact_type: str = None,
365
- instructions: dict = None,
364
+ artifact_type: Optional[str] = None,
365
+ instructions: Optional[dict] = None,
366
366
  ) -> Any:
367
367
  """
368
368
  Unpack the data item's artifact by the provided type using the given instructions.
@@ -399,7 +399,10 @@ class DefaultPackager(Packager, metaclass=_DefaultPackagerMeta):
399
399
  return unpack_method(data_item, **instructions)
400
400
 
401
401
  def is_packable(
402
- self, obj: Any, artifact_type: str = None, configurations: dict = None
402
+ self,
403
+ obj: Any,
404
+ artifact_type: Optional[str] = None,
405
+ configurations: Optional[dict] = None,
403
406
  ) -> bool:
404
407
  """
405
408
  Check if this packager can pack an object of the provided type as the provided artifact type.
@@ -480,10 +483,10 @@ class DefaultPackager(Packager, metaclass=_DefaultPackagerMeta):
480
483
  self,
481
484
  data_item: DataItem,
482
485
  pickle_module_name: str = DEFAULT_PICKLE_MODULE,
483
- object_module_name: str = None,
484
- python_version: str = None,
485
- pickle_module_version: str = None,
486
- object_module_version: str = None,
486
+ object_module_name: Optional[str] = None,
487
+ python_version: Optional[str] = None,
488
+ pickle_module_version: Optional[str] = None,
489
+ object_module_version: Optional[str] = None,
487
490
  ) -> Any:
488
491
  """
489
492
  Unpack the data item's object, unpickle it using the instructions, and return.
@@ -16,7 +16,7 @@ import os
16
16
  import pathlib
17
17
  import tempfile
18
18
  from abc import ABC, abstractmethod
19
- from typing import Any, Union
19
+ from typing import Any, Optional, Union
20
20
 
21
21
  import numpy as np
22
22
  import pandas as pd
@@ -371,7 +371,10 @@ class NumPyNDArrayPackager(DefaultPackager):
371
371
  return artifact, {}
372
372
 
373
373
  def unpack_file(
374
- self, data_item: DataItem, file_format: str = None, allow_pickle: bool = False
374
+ self,
375
+ data_item: DataItem,
376
+ file_format: Optional[str] = None,
377
+ allow_pickle: bool = False,
375
378
  ) -> np.ndarray:
376
379
  """
377
380
  Unpack a numppy array from file.
@@ -474,7 +477,7 @@ class _NumPyNDArrayCollectionPackager(DefaultPackager):
474
477
  def unpack_file(
475
478
  self,
476
479
  data_item: DataItem,
477
- file_format: str = None,
480
+ file_format: Optional[str] = None,
478
481
  allow_pickle: bool = False,
479
482
  ) -> dict[str, np.ndarray]:
480
483
  """
@@ -548,7 +551,10 @@ class NumPyNDArrayDictPackager(_NumPyNDArrayCollectionPackager):
548
551
  PACKABLE_OBJECT_TYPE = dict[str, np.ndarray]
549
552
 
550
553
  def is_packable(
551
- self, obj: Any, artifact_type: str = None, configurations: dict = None
554
+ self,
555
+ obj: Any,
556
+ artifact_type: Optional[str] = None,
557
+ configurations: Optional[dict] = None,
552
558
  ) -> bool:
553
559
  """
554
560
  Check if the object provided is a dictionary of numpy arrays.
@@ -602,7 +608,7 @@ class NumPyNDArrayDictPackager(_NumPyNDArrayCollectionPackager):
602
608
  def unpack_file(
603
609
  self,
604
610
  data_item: DataItem,
605
- file_format: str = None,
611
+ file_format: Optional[str] = None,
606
612
  allow_pickle: bool = False,
607
613
  ) -> dict[str, np.ndarray]:
608
614
  """
@@ -633,7 +639,10 @@ class NumPyNDArrayListPackager(_NumPyNDArrayCollectionPackager):
633
639
  PACKABLE_OBJECT_TYPE = list[np.ndarray]
634
640
 
635
641
  def is_packable(
636
- self, obj: Any, artifact_type: str = None, configurations: dict = None
642
+ self,
643
+ obj: Any,
644
+ artifact_type: Optional[str] = None,
645
+ configurations: Optional[dict] = None,
637
646
  ) -> bool:
638
647
  """
639
648
  Check if the object provided is a list of numpy arrays.
@@ -679,7 +688,7 @@ class NumPyNDArrayListPackager(_NumPyNDArrayCollectionPackager):
679
688
  def unpack_file(
680
689
  self,
681
690
  data_item: DataItem,
682
- file_format: str = None,
691
+ file_format: Optional[str] = None,
683
692
  allow_pickle: bool = False,
684
693
  ) -> list[np.ndarray]:
685
694
  """
@@ -17,7 +17,7 @@ import os
17
17
  import pathlib
18
18
  import tempfile
19
19
  from abc import ABC, abstractmethod
20
- from typing import Any, Union
20
+ from typing import Any, Optional, Union
21
21
 
22
22
  import pandas as pd
23
23
 
@@ -56,7 +56,7 @@ class _Formatter(ABC):
56
56
  @classmethod
57
57
  @abstractmethod
58
58
  def read(
59
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
59
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
60
60
  ) -> pd.DataFrame:
61
61
  """
62
62
  Read the dataframe from the given file path.
@@ -173,7 +173,7 @@ class _ParquetFormatter(_Formatter):
173
173
 
174
174
  @classmethod
175
175
  def read(
176
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
176
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
177
177
  ) -> pd.DataFrame:
178
178
  """
179
179
  Read the dataframe from the given parquet file path.
@@ -221,7 +221,7 @@ class _CSVFormatter(_Formatter):
221
221
 
222
222
  @classmethod
223
223
  def read(
224
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
224
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
225
225
  ) -> pd.DataFrame:
226
226
  """
227
227
  Read the dataframe from the given csv file path.
@@ -275,7 +275,7 @@ class _H5Formatter(_Formatter):
275
275
 
276
276
  @classmethod
277
277
  def read(
278
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
278
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
279
279
  ) -> pd.DataFrame:
280
280
  """
281
281
  Read the dataframe from the given h5 file path.
@@ -332,7 +332,7 @@ class _XMLFormatter(_Formatter):
332
332
 
333
333
  @classmethod
334
334
  def read(
335
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
335
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
336
336
  ) -> pd.DataFrame:
337
337
  """
338
338
  Read the dataframe from the given xml file path.
@@ -391,7 +391,7 @@ class _XLSXFormatter(_Formatter):
391
391
 
392
392
  @classmethod
393
393
  def read(
394
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
394
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
395
395
  ) -> pd.DataFrame:
396
396
  """
397
397
  Read the dataframe from the given xlsx file path.
@@ -449,7 +449,7 @@ class _HTMLFormatter(_Formatter):
449
449
 
450
450
  @classmethod
451
451
  def read(
452
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
452
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
453
453
  ) -> pd.DataFrame:
454
454
  """
455
455
  Read dataframes from the given html file path.
@@ -510,7 +510,7 @@ class _JSONFormatter(_Formatter):
510
510
 
511
511
  @classmethod
512
512
  def read(
513
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
513
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
514
514
  ) -> pd.DataFrame:
515
515
  """
516
516
  Read dataframes from the given json file path.
@@ -565,7 +565,7 @@ class _FeatherFormatter(_Formatter):
565
565
 
566
566
  @classmethod
567
567
  def read(
568
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
568
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
569
569
  ) -> pd.DataFrame:
570
570
  """
571
571
  Read dataframes from the given feather file path.
@@ -620,7 +620,7 @@ class _ORCFormatter(_Formatter):
620
620
 
621
621
  @classmethod
622
622
  def read(
623
- cls, file_path: str, unflatten_kwargs: dict = None, **read_kwargs
623
+ cls, file_path: str, unflatten_kwargs: Optional[dict] = None, **read_kwargs
624
624
  ) -> pd.DataFrame:
625
625
  """
626
626
  Read dataframes from the given orc file path.
@@ -730,7 +730,7 @@ class PandasDataFramePackager(DefaultPackager):
730
730
  self,
731
731
  obj: pd.DataFrame,
732
732
  key: str,
733
- file_format: str = None,
733
+ file_format: Optional[str] = None,
734
734
  flatten: bool = True,
735
735
  **to_kwargs,
736
736
  ) -> tuple[Artifact, dict]:
@@ -785,8 +785,8 @@ class PandasDataFramePackager(DefaultPackager):
785
785
  def unpack_file(
786
786
  self,
787
787
  data_item: DataItem,
788
- file_format: str = None,
789
- read_kwargs: dict = None,
788
+ file_format: Optional[str] = None,
789
+ read_kwargs: Optional[dict] = None,
790
790
  ) -> pd.DataFrame:
791
791
  """
792
792
  Unpack a pandas dataframe from file.
@@ -883,7 +883,7 @@ class PandasSeriesPackager(PandasDataFramePackager):
883
883
  self,
884
884
  obj: pd.Series,
885
885
  key: str,
886
- file_format: str = None,
886
+ file_format: Optional[str] = None,
887
887
  flatten: bool = True,
888
888
  **to_kwargs,
889
889
  ) -> tuple[Artifact, dict]:
@@ -919,9 +919,9 @@ class PandasSeriesPackager(PandasDataFramePackager):
919
919
  def unpack_file(
920
920
  self,
921
921
  data_item: DataItem,
922
- file_format: str = None,
923
- read_kwargs: dict = None,
924
- column_name: Union[str, int] = None,
922
+ file_format: Optional[str] = None,
923
+ read_kwargs: Optional[dict] = None,
924
+ column_name: Optional[Union[str, int]] = None,
925
925
  ) -> pd.Series:
926
926
  """
927
927
  Unpack a pandas series from file.
@@ -15,7 +15,7 @@
15
15
  import os
16
16
  import pathlib
17
17
  import tempfile
18
- from typing import Union
18
+ from typing import Optional, Union
19
19
 
20
20
  from mlrun.artifacts import Artifact
21
21
  from mlrun.datastore import DataItem
@@ -140,7 +140,7 @@ class StrPackager(DefaultPackager):
140
140
  self,
141
141
  data_item: DataItem,
142
142
  is_directory: bool = False,
143
- archive_format: str = None,
143
+ archive_format: Optional[str] = None,
144
144
  ) -> str:
145
145
  """
146
146
  Unpack a data item representing a path string. If the path is of a file, the file is downloaded to a local
@@ -222,7 +222,7 @@ class _BuiltinCollectionPackager(DefaultPackager):
222
222
  return artifact, instructions
223
223
 
224
224
  def unpack_file(
225
- self, data_item: DataItem, file_format: str = None
225
+ self, data_item: DataItem, file_format: Optional[str] = None
226
226
  ) -> Union[dict, list]:
227
227
  """
228
228
  Unpack a builtin collection from file.
@@ -259,7 +259,9 @@ class DictPackager(_BuiltinCollectionPackager):
259
259
 
260
260
  PACKABLE_OBJECT_TYPE = dict
261
261
 
262
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> dict:
262
+ def unpack_file(
263
+ self, data_item: DataItem, file_format: Optional[str] = None
264
+ ) -> dict:
263
265
  """
264
266
  Unpack a dictionary from file.
265
267
 
@@ -285,7 +287,9 @@ class ListPackager(_BuiltinCollectionPackager):
285
287
 
286
288
  PACKABLE_OBJECT_TYPE = list
287
289
 
288
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> list:
290
+ def unpack_file(
291
+ self, data_item: DataItem, file_format: Optional[str] = None
292
+ ) -> list:
289
293
  """
290
294
  Unpack a list from file.
291
295
 
@@ -355,7 +359,9 @@ class TuplePackager(ListPackager):
355
359
  """
356
360
  return super().pack_file(obj=list(obj), key=key, file_format=file_format)
357
361
 
358
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> tuple:
362
+ def unpack_file(
363
+ self, data_item: DataItem, file_format: Optional[str] = None
364
+ ) -> tuple:
359
365
  """
360
366
  Unpack a tuple from file.
361
367
 
@@ -400,7 +406,9 @@ class SetPackager(ListPackager):
400
406
  """
401
407
  return super().pack_file(obj=list(obj), key=key, file_format=file_format)
402
408
 
403
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> set:
409
+ def unpack_file(
410
+ self, data_item: DataItem, file_format: Optional[str] = None
411
+ ) -> set:
404
412
  """
405
413
  Unpack a set from file.
406
414
 
@@ -434,7 +442,9 @@ class FrozensetPackager(SetPackager):
434
442
  """
435
443
  return super().pack_file(obj=set(obj), key=key, file_format=file_format)
436
444
 
437
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> frozenset:
445
+ def unpack_file(
446
+ self, data_item: DataItem, file_format: Optional[str] = None
447
+ ) -> frozenset:
438
448
  """
439
449
  Unpack a frozenset from file.
440
450
 
@@ -481,7 +491,9 @@ class BytesPackager(ListPackager):
481
491
  """
482
492
  return super().pack_file(obj=list(obj), key=key, file_format=file_format)
483
493
 
484
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> bytes:
494
+ def unpack_file(
495
+ self, data_item: DataItem, file_format: Optional[str] = None
496
+ ) -> bytes:
485
497
  """
486
498
  Unpack a bytes from file.
487
499
 
@@ -526,7 +538,9 @@ class BytearrayPackager(BytesPackager):
526
538
  """
527
539
  return super().pack_file(obj=bytes(obj), key=key, file_format=file_format)
528
540
 
529
- def unpack_file(self, data_item: DataItem, file_format: str = None) -> bytearray:
541
+ def unpack_file(
542
+ self, data_item: DataItem, file_format: Optional[str] = None
543
+ ) -> bytearray:
530
544
  """
531
545
  Unpack a bytearray from file.
532
546
 
@@ -585,7 +599,7 @@ class PathPackager(StrPackager):
585
599
  self,
586
600
  data_item: DataItem,
587
601
  is_directory: bool = False,
588
- archive_format: str = None,
602
+ archive_format: Optional[str] = None,
589
603
  ) -> pathlib.Path:
590
604
  """
591
605
  Unpack a data item representing a `Path`. If the path is of a file, the file is downloaded to a local