snowflake-ml-python 1.4.0__py3-none-any.whl → 1.5.0__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.
Files changed (234) hide show
  1. snowflake/ml/_internal/env_utils.py +77 -32
  2. snowflake/ml/_internal/exceptions/dataset_error_messages.py +5 -0
  3. snowflake/ml/_internal/exceptions/dataset_errors.py +24 -0
  4. snowflake/ml/_internal/exceptions/error_codes.py +3 -0
  5. snowflake/ml/_internal/lineage/data_source.py +10 -0
  6. snowflake/ml/_internal/lineage/dataset_dataframe.py +44 -0
  7. snowflake/ml/_internal/utils/identifier.py +3 -1
  8. snowflake/ml/_internal/utils/sql_identifier.py +2 -6
  9. snowflake/ml/dataset/__init__.py +10 -0
  10. snowflake/ml/dataset/dataset.py +454 -129
  11. snowflake/ml/dataset/dataset_factory.py +53 -0
  12. snowflake/ml/dataset/dataset_metadata.py +103 -0
  13. snowflake/ml/dataset/dataset_reader.py +202 -0
  14. snowflake/ml/feature_store/feature_store.py +531 -332
  15. snowflake/ml/feature_store/feature_view.py +40 -23
  16. snowflake/ml/fileset/embedded_stage_fs.py +146 -0
  17. snowflake/ml/fileset/sfcfs.py +56 -54
  18. snowflake/ml/fileset/snowfs.py +159 -0
  19. snowflake/ml/fileset/stage_fs.py +49 -17
  20. snowflake/ml/model/__init__.py +2 -2
  21. snowflake/ml/model/_api.py +16 -1
  22. snowflake/ml/model/_client/model/model_impl.py +27 -0
  23. snowflake/ml/model/_client/model/model_version_impl.py +137 -50
  24. snowflake/ml/model/_client/ops/model_ops.py +159 -40
  25. snowflake/ml/model/_client/sql/model.py +25 -2
  26. snowflake/ml/model/_client/sql/model_version.py +131 -2
  27. snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +5 -1
  28. snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +1 -0
  29. snowflake/ml/model/_deploy_client/snowservice/deploy.py +2 -0
  30. snowflake/ml/model/_deploy_client/utils/constants.py +0 -5
  31. snowflake/ml/model/_deploy_client/utils/snowservice_client.py +21 -50
  32. snowflake/ml/model/_model_composer/model_composer.py +22 -1
  33. snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +38 -51
  34. snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +19 -1
  35. snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
  36. snowflake/ml/model/_packager/model_env/model_env.py +41 -0
  37. snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
  38. snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
  39. snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
  40. snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
  41. snowflake/ml/model/_packager/model_meta/model_meta.py +37 -11
  42. snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
  43. snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
  44. snowflake/ml/model/_packager/model_packager.py +2 -5
  45. snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
  46. snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
  47. snowflake/ml/model/type_hints.py +21 -2
  48. snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
  49. snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
  50. snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +55 -3
  51. snowflake/ml/modeling/_internal/ml_runtime_implementations/ml_runtime_handlers.py +34 -18
  52. snowflake/ml/modeling/_internal/model_trainer.py +7 -0
  53. snowflake/ml/modeling/_internal/model_trainer_builder.py +42 -9
  54. snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +13 -14
  55. snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +29 -7
  56. snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +261 -16
  57. snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +246 -175
  58. snowflake/ml/modeling/cluster/affinity_propagation.py +246 -175
  59. snowflake/ml/modeling/cluster/agglomerative_clustering.py +246 -175
  60. snowflake/ml/modeling/cluster/birch.py +248 -175
  61. snowflake/ml/modeling/cluster/bisecting_k_means.py +248 -175
  62. snowflake/ml/modeling/cluster/dbscan.py +246 -175
  63. snowflake/ml/modeling/cluster/feature_agglomeration.py +248 -175
  64. snowflake/ml/modeling/cluster/k_means.py +248 -175
  65. snowflake/ml/modeling/cluster/mean_shift.py +246 -175
  66. snowflake/ml/modeling/cluster/mini_batch_k_means.py +248 -175
  67. snowflake/ml/modeling/cluster/optics.py +246 -175
  68. snowflake/ml/modeling/cluster/spectral_biclustering.py +246 -175
  69. snowflake/ml/modeling/cluster/spectral_clustering.py +246 -175
  70. snowflake/ml/modeling/cluster/spectral_coclustering.py +246 -175
  71. snowflake/ml/modeling/compose/column_transformer.py +248 -175
  72. snowflake/ml/modeling/compose/transformed_target_regressor.py +246 -175
  73. snowflake/ml/modeling/covariance/elliptic_envelope.py +246 -175
  74. snowflake/ml/modeling/covariance/empirical_covariance.py +246 -175
  75. snowflake/ml/modeling/covariance/graphical_lasso.py +246 -175
  76. snowflake/ml/modeling/covariance/graphical_lasso_cv.py +246 -175
  77. snowflake/ml/modeling/covariance/ledoit_wolf.py +246 -175
  78. snowflake/ml/modeling/covariance/min_cov_det.py +246 -175
  79. snowflake/ml/modeling/covariance/oas.py +246 -175
  80. snowflake/ml/modeling/covariance/shrunk_covariance.py +246 -175
  81. snowflake/ml/modeling/decomposition/dictionary_learning.py +248 -175
  82. snowflake/ml/modeling/decomposition/factor_analysis.py +248 -175
  83. snowflake/ml/modeling/decomposition/fast_ica.py +248 -175
  84. snowflake/ml/modeling/decomposition/incremental_pca.py +248 -175
  85. snowflake/ml/modeling/decomposition/kernel_pca.py +248 -175
  86. snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +248 -175
  87. snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +248 -175
  88. snowflake/ml/modeling/decomposition/pca.py +248 -175
  89. snowflake/ml/modeling/decomposition/sparse_pca.py +248 -175
  90. snowflake/ml/modeling/decomposition/truncated_svd.py +248 -175
  91. snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +248 -175
  92. snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +246 -175
  93. snowflake/ml/modeling/ensemble/ada_boost_classifier.py +246 -175
  94. snowflake/ml/modeling/ensemble/ada_boost_regressor.py +246 -175
  95. snowflake/ml/modeling/ensemble/bagging_classifier.py +246 -175
  96. snowflake/ml/modeling/ensemble/bagging_regressor.py +246 -175
  97. snowflake/ml/modeling/ensemble/extra_trees_classifier.py +246 -175
  98. snowflake/ml/modeling/ensemble/extra_trees_regressor.py +246 -175
  99. snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +246 -175
  100. snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +246 -175
  101. snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +246 -175
  102. snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +246 -175
  103. snowflake/ml/modeling/ensemble/isolation_forest.py +246 -175
  104. snowflake/ml/modeling/ensemble/random_forest_classifier.py +246 -175
  105. snowflake/ml/modeling/ensemble/random_forest_regressor.py +246 -175
  106. snowflake/ml/modeling/ensemble/stacking_regressor.py +248 -175
  107. snowflake/ml/modeling/ensemble/voting_classifier.py +248 -175
  108. snowflake/ml/modeling/ensemble/voting_regressor.py +248 -175
  109. snowflake/ml/modeling/feature_selection/generic_univariate_select.py +248 -175
  110. snowflake/ml/modeling/feature_selection/select_fdr.py +248 -175
  111. snowflake/ml/modeling/feature_selection/select_fpr.py +248 -175
  112. snowflake/ml/modeling/feature_selection/select_fwe.py +248 -175
  113. snowflake/ml/modeling/feature_selection/select_k_best.py +248 -175
  114. snowflake/ml/modeling/feature_selection/select_percentile.py +248 -175
  115. snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +248 -175
  116. snowflake/ml/modeling/feature_selection/variance_threshold.py +248 -175
  117. snowflake/ml/modeling/framework/_utils.py +8 -1
  118. snowflake/ml/modeling/framework/base.py +72 -37
  119. snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +246 -175
  120. snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +246 -175
  121. snowflake/ml/modeling/impute/iterative_imputer.py +248 -175
  122. snowflake/ml/modeling/impute/knn_imputer.py +248 -175
  123. snowflake/ml/modeling/impute/missing_indicator.py +248 -175
  124. snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +248 -175
  125. snowflake/ml/modeling/kernel_approximation/nystroem.py +248 -175
  126. snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +248 -175
  127. snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +248 -175
  128. snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +248 -175
  129. snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +246 -175
  130. snowflake/ml/modeling/lightgbm/lgbm_classifier.py +246 -175
  131. snowflake/ml/modeling/lightgbm/lgbm_regressor.py +246 -175
  132. snowflake/ml/modeling/linear_model/ard_regression.py +246 -175
  133. snowflake/ml/modeling/linear_model/bayesian_ridge.py +246 -175
  134. snowflake/ml/modeling/linear_model/elastic_net.py +246 -175
  135. snowflake/ml/modeling/linear_model/elastic_net_cv.py +246 -175
  136. snowflake/ml/modeling/linear_model/gamma_regressor.py +246 -175
  137. snowflake/ml/modeling/linear_model/huber_regressor.py +246 -175
  138. snowflake/ml/modeling/linear_model/lars.py +246 -175
  139. snowflake/ml/modeling/linear_model/lars_cv.py +246 -175
  140. snowflake/ml/modeling/linear_model/lasso.py +246 -175
  141. snowflake/ml/modeling/linear_model/lasso_cv.py +246 -175
  142. snowflake/ml/modeling/linear_model/lasso_lars.py +246 -175
  143. snowflake/ml/modeling/linear_model/lasso_lars_cv.py +246 -175
  144. snowflake/ml/modeling/linear_model/lasso_lars_ic.py +246 -175
  145. snowflake/ml/modeling/linear_model/linear_regression.py +246 -175
  146. snowflake/ml/modeling/linear_model/logistic_regression.py +246 -175
  147. snowflake/ml/modeling/linear_model/logistic_regression_cv.py +246 -175
  148. snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +246 -175
  149. snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +246 -175
  150. snowflake/ml/modeling/linear_model/multi_task_lasso.py +246 -175
  151. snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +246 -175
  152. snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +246 -175
  153. snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +246 -175
  154. snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +246 -175
  155. snowflake/ml/modeling/linear_model/perceptron.py +246 -175
  156. snowflake/ml/modeling/linear_model/poisson_regressor.py +246 -175
  157. snowflake/ml/modeling/linear_model/ransac_regressor.py +246 -175
  158. snowflake/ml/modeling/linear_model/ridge.py +246 -175
  159. snowflake/ml/modeling/linear_model/ridge_classifier.py +246 -175
  160. snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +246 -175
  161. snowflake/ml/modeling/linear_model/ridge_cv.py +246 -175
  162. snowflake/ml/modeling/linear_model/sgd_classifier.py +246 -175
  163. snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +246 -175
  164. snowflake/ml/modeling/linear_model/sgd_regressor.py +246 -175
  165. snowflake/ml/modeling/linear_model/theil_sen_regressor.py +246 -175
  166. snowflake/ml/modeling/linear_model/tweedie_regressor.py +246 -175
  167. snowflake/ml/modeling/manifold/isomap.py +248 -175
  168. snowflake/ml/modeling/manifold/mds.py +248 -175
  169. snowflake/ml/modeling/manifold/spectral_embedding.py +248 -175
  170. snowflake/ml/modeling/manifold/tsne.py +248 -175
  171. snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +246 -175
  172. snowflake/ml/modeling/mixture/gaussian_mixture.py +246 -175
  173. snowflake/ml/modeling/model_selection/grid_search_cv.py +63 -41
  174. snowflake/ml/modeling/model_selection/randomized_search_cv.py +80 -38
  175. snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +246 -175
  176. snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +246 -175
  177. snowflake/ml/modeling/multiclass/output_code_classifier.py +246 -175
  178. snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +246 -175
  179. snowflake/ml/modeling/naive_bayes/categorical_nb.py +246 -175
  180. snowflake/ml/modeling/naive_bayes/complement_nb.py +246 -175
  181. snowflake/ml/modeling/naive_bayes/gaussian_nb.py +246 -175
  182. snowflake/ml/modeling/naive_bayes/multinomial_nb.py +246 -175
  183. snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +246 -175
  184. snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +246 -175
  185. snowflake/ml/modeling/neighbors/kernel_density.py +246 -175
  186. snowflake/ml/modeling/neighbors/local_outlier_factor.py +246 -175
  187. snowflake/ml/modeling/neighbors/nearest_centroid.py +246 -175
  188. snowflake/ml/modeling/neighbors/nearest_neighbors.py +246 -175
  189. snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +248 -175
  190. snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +246 -175
  191. snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +246 -175
  192. snowflake/ml/modeling/neural_network/bernoulli_rbm.py +248 -175
  193. snowflake/ml/modeling/neural_network/mlp_classifier.py +246 -175
  194. snowflake/ml/modeling/neural_network/mlp_regressor.py +246 -175
  195. snowflake/ml/modeling/pipeline/pipeline.py +517 -35
  196. snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
  197. snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
  198. snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
  199. snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
  200. snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
  201. snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
  202. snowflake/ml/modeling/preprocessing/one_hot_encoder.py +13 -5
  203. snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
  204. snowflake/ml/modeling/preprocessing/polynomial_features.py +248 -175
  205. snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
  206. snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
  207. snowflake/ml/modeling/semi_supervised/label_propagation.py +246 -175
  208. snowflake/ml/modeling/semi_supervised/label_spreading.py +246 -175
  209. snowflake/ml/modeling/svm/linear_svc.py +246 -175
  210. snowflake/ml/modeling/svm/linear_svr.py +246 -175
  211. snowflake/ml/modeling/svm/nu_svc.py +246 -175
  212. snowflake/ml/modeling/svm/nu_svr.py +246 -175
  213. snowflake/ml/modeling/svm/svc.py +246 -175
  214. snowflake/ml/modeling/svm/svr.py +246 -175
  215. snowflake/ml/modeling/tree/decision_tree_classifier.py +246 -175
  216. snowflake/ml/modeling/tree/decision_tree_regressor.py +246 -175
  217. snowflake/ml/modeling/tree/extra_tree_classifier.py +246 -175
  218. snowflake/ml/modeling/tree/extra_tree_regressor.py +246 -175
  219. snowflake/ml/modeling/xgboost/xgb_classifier.py +246 -175
  220. snowflake/ml/modeling/xgboost/xgb_regressor.py +246 -175
  221. snowflake/ml/modeling/xgboost/xgbrf_classifier.py +246 -175
  222. snowflake/ml/modeling/xgboost/xgbrf_regressor.py +246 -175
  223. snowflake/ml/registry/model_registry.py +3 -149
  224. snowflake/ml/registry/registry.py +1 -1
  225. snowflake/ml/version.py +1 -1
  226. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/METADATA +129 -57
  227. snowflake_ml_python-1.5.0.dist-info/RECORD +380 -0
  228. snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
  229. snowflake/ml/registry/_artifact_manager.py +0 -156
  230. snowflake/ml/registry/artifact.py +0 -46
  231. snowflake_ml_python-1.4.0.dist-info/RECORD +0 -370
  232. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/LICENSE.txt +0 -0
  233. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/WHEEL +0 -0
  234. {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/top_level.txt +0 -0
@@ -13,12 +13,8 @@ from packaging import requirements, specifiers, utils as packaging_utils, versio
13
13
 
14
14
  import snowflake.connector
15
15
  from snowflake.ml._internal import env as snowml_env
16
- from snowflake.ml._internal.exceptions import (
17
- error_codes,
18
- exceptions as snowml_exceptions,
19
- )
20
16
  from snowflake.ml._internal.utils import query_result_checker
21
- from snowflake.snowpark import session
17
+ from snowflake.snowpark import context, exceptions, session
22
18
  from snowflake.snowpark._internal import utils as snowpark_utils
23
19
 
24
20
 
@@ -237,6 +233,72 @@ def get_local_installed_version_of_pip_package(pip_req: requirements.Requirement
237
233
  return new_pip_req
238
234
 
239
235
 
236
+ class IncorrectLocalEnvironmentError(Exception):
237
+ ...
238
+
239
+
240
+ def validate_local_installed_version_of_pip_package(pip_req: requirements.Requirement) -> None:
241
+ """Validate if the package is locally installed, and the local version meet the specifier of the requirements.
242
+
243
+ Args:
244
+ pip_req: A requirements.Requirement object showing the requirement.
245
+
246
+ Raises:
247
+ IncorrectLocalEnvironmentError: Raised when cannot find the local installation of the requested package.
248
+ IncorrectLocalEnvironmentError: Raised when the local installed version cannot meet the requirement.
249
+ """
250
+ try:
251
+ local_dist = importlib_metadata.distribution(pip_req.name)
252
+ local_dist_version = version.parse(local_dist.version)
253
+ except importlib_metadata.PackageNotFoundError:
254
+ raise IncorrectLocalEnvironmentError(f"Cannot find the local installation of the requested package {pip_req}.")
255
+
256
+ if not pip_req.specifier.contains(local_dist_version):
257
+ raise IncorrectLocalEnvironmentError(
258
+ f"The local installed version {local_dist_version} cannot meet the requirement {pip_req}."
259
+ )
260
+
261
+
262
+ CONDA_PKG_NAME_TO_PYPI_MAP = {"pytorch": "torch"}
263
+
264
+
265
+ def try_convert_conda_requirement_to_pip(conda_req: requirements.Requirement) -> requirements.Requirement:
266
+ """Return a new requirements.Requirement object whose name has been attempted to convert to name in pypi from conda.
267
+
268
+ Args:
269
+ conda_req: A requirements.Requirement object showing the requirement in conda.
270
+
271
+ Returns:
272
+ A new requirements.Requirement object showing the requirement in pypi.
273
+ """
274
+ pip_req = copy.deepcopy(conda_req)
275
+ pip_req.name = CONDA_PKG_NAME_TO_PYPI_MAP.get(conda_req.name, conda_req.name)
276
+ return pip_req
277
+
278
+
279
+ def validate_py_runtime_version(provided_py_version_str: str) -> None:
280
+ """Validate the provided python version string with python version in current runtime.
281
+ If the major or minor is different, errors out.
282
+
283
+ Args:
284
+ provided_py_version_str: the provided python version string.
285
+
286
+ Raises:
287
+ IncorrectLocalEnvironmentError: Raised when the provided python version has different major or minor.
288
+ """
289
+ if provided_py_version_str != snowml_env.PYTHON_VERSION:
290
+ provided_py_version = version.parse(provided_py_version_str)
291
+ current_py_version = version.parse(snowml_env.PYTHON_VERSION)
292
+ if (
293
+ provided_py_version.major != current_py_version.major
294
+ or provided_py_version.minor != current_py_version.minor
295
+ ):
296
+ raise IncorrectLocalEnvironmentError(
297
+ f"Requested python version is {provided_py_version_str} "
298
+ f"while current Python version is {snowml_env.PYTHON_VERSION}. "
299
+ )
300
+
301
+
240
302
  def get_package_spec_with_supported_ops_only(req: requirements.Requirement) -> requirements.Requirement:
241
303
  """Get the package spec with supported ops only including ==, >=, <=, > and <
242
304
 
@@ -332,6 +394,16 @@ def get_matched_package_versions_in_snowflake_conda_channel(
332
394
  return matched_versions
333
395
 
334
396
 
397
+ def get_matched_package_versions_in_information_schema_with_active_session(
398
+ reqs: List[requirements.Requirement], python_version: str
399
+ ) -> Dict[str, List[version.Version]]:
400
+ try:
401
+ session = context.get_active_session()
402
+ except exceptions.SnowparkSessionException:
403
+ return {}
404
+ return get_matched_package_versions_in_information_schema(session, reqs, python_version)
405
+
406
+
335
407
  def get_matched_package_versions_in_information_schema(
336
408
  session: session.Session, reqs: List[requirements.Requirement], python_version: str
337
409
  ) -> Dict[str, List[version.Version]]:
@@ -558,33 +630,6 @@ def parse_python_version_string(dep: str) -> Optional[str]:
558
630
  return None
559
631
 
560
632
 
561
- def validate_py_runtime_version(provided_py_version_str: str) -> None:
562
- """Validate the provided python version string with python version in current runtime.
563
- If the major or minor is different, errors out.
564
-
565
- Args:
566
- provided_py_version_str: the provided python version string.
567
-
568
- Raises:
569
- SnowflakeMLException: Raised when the provided python version has different major or minor.
570
- """
571
- if provided_py_version_str != snowml_env.PYTHON_VERSION:
572
- provided_py_version = version.parse(provided_py_version_str)
573
- current_py_version = version.parse(snowml_env.PYTHON_VERSION)
574
- if (
575
- provided_py_version.major != current_py_version.major
576
- or provided_py_version.minor != current_py_version.minor
577
- ):
578
- raise snowml_exceptions.SnowflakeMLException(
579
- error_code=error_codes.LOCAL_ENVIRONMENT_ERROR,
580
- original_exception=RuntimeError(
581
- f"Unable to load model which is saved with Python {provided_py_version_str} "
582
- f"while current Python version is {snowml_env.PYTHON_VERSION}. "
583
- "To load model metadata only, set meta_only to True."
584
- ),
585
- )
586
-
587
-
588
633
  def _find_conda_dep_spec(
589
634
  conda_chan_deps: DefaultDict[str, List[requirements.Requirement]], pkg_name: str
590
635
  ) -> Optional[Tuple[str, requirements.Requirement]]:
@@ -0,0 +1,5 @@
1
+ DATASET_ALREADY_EXISTS = "Dataset {} already exists."
2
+ DATASET_VERSION_ALREADY_EXISTS = "Dataset {} version {} already exists."
3
+
4
+ DATASET_NOT_EXIST = "Dataset {} does not exist or is inaccessible."
5
+ DATASET_VERSION_NOT_EXIST = "Dataset {} version '{}' does not exist or is inaccessible."
@@ -0,0 +1,24 @@
1
+ # Error code from Snowflake Python Connector.
2
+ ERRNO_OBJECT_ALREADY_EXISTS = "002002"
3
+ ERRNO_OBJECT_NOT_EXIST = "002043"
4
+ ERRNO_FILES_ALREADY_EXISTING = "001030"
5
+ ERRNO_VERSION_ALREADY_EXISTS = "092917"
6
+ ERRNO_DATASET_NOT_EXIST = "399019"
7
+ ERRNO_DATASET_VERSION_NOT_EXIST = "399012"
8
+ ERRNO_DATASET_VERSION_ALREADY_EXISTS = "399020"
9
+
10
+
11
+ class DatasetError(Exception):
12
+ """Base class for other exceptions."""
13
+
14
+
15
+ class DatasetNotExistError(DatasetError):
16
+ """Raised when the requested Dataset does not exist."""
17
+
18
+
19
+ class DatasetExistError(DatasetError):
20
+ """Raised when there is already an existing Dataset with the same name and version in selected schema."""
21
+
22
+
23
+ class DatasetCannotDeleteError(DatasetError):
24
+ """Raised when a Dataset is unable to get deleted."""
@@ -105,3 +105,6 @@ UNFEASIBLE_ENVIRONMENT_ERROR = "2502"
105
105
 
106
106
  # Missing required client side dependency.
107
107
  CLIENT_DEPENDENCY_MISSING_ERROR = "2511"
108
+
109
+ # Current client side snowpark-ml-python version is outdated and may have forward compatibility issue
110
+ SNOWML_PACKAGE_OUTDATED = "2700"
@@ -0,0 +1,10 @@
1
+ import dataclasses
2
+ from typing import List, Optional
3
+
4
+
5
+ @dataclasses.dataclass(frozen=True)
6
+ class DataSource:
7
+ fully_qualified_name: str
8
+ version: str
9
+ url: str
10
+ exclude_cols: Optional[List[str]] = None
@@ -0,0 +1,44 @@
1
+ import copy
2
+ from typing import List
3
+
4
+ from snowflake import snowpark
5
+ from snowflake.ml._internal.lineage import data_source
6
+
7
+
8
+ class DatasetDataFrame(snowpark.DataFrame):
9
+ """
10
+ Represents a lazily-evaluated dataset. It extends :class:`snowpark.DataFrame` so all
11
+ :class:`snowpark.DataFrame` operations can be applied to it. It holds additional information
12
+ related to the :class`Dataset`.
13
+
14
+ It will be created by dataset.read.to_snowpark_dataframe() API and by the transformations
15
+ that produce a new dataframe.
16
+ """
17
+
18
+ @staticmethod
19
+ def from_dataframe(
20
+ df: snowpark.DataFrame, data_sources: List[data_source.DataSource], inplace: bool = False
21
+ ) -> "DatasetDataFrame":
22
+ """
23
+ Create a new DatasetDataFrame instance from a snowpark.DataFrame instance with
24
+ additional source information.
25
+
26
+ Args:
27
+ df (snowpark.DataFrame): The Snowpark DataFrame to be converted.
28
+ data_sources (List[DataSource]): A list of data sources to associate with the DataFrame.
29
+ inplace (bool): If True, modifies the DataFrame in place; otherwise, returns a new DatasetDataFrame.
30
+
31
+ Returns:
32
+ DatasetDataFrame: A new or modified DatasetDataFrame depending on the 'inplace' argument.
33
+ """
34
+ if not inplace:
35
+ df = copy.deepcopy(df)
36
+ df.__class__ = DatasetDataFrame
37
+ df._data_sources = data_sources # type:ignore[attr-defined]
38
+ return df # type: ignore[return-value]
39
+
40
+ def _get_sources(self) -> List[data_source.DataSource]:
41
+ """
42
+ Returns the data sources associated with the DataFrame.
43
+ """
44
+ return self._data_sources # type: ignore[no-any-return]
@@ -338,4 +338,6 @@ def resolve_identifier(name: str) -> str:
338
338
  elif UNQUOTED_CASE_INSENSITIVE_RE.match(name):
339
339
  return name.upper()
340
340
  else:
341
- raise ValueError(f"Invalid name {name} passed. ID is not quoted and cannot normalized.")
341
+ raise ValueError(
342
+ f"{name} is not a valid SQL identifier: https://docs.snowflake.com/en/sql-reference/identifiers-syntax"
343
+ )
@@ -27,15 +27,11 @@ class SqlIdentifier(str):
27
27
  automatically added if necessary to make sure the original input's cases are preserved.
28
28
  Default to False.
29
29
 
30
- Raises:
31
- ValueError: input name is not a valid identifier.
32
-
33
30
  Returns:
34
31
  Returns new instance created.
35
32
  """
36
- # TODO (wezhou) add stronger validation to recognize a valid snowflake identifier.
37
- if not name:
38
- raise ValueError(f"name:`{name}` is not a valid identifier.")
33
+ assert name is not None
34
+
39
35
  if case_sensitive:
40
36
  return super().__new__(cls, identifier.get_inferred_name(name))
41
37
  else:
@@ -0,0 +1,10 @@
1
+ from .dataset import Dataset
2
+ from .dataset_factory import create_from_dataframe, load_dataset
3
+ from .dataset_reader import DatasetReader
4
+
5
+ __all__ = [
6
+ "Dataset",
7
+ "DatasetReader",
8
+ "create_from_dataframe",
9
+ "load_dataset",
10
+ ]