snowflake-ml-python 1.3.1__py3-none-any.whl → 1.4.1__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 (219) hide show
  1. snowflake/ml/_internal/env_utils.py +11 -1
  2. snowflake/ml/_internal/human_readable_id/adjectives.txt +128 -0
  3. snowflake/ml/_internal/human_readable_id/animals.txt +128 -0
  4. snowflake/ml/_internal/human_readable_id/hrid_generator.py +40 -0
  5. snowflake/ml/_internal/human_readable_id/hrid_generator_base.py +135 -0
  6. snowflake/ml/_internal/utils/formatting.py +1 -1
  7. snowflake/ml/_internal/utils/identifier.py +3 -1
  8. snowflake/ml/_internal/utils/sql_identifier.py +2 -6
  9. snowflake/ml/feature_store/feature_store.py +166 -184
  10. snowflake/ml/feature_store/feature_view.py +12 -24
  11. snowflake/ml/fileset/sfcfs.py +56 -50
  12. snowflake/ml/fileset/stage_fs.py +48 -13
  13. snowflake/ml/model/_client/model/model_version_impl.py +6 -49
  14. snowflake/ml/model/_client/ops/model_ops.py +78 -29
  15. snowflake/ml/model/_client/sql/model.py +23 -2
  16. snowflake/ml/model/_client/sql/model_version.py +22 -1
  17. snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +1 -3
  18. snowflake/ml/model/_deploy_client/snowservice/deploy.py +5 -2
  19. snowflake/ml/model/_model_composer/model_composer.py +7 -5
  20. snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +19 -54
  21. snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +8 -1
  22. snowflake/ml/model/_model_composer/model_method/infer_table_function.py_template +1 -1
  23. snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
  24. snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
  25. snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
  26. snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
  27. snowflake/ml/model/_packager/model_handlers/snowmlmodel.py +13 -1
  28. snowflake/ml/model/_packager/model_handlers/xgboost.py +1 -1
  29. snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
  30. snowflake/ml/model/_packager/model_meta/model_meta.py +36 -6
  31. snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
  32. snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
  33. snowflake/ml/model/_packager/model_packager.py +2 -2
  34. snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
  35. snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
  36. snowflake/ml/model/custom_model.py +3 -1
  37. snowflake/ml/model/type_hints.py +21 -2
  38. snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
  39. snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
  40. snowflake/ml/modeling/_internal/model_specifications.py +3 -1
  41. snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +545 -0
  42. snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +8 -5
  43. snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +195 -123
  44. snowflake/ml/modeling/cluster/affinity_propagation.py +195 -123
  45. snowflake/ml/modeling/cluster/agglomerative_clustering.py +195 -123
  46. snowflake/ml/modeling/cluster/birch.py +195 -123
  47. snowflake/ml/modeling/cluster/bisecting_k_means.py +195 -123
  48. snowflake/ml/modeling/cluster/dbscan.py +195 -123
  49. snowflake/ml/modeling/cluster/feature_agglomeration.py +195 -123
  50. snowflake/ml/modeling/cluster/k_means.py +195 -123
  51. snowflake/ml/modeling/cluster/mean_shift.py +195 -123
  52. snowflake/ml/modeling/cluster/mini_batch_k_means.py +195 -123
  53. snowflake/ml/modeling/cluster/optics.py +195 -123
  54. snowflake/ml/modeling/cluster/spectral_biclustering.py +195 -123
  55. snowflake/ml/modeling/cluster/spectral_clustering.py +195 -123
  56. snowflake/ml/modeling/cluster/spectral_coclustering.py +195 -123
  57. snowflake/ml/modeling/compose/column_transformer.py +195 -123
  58. snowflake/ml/modeling/compose/transformed_target_regressor.py +195 -123
  59. snowflake/ml/modeling/covariance/elliptic_envelope.py +195 -123
  60. snowflake/ml/modeling/covariance/empirical_covariance.py +195 -123
  61. snowflake/ml/modeling/covariance/graphical_lasso.py +195 -123
  62. snowflake/ml/modeling/covariance/graphical_lasso_cv.py +195 -123
  63. snowflake/ml/modeling/covariance/ledoit_wolf.py +195 -123
  64. snowflake/ml/modeling/covariance/min_cov_det.py +195 -123
  65. snowflake/ml/modeling/covariance/oas.py +195 -123
  66. snowflake/ml/modeling/covariance/shrunk_covariance.py +195 -123
  67. snowflake/ml/modeling/decomposition/dictionary_learning.py +195 -123
  68. snowflake/ml/modeling/decomposition/factor_analysis.py +195 -123
  69. snowflake/ml/modeling/decomposition/fast_ica.py +195 -123
  70. snowflake/ml/modeling/decomposition/incremental_pca.py +195 -123
  71. snowflake/ml/modeling/decomposition/kernel_pca.py +195 -123
  72. snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +195 -123
  73. snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +195 -123
  74. snowflake/ml/modeling/decomposition/pca.py +195 -123
  75. snowflake/ml/modeling/decomposition/sparse_pca.py +195 -123
  76. snowflake/ml/modeling/decomposition/truncated_svd.py +195 -123
  77. snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +195 -123
  78. snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +195 -123
  79. snowflake/ml/modeling/ensemble/ada_boost_classifier.py +195 -123
  80. snowflake/ml/modeling/ensemble/ada_boost_regressor.py +195 -123
  81. snowflake/ml/modeling/ensemble/bagging_classifier.py +195 -123
  82. snowflake/ml/modeling/ensemble/bagging_regressor.py +195 -123
  83. snowflake/ml/modeling/ensemble/extra_trees_classifier.py +195 -123
  84. snowflake/ml/modeling/ensemble/extra_trees_regressor.py +195 -123
  85. snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +195 -123
  86. snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +195 -123
  87. snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +195 -123
  88. snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +195 -123
  89. snowflake/ml/modeling/ensemble/isolation_forest.py +195 -123
  90. snowflake/ml/modeling/ensemble/random_forest_classifier.py +195 -123
  91. snowflake/ml/modeling/ensemble/random_forest_regressor.py +195 -123
  92. snowflake/ml/modeling/ensemble/stacking_regressor.py +195 -123
  93. snowflake/ml/modeling/ensemble/voting_classifier.py +195 -123
  94. snowflake/ml/modeling/ensemble/voting_regressor.py +195 -123
  95. snowflake/ml/modeling/feature_selection/generic_univariate_select.py +195 -123
  96. snowflake/ml/modeling/feature_selection/select_fdr.py +195 -123
  97. snowflake/ml/modeling/feature_selection/select_fpr.py +195 -123
  98. snowflake/ml/modeling/feature_selection/select_fwe.py +195 -123
  99. snowflake/ml/modeling/feature_selection/select_k_best.py +195 -123
  100. snowflake/ml/modeling/feature_selection/select_percentile.py +195 -123
  101. snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +195 -123
  102. snowflake/ml/modeling/feature_selection/variance_threshold.py +195 -123
  103. snowflake/ml/modeling/framework/_utils.py +8 -1
  104. snowflake/ml/modeling/framework/base.py +24 -6
  105. snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +195 -123
  106. snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +195 -123
  107. snowflake/ml/modeling/impute/iterative_imputer.py +195 -123
  108. snowflake/ml/modeling/impute/knn_imputer.py +195 -123
  109. snowflake/ml/modeling/impute/missing_indicator.py +195 -123
  110. snowflake/ml/modeling/impute/simple_imputer.py +4 -15
  111. snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +195 -123
  112. snowflake/ml/modeling/kernel_approximation/nystroem.py +195 -123
  113. snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +195 -123
  114. snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +195 -123
  115. snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +195 -123
  116. snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +195 -123
  117. snowflake/ml/modeling/lightgbm/lgbm_classifier.py +198 -125
  118. snowflake/ml/modeling/lightgbm/lgbm_regressor.py +198 -125
  119. snowflake/ml/modeling/linear_model/ard_regression.py +195 -123
  120. snowflake/ml/modeling/linear_model/bayesian_ridge.py +195 -123
  121. snowflake/ml/modeling/linear_model/elastic_net.py +195 -123
  122. snowflake/ml/modeling/linear_model/elastic_net_cv.py +195 -123
  123. snowflake/ml/modeling/linear_model/gamma_regressor.py +195 -123
  124. snowflake/ml/modeling/linear_model/huber_regressor.py +195 -123
  125. snowflake/ml/modeling/linear_model/lars.py +195 -123
  126. snowflake/ml/modeling/linear_model/lars_cv.py +195 -123
  127. snowflake/ml/modeling/linear_model/lasso.py +195 -123
  128. snowflake/ml/modeling/linear_model/lasso_cv.py +195 -123
  129. snowflake/ml/modeling/linear_model/lasso_lars.py +195 -123
  130. snowflake/ml/modeling/linear_model/lasso_lars_cv.py +195 -123
  131. snowflake/ml/modeling/linear_model/lasso_lars_ic.py +195 -123
  132. snowflake/ml/modeling/linear_model/linear_regression.py +195 -123
  133. snowflake/ml/modeling/linear_model/logistic_regression.py +195 -123
  134. snowflake/ml/modeling/linear_model/logistic_regression_cv.py +195 -123
  135. snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +195 -123
  136. snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +195 -123
  137. snowflake/ml/modeling/linear_model/multi_task_lasso.py +195 -123
  138. snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +195 -123
  139. snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +195 -123
  140. snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +195 -123
  141. snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +195 -123
  142. snowflake/ml/modeling/linear_model/perceptron.py +195 -123
  143. snowflake/ml/modeling/linear_model/poisson_regressor.py +195 -123
  144. snowflake/ml/modeling/linear_model/ransac_regressor.py +195 -123
  145. snowflake/ml/modeling/linear_model/ridge.py +195 -123
  146. snowflake/ml/modeling/linear_model/ridge_classifier.py +195 -123
  147. snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +195 -123
  148. snowflake/ml/modeling/linear_model/ridge_cv.py +195 -123
  149. snowflake/ml/modeling/linear_model/sgd_classifier.py +195 -123
  150. snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +195 -123
  151. snowflake/ml/modeling/linear_model/sgd_regressor.py +195 -123
  152. snowflake/ml/modeling/linear_model/theil_sen_regressor.py +195 -123
  153. snowflake/ml/modeling/linear_model/tweedie_regressor.py +195 -123
  154. snowflake/ml/modeling/manifold/isomap.py +195 -123
  155. snowflake/ml/modeling/manifold/mds.py +195 -123
  156. snowflake/ml/modeling/manifold/spectral_embedding.py +195 -123
  157. snowflake/ml/modeling/manifold/tsne.py +195 -123
  158. snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +195 -123
  159. snowflake/ml/modeling/mixture/gaussian_mixture.py +195 -123
  160. snowflake/ml/modeling/model_selection/grid_search_cv.py +42 -18
  161. snowflake/ml/modeling/model_selection/randomized_search_cv.py +42 -18
  162. snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +195 -123
  163. snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +195 -123
  164. snowflake/ml/modeling/multiclass/output_code_classifier.py +195 -123
  165. snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +195 -123
  166. snowflake/ml/modeling/naive_bayes/categorical_nb.py +195 -123
  167. snowflake/ml/modeling/naive_bayes/complement_nb.py +195 -123
  168. snowflake/ml/modeling/naive_bayes/gaussian_nb.py +195 -123
  169. snowflake/ml/modeling/naive_bayes/multinomial_nb.py +195 -123
  170. snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +195 -123
  171. snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +195 -123
  172. snowflake/ml/modeling/neighbors/kernel_density.py +195 -123
  173. snowflake/ml/modeling/neighbors/local_outlier_factor.py +195 -123
  174. snowflake/ml/modeling/neighbors/nearest_centroid.py +195 -123
  175. snowflake/ml/modeling/neighbors/nearest_neighbors.py +195 -123
  176. snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +195 -123
  177. snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +195 -123
  178. snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +195 -123
  179. snowflake/ml/modeling/neural_network/bernoulli_rbm.py +195 -123
  180. snowflake/ml/modeling/neural_network/mlp_classifier.py +195 -123
  181. snowflake/ml/modeling/neural_network/mlp_regressor.py +195 -123
  182. snowflake/ml/modeling/pipeline/pipeline.py +4 -4
  183. snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
  184. snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
  185. snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
  186. snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
  187. snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
  188. snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
  189. snowflake/ml/modeling/preprocessing/one_hot_encoder.py +1 -5
  190. snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
  191. snowflake/ml/modeling/preprocessing/polynomial_features.py +195 -123
  192. snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
  193. snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
  194. snowflake/ml/modeling/semi_supervised/label_propagation.py +195 -123
  195. snowflake/ml/modeling/semi_supervised/label_spreading.py +195 -123
  196. snowflake/ml/modeling/svm/linear_svc.py +195 -123
  197. snowflake/ml/modeling/svm/linear_svr.py +195 -123
  198. snowflake/ml/modeling/svm/nu_svc.py +195 -123
  199. snowflake/ml/modeling/svm/nu_svr.py +195 -123
  200. snowflake/ml/modeling/svm/svc.py +195 -123
  201. snowflake/ml/modeling/svm/svr.py +195 -123
  202. snowflake/ml/modeling/tree/decision_tree_classifier.py +195 -123
  203. snowflake/ml/modeling/tree/decision_tree_regressor.py +195 -123
  204. snowflake/ml/modeling/tree/extra_tree_classifier.py +195 -123
  205. snowflake/ml/modeling/tree/extra_tree_regressor.py +195 -123
  206. snowflake/ml/modeling/xgboost/xgb_classifier.py +195 -123
  207. snowflake/ml/modeling/xgboost/xgb_regressor.py +195 -123
  208. snowflake/ml/modeling/xgboost/xgbrf_classifier.py +195 -123
  209. snowflake/ml/modeling/xgboost/xgbrf_regressor.py +195 -123
  210. snowflake/ml/registry/_manager/model_manager.py +5 -1
  211. snowflake/ml/registry/model_registry.py +99 -26
  212. snowflake/ml/registry/registry.py +3 -2
  213. snowflake/ml/version.py +1 -1
  214. {snowflake_ml_python-1.3.1.dist-info → snowflake_ml_python-1.4.1.dist-info}/METADATA +94 -55
  215. {snowflake_ml_python-1.3.1.dist-info → snowflake_ml_python-1.4.1.dist-info}/RECORD +218 -212
  216. snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
  217. {snowflake_ml_python-1.3.1.dist-info → snowflake_ml_python-1.4.1.dist-info}/LICENSE.txt +0 -0
  218. {snowflake_ml_python-1.3.1.dist-info → snowflake_ml_python-1.4.1.dist-info}/WHEEL +0 -0
  219. {snowflake_ml_python-1.3.1.dist-info → snowflake_ml_python-1.4.1.dist-info}/top_level.txt +0 -0
@@ -18,7 +18,7 @@ from snowflake.ml._internal.exceptions import (
18
18
  exceptions as snowml_exceptions,
19
19
  )
20
20
  from snowflake.ml._internal.utils import query_result_checker
21
- from snowflake.snowpark import session
21
+ from snowflake.snowpark import context, exceptions, session
22
22
  from snowflake.snowpark._internal import utils as snowpark_utils
23
23
 
24
24
 
@@ -332,6 +332,16 @@ def get_matched_package_versions_in_snowflake_conda_channel(
332
332
  return matched_versions
333
333
 
334
334
 
335
+ def get_matched_package_versions_in_information_schema_with_active_session(
336
+ reqs: List[requirements.Requirement], python_version: str
337
+ ) -> Dict[str, List[version.Version]]:
338
+ try:
339
+ session = context.get_active_session()
340
+ except exceptions.SnowparkSessionException:
341
+ return {}
342
+ return get_matched_package_versions_in_information_schema(session, reqs, python_version)
343
+
344
+
335
345
  def get_matched_package_versions_in_information_schema(
336
346
  session: session.Session, reqs: List[requirements.Requirement], python_version: str
337
347
  ) -> Dict[str, List[version.Version]]:
@@ -0,0 +1,128 @@
1
+ afraid
2
+ ancient
3
+ angry
4
+ average
5
+ bad
6
+ big
7
+ bitter
8
+ black
9
+ blue
10
+ brave
11
+ breezy
12
+ bright
13
+ brown
14
+ calm
15
+ chatty
16
+ chilly
17
+ clever
18
+ cold
19
+ cowardly
20
+ cuddly
21
+ curly
22
+ curvy
23
+ dangerous
24
+ dry
25
+ dull
26
+ empty
27
+ evil
28
+ fast
29
+ fat
30
+ fluffy
31
+ foolish
32
+ fresh
33
+ friendly
34
+ funny
35
+ gentle
36
+ giant
37
+ good
38
+ great
39
+ green
40
+ grumpy
41
+ happy
42
+ hard
43
+ heavy
44
+ helpless
45
+ honest
46
+ horrible
47
+ hot
48
+ hungry
49
+ itchy
50
+ jolly
51
+ kind
52
+ lazy
53
+ light
54
+ little
55
+ loud
56
+ lovely
57
+ lucky
58
+ massive
59
+ mean
60
+ mighty
61
+ modern
62
+ moody
63
+ nasty
64
+ neat
65
+ nervous
66
+ new
67
+ nice
68
+ odd
69
+ old
70
+ orange
71
+ ordinary
72
+ perfect
73
+ pink
74
+ plastic
75
+ polite
76
+ popular
77
+ pretty
78
+ proud
79
+ purple
80
+ quick
81
+ quiet
82
+ rare
83
+ red
84
+ rotten
85
+ rude
86
+ selfish
87
+ serious
88
+ shaggy
89
+ sharp
90
+ short
91
+ shy
92
+ silent
93
+ silly
94
+ slimy
95
+ slippery
96
+ smart
97
+ smooth
98
+ soft
99
+ sour
100
+ spicy
101
+ splendid
102
+ spotty
103
+ stale
104
+ strange
105
+ strong
106
+ stupid
107
+ sweet
108
+ swift
109
+ tall
110
+ tame
111
+ tasty
112
+ tender
113
+ terrible
114
+ thin
115
+ tidy
116
+ tiny
117
+ tough
118
+ tricky
119
+ ugly
120
+ warm
121
+ weak
122
+ wet
123
+ wicked
124
+ wise
125
+ witty
126
+ wonderful
127
+ yellow
128
+ young
@@ -0,0 +1,128 @@
1
+ anaconda
2
+ ant
3
+ ape
4
+ baboon
5
+ badger
6
+ bat
7
+ bear
8
+ bird
9
+ bobcat
10
+ bulldog
11
+ bullfrog
12
+ camel
13
+ canary
14
+ capybara
15
+ cat
16
+ catfish
17
+ cheetah
18
+ chicken
19
+ chipmunk
20
+ cobra
21
+ cougar
22
+ cow
23
+ crab
24
+ deer
25
+ dingo
26
+ dodo
27
+ dog
28
+ dolphin
29
+ donkey
30
+ dragon
31
+ dragonfly
32
+ duck
33
+ eagle
34
+ earwig
35
+ eel
36
+ egret
37
+ elephant
38
+ emu
39
+ falcon
40
+ fireant
41
+ firefox
42
+ fish
43
+ fly
44
+ fox
45
+ frog
46
+ gazelle
47
+ gecko
48
+ gibbon
49
+ giraffe
50
+ goat
51
+ goose
52
+ gorilla
53
+ grasshopper
54
+ horse
55
+ hound
56
+ husky
57
+ impala
58
+ insect
59
+ jackal
60
+ jaguar
61
+ jellyfish
62
+ kangaroo
63
+ kiwi
64
+ ladybug
65
+ leech
66
+ leopard
67
+ llama
68
+ liger
69
+ lion
70
+ lionfish
71
+ lizard
72
+ lobster
73
+ mayfly
74
+ mamba
75
+ mole
76
+ monkey
77
+ moose
78
+ moth
79
+ mouse
80
+ mule
81
+ newt
82
+ octopus
83
+ otter
84
+ owl
85
+ panda
86
+ panther
87
+ parrot
88
+ penguin
89
+ pig
90
+ puma
91
+ pug
92
+ python
93
+ quail
94
+ rabbit
95
+ ram
96
+ rat
97
+ ray
98
+ rattlesnake
99
+ robin
100
+ salmon
101
+ seahorse
102
+ seal
103
+ shark
104
+ sheep
105
+ shrimp
106
+ skunk
107
+ sloth
108
+ snail
109
+ snake
110
+ squid
111
+ starfish
112
+ stingray
113
+ swan
114
+ termite
115
+ tiger
116
+ treefrog
117
+ turkey
118
+ turtle
119
+ vampirebat
120
+ walrus
121
+ warthog
122
+ wasp
123
+ wolverine
124
+ wombat
125
+ worm
126
+ yak
127
+ yeti
128
+ zebra
@@ -0,0 +1,40 @@
1
+ """Implement a generator for human readable ID (HRID).
2
+
3
+ The original idea for this comes from Asana where it is documented on their
4
+ blog:
5
+ http://blog.asana.com/2011/09/6-sad-squid-snuggle-softly/
6
+
7
+ There are other partial implementations of this and can be found here:
8
+ Node.js: https://github.com/linus/greg
9
+ Java: https://github.com/PerWiklander/IdentifierSentence
10
+
11
+ In this module you will find:
12
+
13
+ HRID16: An implementation of HRIDBase for 16 bit integers.
14
+
15
+ The list used here is coming from:
16
+ https://git.coolaj86.com/coolaj86/human-readable-ids.js
17
+ """
18
+
19
+ import random
20
+
21
+ import importlib_resources
22
+
23
+ from snowflake.ml._internal import human_readable_id
24
+ from snowflake.ml._internal.human_readable_id import hrid_generator_base
25
+
26
+
27
+ class HRID16(hrid_generator_base.HRIDBase):
28
+ """An implementation of HRIDBase for 16 bit integers."""
29
+
30
+ def __id_generator__(self) -> int:
31
+ return int(random.getrandbits(16))
32
+
33
+ __hrid_structure__ = ("adjective", "animal", "number")
34
+ __hrid_words__ = dict(
35
+ number=tuple(str(x) for x in range(1, 5)),
36
+ adjective=tuple(
37
+ importlib_resources.files(human_readable_id).joinpath("adjectives.txt").read_text("utf-8").split()
38
+ ),
39
+ animal=tuple(importlib_resources.files(human_readable_id).joinpath("animals.txt").read_text("utf-8").split()),
40
+ )
@@ -0,0 +1,135 @@
1
+ """Implement a generator for human readable ID (HRID).
2
+
3
+ The original idea for this comes from Asana where it is documented on their
4
+ blog:
5
+ http://blog.asana.com/2011/09/6-sad-squid-snuggle-softly/
6
+
7
+ There are other partial implementations of this and can be found here:
8
+ Node.js: https://github.com/linus/greg
9
+ Java: https://github.com/PerWiklander/IdentifierSentence
10
+
11
+ In this module you will find:
12
+
13
+ HRIDBase: The base class for all human readable id.
14
+ """
15
+
16
+ import math
17
+ from abc import ABC, abstractmethod
18
+ from typing import Dict, List, Tuple
19
+
20
+
21
+ class HRIDBase(ABC):
22
+ """The base class for all all human readable id.
23
+
24
+ This provides all of the necessary helper functionality to turn IDs into
25
+ HRIDs and HRIDs into IDs. ID typically is a random int, while HRID is a corresponding short string.
26
+ """
27
+
28
+ @abstractmethod
29
+ def __id_generator__(self) -> int:
30
+ """The generator to use to generate new IDs. The implementer needs to provide this."""
31
+ pass
32
+
33
+ __hrid_structure__: Tuple[str, ...]
34
+ """The HRID structure to be generated. The implementer needs to provide this."""
35
+
36
+ __hrid_words__: Dict[str, Tuple[str, ...]]
37
+ """The mapping between the HRID parts and the words to use. The implementer needs to provide this."""
38
+
39
+ __separator__ = "_"
40
+
41
+ def __init__(self) -> None:
42
+ self._part_n_words = dict()
43
+ self._part_bits = dict()
44
+ for part in self.__hrid_structure__:
45
+ n_words = len(self.__hrid_words__[part])
46
+ self._part_n_words[part] = n_words
47
+ if not (n_words > 0 and ((n_words & (n_words - 1)) == 0)):
48
+ raise ValueError(f"{part} part has {n_words} words, which is not a power of 2")
49
+ self._part_bits[part] = int(math.log(self._part_n_words[part], 2))
50
+ self.__total_bits__ = sum(v for v in self._part_bits.values())
51
+
52
+ def hrid_to_id(self, hrid: str) -> int:
53
+ """Take the HRID and convert it the ID.
54
+
55
+ Args:
56
+ hrid: The HRID to convert into an ID
57
+
58
+ Returns:
59
+ The ID represented by the HRID
60
+ """
61
+ idxs = self._hrid_to_idxs(hrid)
62
+ id = 0
63
+ for i in range(len(idxs)):
64
+ part = self.__hrid_structure__[i]
65
+ id = (id << self._part_bits[part]) + idxs[i]
66
+ return id
67
+
68
+ def id_to_hrid(self, id: int) -> str:
69
+ """Take the ID and convert it a HRID.
70
+
71
+ Args:
72
+ id: The ID to convert into a HRID
73
+
74
+ Returns:
75
+ The HRID represented by the ID
76
+ """
77
+ idxs = self._id_to_idxs(id)
78
+ hrid = []
79
+ for i in range(len(self.__hrid_structure__)):
80
+ part = self.__hrid_structure__[i]
81
+ values = self.__hrid_words__[part]
82
+ hrid.append(str(values[idxs[i]]))
83
+ return self.__separator__.join(hrid)
84
+
85
+ def generate(self) -> Tuple[int, str]:
86
+ """Generate an ID and the corresponding HRID.
87
+
88
+ Returns:
89
+ A tuple containing the id and the HRID
90
+ """
91
+ id = self.__id_generator__()
92
+ hrid = self.id_to_hrid(id)
93
+ return (id, hrid)
94
+
95
+ def _id_to_idxs(self, id: int) -> List[int]:
96
+ """Take the ID and convert it to indices into the HRID words.
97
+
98
+ Args:
99
+ id: The ID to convert into indices
100
+
101
+ Returns:
102
+ A list of indices into the HRID words
103
+ """
104
+ shift = self.__total_bits__
105
+ idxs = []
106
+ for part in self.__hrid_structure__:
107
+ shift -= self._part_bits[part]
108
+ mask = (self._part_n_words[part] - 1) << shift
109
+ idxs.append((id & mask) >> shift)
110
+ return idxs
111
+
112
+ def _hrid_to_idxs(self, hrid: str) -> List[int]:
113
+ """Take the HRID and convert it to indices into the HRID words.
114
+
115
+ Args:
116
+ hrid: The HRID to convert into indices
117
+
118
+ Raises:
119
+ ValueError: Raised when the input does not meet the structure.
120
+
121
+ Returns:
122
+ A list of indices into the HRID words
123
+ """
124
+ split_hrid = hrid.split(self.__separator__)
125
+ if len(split_hrid) != len(self.__hrid_structure__):
126
+ raise ValueError(
127
+ ("The hrid must have {} parts and be of the form {}").format(
128
+ len(self.__hrid_structure__), self.__hrid_structure__
129
+ )
130
+ )
131
+ idxs = []
132
+ for i in range(len(self.__hrid_structure__)):
133
+ part = self.__hrid_structure__[i]
134
+ idxs.append(self.__hrid_words__[part].index(split_hrid[i]))
135
+ return idxs
@@ -1,7 +1,7 @@
1
1
  """String formatting utilities for general use in the SnowML Reposiory.
2
2
 
3
3
  This file contains a collection of utilities that help with formatting strings. Functionality is not limited to tests
4
- only. Anything that is re-usable across different modules and related to string formatting should go here.
4
+ only. Anything that is reusable across different modules and related to string formatting should go here.
5
5
  """
6
6
 
7
7
  import re
@@ -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: