mlrun 1.7.0rc29__py3-none-any.whl → 1.7.0rc31__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 (39) hide show
  1. mlrun/common/constants.py +1 -1
  2. mlrun/common/formatters/artifact.py +1 -0
  3. mlrun/common/schemas/model_monitoring/constants.py +5 -1
  4. mlrun/common/schemas/project.py +10 -9
  5. mlrun/config.py +21 -2
  6. mlrun/data_types/spark.py +2 -2
  7. mlrun/data_types/to_pandas.py +48 -16
  8. mlrun/datastore/__init__.py +1 -0
  9. mlrun/datastore/base.py +20 -8
  10. mlrun/datastore/datastore.py +4 -2
  11. mlrun/datastore/datastore_profile.py +1 -1
  12. mlrun/datastore/google_cloud_storage.py +1 -0
  13. mlrun/datastore/inmem.py +3 -0
  14. mlrun/datastore/s3.py +2 -0
  15. mlrun/datastore/sources.py +14 -0
  16. mlrun/datastore/targets.py +11 -1
  17. mlrun/db/base.py +1 -0
  18. mlrun/db/httpdb.py +10 -2
  19. mlrun/db/nopdb.py +1 -0
  20. mlrun/feature_store/retrieval/spark_merger.py +3 -32
  21. mlrun/model.py +1 -5
  22. mlrun/model_monitoring/api.py +3 -3
  23. mlrun/model_monitoring/controller.py +57 -73
  24. mlrun/model_monitoring/db/stores/sqldb/sql_store.py +8 -2
  25. mlrun/model_monitoring/db/stores/v3io_kv/kv_store.py +3 -0
  26. mlrun/model_monitoring/helpers.py +6 -12
  27. mlrun/model_monitoring/writer.py +1 -2
  28. mlrun/projects/project.py +16 -0
  29. mlrun/run.py +5 -5
  30. mlrun/runtimes/base.py +1 -1
  31. mlrun/utils/version/version.json +2 -2
  32. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/METADATA +6 -6
  33. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/RECORD +37 -39
  34. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/WHEEL +1 -1
  35. mlrun/feature_store/retrieval/conversion.py +0 -271
  36. mlrun/model_monitoring/controller_handler.py +0 -37
  37. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/LICENSE +0 -0
  38. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/entry_points.txt +0 -0
  39. {mlrun-1.7.0rc29.dist-info → mlrun-1.7.0rc31.dist-info}/top_level.txt +0 -0
@@ -1,271 +0,0 @@
1
- # Copyright 2024 Iguazio
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- #
15
- import warnings
16
- from collections import Counter
17
-
18
- # Copied from https://github.com/apache/spark/blob/v3.2.3/python/pyspark/sql/pandas/conversion.py, with
19
- # np.bool -> bool and np.object -> object fix backported from pyspark v3.3.3.
20
-
21
-
22
- class PandasConversionMixin:
23
- """
24
- Min-in for the conversion from Spark to pandas. Currently, only :class:`DataFrame`
25
- can use this class.
26
- """
27
-
28
- def toPandas(self):
29
- """
30
- Returns the contents of this :class:`DataFrame` as Pandas ``pandas.DataFrame``.
31
-
32
- This is only available if Pandas is installed and available.
33
-
34
- .. versionadded:: 1.3.0
35
-
36
- Notes
37
- -----
38
- This method should only be used if the resulting Pandas's :class:`DataFrame` is
39
- expected to be small, as all the data is loaded into the driver's memory.
40
-
41
- Usage with spark.sql.execution.arrow.pyspark.enabled=True is experimental.
42
-
43
- Examples
44
- --------
45
- >>> df.toPandas() # doctest: +SKIP
46
- age name
47
- 0 2 Alice
48
- 1 5 Bob
49
- """
50
- from pyspark.sql.dataframe import DataFrame
51
-
52
- assert isinstance(self, DataFrame)
53
-
54
- from pyspark.sql.pandas.utils import require_minimum_pandas_version
55
-
56
- require_minimum_pandas_version()
57
-
58
- import numpy as np
59
- import pandas as pd
60
- from pyspark.sql.types import (
61
- BooleanType,
62
- IntegralType,
63
- MapType,
64
- TimestampType,
65
- )
66
-
67
- timezone = self.sql_ctx._conf.sessionLocalTimeZone()
68
-
69
- if self.sql_ctx._conf.arrowPySparkEnabled():
70
- use_arrow = True
71
- try:
72
- from pyspark.sql.pandas.types import to_arrow_schema
73
- from pyspark.sql.pandas.utils import require_minimum_pyarrow_version
74
-
75
- require_minimum_pyarrow_version()
76
- to_arrow_schema(self.schema)
77
- except Exception as e:
78
- if self.sql_ctx._conf.arrowPySparkFallbackEnabled():
79
- msg = (
80
- "toPandas attempted Arrow optimization because "
81
- "'spark.sql.execution.arrow.pyspark.enabled' is set to true; however, "
82
- f"failed by the reason below:\n {e}\n"
83
- "Attempting non-optimization as "
84
- "'spark.sql.execution.arrow.pyspark.fallback.enabled' is set to "
85
- "true."
86
- )
87
- warnings.warn(msg)
88
- use_arrow = False
89
- else:
90
- msg = (
91
- "toPandas attempted Arrow optimization because "
92
- "'spark.sql.execution.arrow.pyspark.enabled' is set to true, but has "
93
- "reached the error below and will not continue because automatic fallback "
94
- "with 'spark.sql.execution.arrow.pyspark.fallback.enabled' has been set to "
95
- f"false.\n {e}"
96
- )
97
- warnings.warn(msg)
98
- raise
99
-
100
- # Try to use Arrow optimization when the schema is supported and the required version
101
- # of PyArrow is found, if 'spark.sql.execution.arrow.pyspark.enabled' is enabled.
102
- if use_arrow:
103
- try:
104
- import pyarrow
105
- from pyspark.sql.pandas.types import (
106
- _check_series_localize_timestamps,
107
- _convert_map_items_to_dict,
108
- )
109
-
110
- # Rename columns to avoid duplicated column names.
111
- tmp_column_names = [f"col_{i}" for i in range(len(self.columns))]
112
- self_destruct = self.sql_ctx._conf.arrowPySparkSelfDestructEnabled()
113
- batches = self.toDF(*tmp_column_names)._collect_as_arrow(
114
- split_batches=self_destruct
115
- )
116
- if len(batches) > 0:
117
- table = pyarrow.Table.from_batches(batches)
118
- # Ensure only the table has a reference to the batches, so that
119
- # self_destruct (if enabled) is effective
120
- del batches
121
- # Pandas DataFrame created from PyArrow uses datetime64[ns] for date type
122
- # values, but we should use datetime.date to match the behavior with when
123
- # Arrow optimization is disabled.
124
- pandas_options = {"date_as_object": True}
125
- if self_destruct:
126
- # Configure PyArrow to use as little memory as possible:
127
- # self_destruct - free columns as they are converted
128
- # split_blocks - create a separate Pandas block for each column
129
- # use_threads - convert one column at a time
130
- pandas_options.update(
131
- {
132
- "self_destruct": True,
133
- "split_blocks": True,
134
- "use_threads": False,
135
- }
136
- )
137
- pdf = table.to_pandas(**pandas_options)
138
- # Rename back to the original column names.
139
- pdf.columns = self.columns
140
- for field in self.schema:
141
- if isinstance(field.dataType, TimestampType):
142
- pdf[field.name] = _check_series_localize_timestamps(
143
- pdf[field.name], timezone
144
- )
145
- elif isinstance(field.dataType, MapType):
146
- pdf[field.name] = _convert_map_items_to_dict(
147
- pdf[field.name]
148
- )
149
- return pdf
150
- else:
151
- return pd.DataFrame.from_records([], columns=self.columns)
152
- except Exception as e:
153
- # We might have to allow fallback here as well but multiple Spark jobs can
154
- # be executed. So, simply fail in this case for now.
155
- msg = (
156
- "toPandas attempted Arrow optimization because "
157
- "'spark.sql.execution.arrow.pyspark.enabled' is set to true, but has "
158
- "reached the error below and can not continue. Note that "
159
- "'spark.sql.execution.arrow.pyspark.fallback.enabled' does not have an "
160
- "effect on failures in the middle of "
161
- f"computation.\n {e}"
162
- )
163
- warnings.warn(msg)
164
- raise
165
-
166
- # Below is toPandas without Arrow optimization.
167
- pdf = pd.DataFrame.from_records(self.collect(), columns=self.columns)
168
- column_counter = Counter(self.columns)
169
-
170
- dtype = [None] * len(self.schema)
171
- for field_idx, field in enumerate(self.schema):
172
- # For duplicate column name, we use `iloc` to access it.
173
- if column_counter[field.name] > 1:
174
- pandas_col = pdf.iloc[:, field_idx]
175
- else:
176
- pandas_col = pdf[field.name]
177
-
178
- pandas_type = PandasConversionMixin._to_corrected_pandas_type(
179
- field.dataType
180
- )
181
- # SPARK-21766: if an integer field is nullable and has null values, it can be
182
- # inferred by pandas as float column. Once we convert the column with NaN back
183
- # to integer type e.g., np.int16, we will hit exception. So we use the inferred
184
- # float type, not the corrected type from the schema in this case.
185
- if pandas_type is not None and not (
186
- isinstance(field.dataType, IntegralType)
187
- and field.nullable
188
- and pandas_col.isnull().any()
189
- ):
190
- dtype[field_idx] = pandas_type
191
- # Ensure we fall back to nullable numpy types, even when whole column is null:
192
- if isinstance(field.dataType, IntegralType) and pandas_col.isnull().any():
193
- dtype[field_idx] = np.float64
194
- if isinstance(field.dataType, BooleanType) and pandas_col.isnull().any():
195
- dtype[field_idx] = object
196
-
197
- df = pd.DataFrame()
198
- for index, t in enumerate(dtype):
199
- column_name = self.schema[index].name
200
-
201
- # For duplicate column name, we use `iloc` to access it.
202
- if column_counter[column_name] > 1:
203
- series = pdf.iloc[:, index]
204
- else:
205
- series = pdf[column_name]
206
-
207
- if t is not None:
208
- series = series.astype(t, copy=False)
209
-
210
- # `insert` API makes copy of data, we only do it for Series of duplicate column names.
211
- # `pdf.iloc[:, index] = pdf.iloc[:, index]...` doesn't always work because `iloc` could
212
- # return a view or a copy depending by context.
213
- if column_counter[column_name] > 1:
214
- df.insert(index, column_name, series, allow_duplicates=True)
215
- else:
216
- df[column_name] = series
217
-
218
- pdf = df
219
-
220
- if timezone is None:
221
- return pdf
222
- else:
223
- from pyspark.sql.pandas.types import (
224
- _check_series_convert_timestamps_local_tz,
225
- )
226
-
227
- for field in self.schema:
228
- # TODO: handle nested timestamps, such as ArrayType(TimestampType())?
229
- if isinstance(field.dataType, TimestampType):
230
- pdf[field.name] = _check_series_convert_timestamps_local_tz(
231
- pdf[field.name], timezone
232
- )
233
- return pdf
234
-
235
- @staticmethod
236
- def _to_corrected_pandas_type(dt):
237
- """
238
- When converting Spark SQL records to Pandas :class:`DataFrame`, the inferred data type
239
- may be wrong. This method gets the corrected data type for Pandas if that type may be
240
- inferred incorrectly.
241
- """
242
- import numpy as np
243
- from pyspark.sql.types import (
244
- BooleanType,
245
- ByteType,
246
- DoubleType,
247
- FloatType,
248
- IntegerType,
249
- LongType,
250
- ShortType,
251
- TimestampType,
252
- )
253
-
254
- if type(dt) == ByteType:
255
- return np.int8
256
- elif type(dt) == ShortType:
257
- return np.int16
258
- elif type(dt) == IntegerType:
259
- return np.int32
260
- elif type(dt) == LongType:
261
- return np.int64
262
- elif type(dt) == FloatType:
263
- return np.float32
264
- elif type(dt) == DoubleType:
265
- return np.float64
266
- elif type(dt) == BooleanType:
267
- return bool
268
- elif type(dt) == TimestampType:
269
- return np.datetime64
270
- else:
271
- return None
@@ -1,37 +0,0 @@
1
- # Copyright 2023 Iguazio
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- import nuclio
15
-
16
- import mlrun
17
- from mlrun.model_monitoring.controller import MonitoringApplicationController
18
-
19
-
20
- def handler(context: nuclio.Context, event: nuclio.Event) -> None:
21
- """
22
- Run model monitoring application processor
23
-
24
- :param context: the Nuclio context
25
- :param event: trigger event
26
- """
27
- context.user_data.monitor_app_controller.run(event)
28
-
29
-
30
- def init_context(context):
31
- mlrun_context = mlrun.get_or_create_ctx("model_monitoring_controller")
32
- mlrun_context.logger.info("Initialize monitoring app controller")
33
- monitor_app_controller = MonitoringApplicationController(
34
- mlrun_context=mlrun_context,
35
- project=mlrun_context.project,
36
- )
37
- setattr(context.user_data, "monitor_app_controller", monitor_app_controller)