snowpark-connect 0.20.2__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 snowpark-connect might be problematic. Click here for more details.

Files changed (879) hide show
  1. snowflake/snowpark_connect/__init__.py +23 -0
  2. snowflake/snowpark_connect/analyze_plan/__init__.py +3 -0
  3. snowflake/snowpark_connect/analyze_plan/map_tree_string.py +38 -0
  4. snowflake/snowpark_connect/column_name_handler.py +735 -0
  5. snowflake/snowpark_connect/config.py +576 -0
  6. snowflake/snowpark_connect/constants.py +47 -0
  7. snowflake/snowpark_connect/control_server.py +52 -0
  8. snowflake/snowpark_connect/dataframe_name_handler.py +54 -0
  9. snowflake/snowpark_connect/date_time_format_mapping.py +399 -0
  10. snowflake/snowpark_connect/empty_dataframe.py +18 -0
  11. snowflake/snowpark_connect/error/__init__.py +11 -0
  12. snowflake/snowpark_connect/error/error_mapping.py +6174 -0
  13. snowflake/snowpark_connect/error/error_utils.py +321 -0
  14. snowflake/snowpark_connect/error/exceptions.py +24 -0
  15. snowflake/snowpark_connect/execute_plan/__init__.py +3 -0
  16. snowflake/snowpark_connect/execute_plan/map_execution_command.py +204 -0
  17. snowflake/snowpark_connect/execute_plan/map_execution_root.py +173 -0
  18. snowflake/snowpark_connect/execute_plan/utils.py +183 -0
  19. snowflake/snowpark_connect/expression/__init__.py +3 -0
  20. snowflake/snowpark_connect/expression/literal.py +90 -0
  21. snowflake/snowpark_connect/expression/map_cast.py +343 -0
  22. snowflake/snowpark_connect/expression/map_expression.py +293 -0
  23. snowflake/snowpark_connect/expression/map_extension.py +104 -0
  24. snowflake/snowpark_connect/expression/map_sql_expression.py +633 -0
  25. snowflake/snowpark_connect/expression/map_udf.py +142 -0
  26. snowflake/snowpark_connect/expression/map_unresolved_attribute.py +241 -0
  27. snowflake/snowpark_connect/expression/map_unresolved_extract_value.py +85 -0
  28. snowflake/snowpark_connect/expression/map_unresolved_function.py +9450 -0
  29. snowflake/snowpark_connect/expression/map_unresolved_star.py +218 -0
  30. snowflake/snowpark_connect/expression/map_update_fields.py +164 -0
  31. snowflake/snowpark_connect/expression/map_window_function.py +258 -0
  32. snowflake/snowpark_connect/expression/typer.py +125 -0
  33. snowflake/snowpark_connect/includes/__init__.py +0 -0
  34. snowflake/snowpark_connect/includes/jars/antlr4-runtime-4.9.3.jar +0 -0
  35. snowflake/snowpark_connect/includes/jars/commons-cli-1.5.0.jar +0 -0
  36. snowflake/snowpark_connect/includes/jars/commons-codec-1.16.1.jar +0 -0
  37. snowflake/snowpark_connect/includes/jars/commons-collections-3.2.2.jar +0 -0
  38. snowflake/snowpark_connect/includes/jars/commons-collections4-4.4.jar +0 -0
  39. snowflake/snowpark_connect/includes/jars/commons-compiler-3.1.9.jar +0 -0
  40. snowflake/snowpark_connect/includes/jars/commons-compress-1.26.0.jar +0 -0
  41. snowflake/snowpark_connect/includes/jars/commons-crypto-1.1.0.jar +0 -0
  42. snowflake/snowpark_connect/includes/jars/commons-dbcp-1.4.jar +0 -0
  43. snowflake/snowpark_connect/includes/jars/commons-io-2.16.1.jar +0 -0
  44. snowflake/snowpark_connect/includes/jars/commons-lang-2.6.jar +0 -0
  45. snowflake/snowpark_connect/includes/jars/commons-lang3-3.12.0.jar +0 -0
  46. snowflake/snowpark_connect/includes/jars/commons-logging-1.1.3.jar +0 -0
  47. snowflake/snowpark_connect/includes/jars/commons-math3-3.6.1.jar +0 -0
  48. snowflake/snowpark_connect/includes/jars/commons-pool-1.5.4.jar +0 -0
  49. snowflake/snowpark_connect/includes/jars/commons-text-1.10.0.jar +0 -0
  50. snowflake/snowpark_connect/includes/jars/hadoop-client-api-3.3.4.jar +0 -0
  51. snowflake/snowpark_connect/includes/jars/jackson-annotations-2.15.2.jar +0 -0
  52. snowflake/snowpark_connect/includes/jars/jackson-core-2.15.2.jar +0 -0
  53. snowflake/snowpark_connect/includes/jars/jackson-core-asl-1.9.13.jar +0 -0
  54. snowflake/snowpark_connect/includes/jars/jackson-databind-2.15.2.jar +0 -0
  55. snowflake/snowpark_connect/includes/jars/jackson-dataformat-yaml-2.15.2.jar +0 -0
  56. snowflake/snowpark_connect/includes/jars/jackson-datatype-jsr310-2.15.2.jar +0 -0
  57. snowflake/snowpark_connect/includes/jars/jackson-mapper-asl-1.9.13.jar +0 -0
  58. snowflake/snowpark_connect/includes/jars/jackson-module-scala_2.12-2.15.2.jar +0 -0
  59. snowflake/snowpark_connect/includes/jars/json4s-ast_2.12-3.7.0-M11.jar +0 -0
  60. snowflake/snowpark_connect/includes/jars/json4s-core_2.12-3.7.0-M11.jar +0 -0
  61. snowflake/snowpark_connect/includes/jars/json4s-jackson_2.12-3.7.0-M11.jar +0 -0
  62. snowflake/snowpark_connect/includes/jars/json4s-scalap_2.12-3.7.0-M11.jar +0 -0
  63. snowflake/snowpark_connect/includes/jars/kryo-shaded-4.0.2.jar +0 -0
  64. snowflake/snowpark_connect/includes/jars/log4j-1.2-api-2.20.0.jar +0 -0
  65. snowflake/snowpark_connect/includes/jars/log4j-api-2.20.0.jar +0 -0
  66. snowflake/snowpark_connect/includes/jars/log4j-core-2.20.0.jar +0 -0
  67. snowflake/snowpark_connect/includes/jars/log4j-slf4j2-impl-2.20.0.jar +0 -0
  68. snowflake/snowpark_connect/includes/jars/paranamer-2.8.jar +0 -0
  69. snowflake/snowpark_connect/includes/jars/scala-collection-compat_2.12-2.7.0.jar +0 -0
  70. snowflake/snowpark_connect/includes/jars/scala-compiler-2.12.18.jar +0 -0
  71. snowflake/snowpark_connect/includes/jars/scala-library-2.12.18.jar +0 -0
  72. snowflake/snowpark_connect/includes/jars/scala-parser-combinators_2.12-2.3.0.jar +0 -0
  73. snowflake/snowpark_connect/includes/jars/scala-reflect-2.12.18.jar +0 -0
  74. snowflake/snowpark_connect/includes/jars/scala-xml_2.12-2.1.0.jar +0 -0
  75. snowflake/snowpark_connect/includes/jars/slf4j-api-2.0.7.jar +0 -0
  76. snowflake/snowpark_connect/includes/jars/spark-catalyst_2.12-3.5.6.jar +0 -0
  77. snowflake/snowpark_connect/includes/jars/spark-common-utils_2.12-3.5.6.jar +0 -0
  78. snowflake/snowpark_connect/includes/jars/spark-core_2.12-3.5.6.jar +0 -0
  79. snowflake/snowpark_connect/includes/jars/spark-graphx_2.12-3.5.6.jar +0 -0
  80. snowflake/snowpark_connect/includes/jars/spark-hive-thriftserver_2.12-3.5.6.jar +0 -0
  81. snowflake/snowpark_connect/includes/jars/spark-hive_2.12-3.5.6.jar +0 -0
  82. snowflake/snowpark_connect/includes/jars/spark-kubernetes_2.12-3.5.6.jar +0 -0
  83. snowflake/snowpark_connect/includes/jars/spark-kvstore_2.12-3.5.6.jar +0 -0
  84. snowflake/snowpark_connect/includes/jars/spark-launcher_2.12-3.5.6.jar +0 -0
  85. snowflake/snowpark_connect/includes/jars/spark-mesos_2.12-3.5.6.jar +0 -0
  86. snowflake/snowpark_connect/includes/jars/spark-mllib-local_2.12-3.5.6.jar +0 -0
  87. snowflake/snowpark_connect/includes/jars/spark-mllib_2.12-3.5.6.jar +0 -0
  88. snowflake/snowpark_connect/includes/jars/spark-network-common_2.12-3.5.6.jar +0 -0
  89. snowflake/snowpark_connect/includes/jars/spark-network-shuffle_2.12-3.5.6.jar +0 -0
  90. snowflake/snowpark_connect/includes/jars/spark-repl_2.12-3.5.6.jar +0 -0
  91. snowflake/snowpark_connect/includes/jars/spark-sketch_2.12-3.5.6.jar +0 -0
  92. snowflake/snowpark_connect/includes/jars/spark-sql-api_2.12-3.5.6.jar +0 -0
  93. snowflake/snowpark_connect/includes/jars/spark-sql_2.12-3.5.6.jar +0 -0
  94. snowflake/snowpark_connect/includes/jars/spark-streaming_2.12-3.5.6.jar +0 -0
  95. snowflake/snowpark_connect/includes/jars/spark-tags_2.12-3.5.6.jar +0 -0
  96. snowflake/snowpark_connect/includes/jars/spark-unsafe_2.12-3.5.6.jar +0 -0
  97. snowflake/snowpark_connect/includes/jars/spark-yarn_2.12-3.5.6.jar +0 -0
  98. snowflake/snowpark_connect/includes/python/__init__.py +21 -0
  99. snowflake/snowpark_connect/includes/python/pyspark/__init__.py +173 -0
  100. snowflake/snowpark_connect/includes/python/pyspark/_globals.py +71 -0
  101. snowflake/snowpark_connect/includes/python/pyspark/_typing.pyi +43 -0
  102. snowflake/snowpark_connect/includes/python/pyspark/accumulators.py +341 -0
  103. snowflake/snowpark_connect/includes/python/pyspark/broadcast.py +383 -0
  104. snowflake/snowpark_connect/includes/python/pyspark/cloudpickle/__init__.py +8 -0
  105. snowflake/snowpark_connect/includes/python/pyspark/cloudpickle/cloudpickle.py +948 -0
  106. snowflake/snowpark_connect/includes/python/pyspark/cloudpickle/cloudpickle_fast.py +844 -0
  107. snowflake/snowpark_connect/includes/python/pyspark/cloudpickle/compat.py +18 -0
  108. snowflake/snowpark_connect/includes/python/pyspark/conf.py +276 -0
  109. snowflake/snowpark_connect/includes/python/pyspark/context.py +2601 -0
  110. snowflake/snowpark_connect/includes/python/pyspark/daemon.py +218 -0
  111. snowflake/snowpark_connect/includes/python/pyspark/errors/__init__.py +70 -0
  112. snowflake/snowpark_connect/includes/python/pyspark/errors/error_classes.py +889 -0
  113. snowflake/snowpark_connect/includes/python/pyspark/errors/exceptions/__init__.py +16 -0
  114. snowflake/snowpark_connect/includes/python/pyspark/errors/exceptions/base.py +228 -0
  115. snowflake/snowpark_connect/includes/python/pyspark/errors/exceptions/captured.py +307 -0
  116. snowflake/snowpark_connect/includes/python/pyspark/errors/exceptions/connect.py +190 -0
  117. snowflake/snowpark_connect/includes/python/pyspark/errors/tests/__init__.py +16 -0
  118. snowflake/snowpark_connect/includes/python/pyspark/errors/tests/test_errors.py +60 -0
  119. snowflake/snowpark_connect/includes/python/pyspark/errors/utils.py +116 -0
  120. snowflake/snowpark_connect/includes/python/pyspark/files.py +165 -0
  121. snowflake/snowpark_connect/includes/python/pyspark/find_spark_home.py +95 -0
  122. snowflake/snowpark_connect/includes/python/pyspark/install.py +203 -0
  123. snowflake/snowpark_connect/includes/python/pyspark/instrumentation_utils.py +190 -0
  124. snowflake/snowpark_connect/includes/python/pyspark/java_gateway.py +248 -0
  125. snowflake/snowpark_connect/includes/python/pyspark/join.py +118 -0
  126. snowflake/snowpark_connect/includes/python/pyspark/ml/__init__.py +71 -0
  127. snowflake/snowpark_connect/includes/python/pyspark/ml/_typing.pyi +84 -0
  128. snowflake/snowpark_connect/includes/python/pyspark/ml/base.py +414 -0
  129. snowflake/snowpark_connect/includes/python/pyspark/ml/classification.py +4332 -0
  130. snowflake/snowpark_connect/includes/python/pyspark/ml/clustering.py +2188 -0
  131. snowflake/snowpark_connect/includes/python/pyspark/ml/common.py +146 -0
  132. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/__init__.py +44 -0
  133. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/base.py +346 -0
  134. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/classification.py +382 -0
  135. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/evaluation.py +291 -0
  136. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/feature.py +258 -0
  137. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/functions.py +77 -0
  138. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/io_utils.py +335 -0
  139. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/pipeline.py +262 -0
  140. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/summarizer.py +120 -0
  141. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/tuning.py +579 -0
  142. snowflake/snowpark_connect/includes/python/pyspark/ml/connect/util.py +173 -0
  143. snowflake/snowpark_connect/includes/python/pyspark/ml/deepspeed/__init__.py +16 -0
  144. snowflake/snowpark_connect/includes/python/pyspark/ml/deepspeed/deepspeed_distributor.py +165 -0
  145. snowflake/snowpark_connect/includes/python/pyspark/ml/deepspeed/tests/test_deepspeed_distributor.py +306 -0
  146. snowflake/snowpark_connect/includes/python/pyspark/ml/dl_util.py +150 -0
  147. snowflake/snowpark_connect/includes/python/pyspark/ml/evaluation.py +1166 -0
  148. snowflake/snowpark_connect/includes/python/pyspark/ml/feature.py +7474 -0
  149. snowflake/snowpark_connect/includes/python/pyspark/ml/fpm.py +543 -0
  150. snowflake/snowpark_connect/includes/python/pyspark/ml/functions.py +842 -0
  151. snowflake/snowpark_connect/includes/python/pyspark/ml/image.py +271 -0
  152. snowflake/snowpark_connect/includes/python/pyspark/ml/linalg/__init__.py +1382 -0
  153. snowflake/snowpark_connect/includes/python/pyspark/ml/model_cache.py +55 -0
  154. snowflake/snowpark_connect/includes/python/pyspark/ml/param/__init__.py +602 -0
  155. snowflake/snowpark_connect/includes/python/pyspark/ml/param/_shared_params_code_gen.py +368 -0
  156. snowflake/snowpark_connect/includes/python/pyspark/ml/param/shared.py +878 -0
  157. snowflake/snowpark_connect/includes/python/pyspark/ml/pipeline.py +451 -0
  158. snowflake/snowpark_connect/includes/python/pyspark/ml/recommendation.py +748 -0
  159. snowflake/snowpark_connect/includes/python/pyspark/ml/regression.py +3335 -0
  160. snowflake/snowpark_connect/includes/python/pyspark/ml/stat.py +523 -0
  161. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/__init__.py +16 -0
  162. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_classification.py +53 -0
  163. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_evaluation.py +50 -0
  164. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_feature.py +43 -0
  165. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_function.py +114 -0
  166. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_pipeline.py +47 -0
  167. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_summarizer.py +43 -0
  168. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_connect_tuning.py +46 -0
  169. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_classification.py +238 -0
  170. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_evaluation.py +194 -0
  171. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_feature.py +156 -0
  172. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_pipeline.py +184 -0
  173. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_summarizer.py +78 -0
  174. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_legacy_mode_tuning.py +292 -0
  175. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_parity_torch_data_loader.py +50 -0
  176. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/connect/test_parity_torch_distributor.py +152 -0
  177. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_algorithms.py +456 -0
  178. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_base.py +96 -0
  179. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_dl_util.py +186 -0
  180. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_evaluation.py +77 -0
  181. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_feature.py +401 -0
  182. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_functions.py +528 -0
  183. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_image.py +82 -0
  184. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_linalg.py +409 -0
  185. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_model_cache.py +55 -0
  186. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_param.py +441 -0
  187. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_persistence.py +546 -0
  188. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_pipeline.py +71 -0
  189. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_stat.py +52 -0
  190. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_training_summary.py +494 -0
  191. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_util.py +85 -0
  192. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/test_wrapper.py +138 -0
  193. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/__init__.py +16 -0
  194. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_cv_io_basic.py +151 -0
  195. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_cv_io_nested.py +97 -0
  196. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_cv_io_pipeline.py +143 -0
  197. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_tuning.py +551 -0
  198. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_tvs_io_basic.py +137 -0
  199. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_tvs_io_nested.py +96 -0
  200. snowflake/snowpark_connect/includes/python/pyspark/ml/tests/tuning/test_tvs_io_pipeline.py +142 -0
  201. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/__init__.py +16 -0
  202. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/data.py +100 -0
  203. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/distributor.py +1133 -0
  204. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/log_communication.py +198 -0
  205. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/tests/__init__.py +16 -0
  206. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/tests/test_data_loader.py +137 -0
  207. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/tests/test_distributor.py +561 -0
  208. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/tests/test_log_communication.py +172 -0
  209. snowflake/snowpark_connect/includes/python/pyspark/ml/torch/torch_run_process_wrapper.py +83 -0
  210. snowflake/snowpark_connect/includes/python/pyspark/ml/tree.py +434 -0
  211. snowflake/snowpark_connect/includes/python/pyspark/ml/tuning.py +1741 -0
  212. snowflake/snowpark_connect/includes/python/pyspark/ml/util.py +749 -0
  213. snowflake/snowpark_connect/includes/python/pyspark/ml/wrapper.py +465 -0
  214. snowflake/snowpark_connect/includes/python/pyspark/mllib/__init__.py +44 -0
  215. snowflake/snowpark_connect/includes/python/pyspark/mllib/_typing.pyi +33 -0
  216. snowflake/snowpark_connect/includes/python/pyspark/mllib/classification.py +989 -0
  217. snowflake/snowpark_connect/includes/python/pyspark/mllib/clustering.py +1318 -0
  218. snowflake/snowpark_connect/includes/python/pyspark/mllib/common.py +174 -0
  219. snowflake/snowpark_connect/includes/python/pyspark/mllib/evaluation.py +691 -0
  220. snowflake/snowpark_connect/includes/python/pyspark/mllib/feature.py +1085 -0
  221. snowflake/snowpark_connect/includes/python/pyspark/mllib/fpm.py +233 -0
  222. snowflake/snowpark_connect/includes/python/pyspark/mllib/linalg/__init__.py +1653 -0
  223. snowflake/snowpark_connect/includes/python/pyspark/mllib/linalg/distributed.py +1662 -0
  224. snowflake/snowpark_connect/includes/python/pyspark/mllib/random.py +698 -0
  225. snowflake/snowpark_connect/includes/python/pyspark/mllib/recommendation.py +389 -0
  226. snowflake/snowpark_connect/includes/python/pyspark/mllib/regression.py +1067 -0
  227. snowflake/snowpark_connect/includes/python/pyspark/mllib/stat/KernelDensity.py +59 -0
  228. snowflake/snowpark_connect/includes/python/pyspark/mllib/stat/__init__.py +34 -0
  229. snowflake/snowpark_connect/includes/python/pyspark/mllib/stat/_statistics.py +409 -0
  230. snowflake/snowpark_connect/includes/python/pyspark/mllib/stat/distribution.py +39 -0
  231. snowflake/snowpark_connect/includes/python/pyspark/mllib/stat/test.py +86 -0
  232. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/__init__.py +16 -0
  233. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_algorithms.py +353 -0
  234. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_feature.py +192 -0
  235. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_linalg.py +680 -0
  236. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_stat.py +206 -0
  237. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_streaming_algorithms.py +471 -0
  238. snowflake/snowpark_connect/includes/python/pyspark/mllib/tests/test_util.py +108 -0
  239. snowflake/snowpark_connect/includes/python/pyspark/mllib/tree.py +888 -0
  240. snowflake/snowpark_connect/includes/python/pyspark/mllib/util.py +659 -0
  241. snowflake/snowpark_connect/includes/python/pyspark/pandas/__init__.py +165 -0
  242. snowflake/snowpark_connect/includes/python/pyspark/pandas/_typing.py +52 -0
  243. snowflake/snowpark_connect/includes/python/pyspark/pandas/accessors.py +989 -0
  244. snowflake/snowpark_connect/includes/python/pyspark/pandas/base.py +1804 -0
  245. snowflake/snowpark_connect/includes/python/pyspark/pandas/categorical.py +822 -0
  246. snowflake/snowpark_connect/includes/python/pyspark/pandas/config.py +539 -0
  247. snowflake/snowpark_connect/includes/python/pyspark/pandas/correlation.py +262 -0
  248. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/__init__.py +16 -0
  249. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/base.py +519 -0
  250. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/binary_ops.py +98 -0
  251. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/boolean_ops.py +426 -0
  252. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/categorical_ops.py +141 -0
  253. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/complex_ops.py +145 -0
  254. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/date_ops.py +127 -0
  255. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/datetime_ops.py +171 -0
  256. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/null_ops.py +83 -0
  257. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/num_ops.py +588 -0
  258. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/string_ops.py +154 -0
  259. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/timedelta_ops.py +101 -0
  260. snowflake/snowpark_connect/includes/python/pyspark/pandas/data_type_ops/udt_ops.py +29 -0
  261. snowflake/snowpark_connect/includes/python/pyspark/pandas/datetimes.py +891 -0
  262. snowflake/snowpark_connect/includes/python/pyspark/pandas/exceptions.py +150 -0
  263. snowflake/snowpark_connect/includes/python/pyspark/pandas/extensions.py +388 -0
  264. snowflake/snowpark_connect/includes/python/pyspark/pandas/frame.py +13738 -0
  265. snowflake/snowpark_connect/includes/python/pyspark/pandas/generic.py +3560 -0
  266. snowflake/snowpark_connect/includes/python/pyspark/pandas/groupby.py +4448 -0
  267. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/__init__.py +21 -0
  268. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/base.py +2783 -0
  269. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/category.py +773 -0
  270. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/datetimes.py +843 -0
  271. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/multi.py +1323 -0
  272. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/numeric.py +210 -0
  273. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexes/timedelta.py +197 -0
  274. snowflake/snowpark_connect/includes/python/pyspark/pandas/indexing.py +1862 -0
  275. snowflake/snowpark_connect/includes/python/pyspark/pandas/internal.py +1680 -0
  276. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/__init__.py +48 -0
  277. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/common.py +76 -0
  278. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/frame.py +63 -0
  279. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/general_functions.py +43 -0
  280. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/groupby.py +93 -0
  281. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/indexes.py +184 -0
  282. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/resample.py +101 -0
  283. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/scalars.py +29 -0
  284. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/series.py +69 -0
  285. snowflake/snowpark_connect/includes/python/pyspark/pandas/missing/window.py +168 -0
  286. snowflake/snowpark_connect/includes/python/pyspark/pandas/mlflow.py +238 -0
  287. snowflake/snowpark_connect/includes/python/pyspark/pandas/namespace.py +3807 -0
  288. snowflake/snowpark_connect/includes/python/pyspark/pandas/numpy_compat.py +260 -0
  289. snowflake/snowpark_connect/includes/python/pyspark/pandas/plot/__init__.py +17 -0
  290. snowflake/snowpark_connect/includes/python/pyspark/pandas/plot/core.py +1213 -0
  291. snowflake/snowpark_connect/includes/python/pyspark/pandas/plot/matplotlib.py +928 -0
  292. snowflake/snowpark_connect/includes/python/pyspark/pandas/plot/plotly.py +261 -0
  293. snowflake/snowpark_connect/includes/python/pyspark/pandas/resample.py +816 -0
  294. snowflake/snowpark_connect/includes/python/pyspark/pandas/series.py +7440 -0
  295. snowflake/snowpark_connect/includes/python/pyspark/pandas/sql_formatter.py +308 -0
  296. snowflake/snowpark_connect/includes/python/pyspark/pandas/sql_processor.py +394 -0
  297. snowflake/snowpark_connect/includes/python/pyspark/pandas/strings.py +2371 -0
  298. snowflake/snowpark_connect/includes/python/pyspark/pandas/supported_api_gen.py +378 -0
  299. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/__init__.py +16 -0
  300. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/__init__.py +16 -0
  301. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_any_all.py +177 -0
  302. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_apply_func.py +575 -0
  303. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_binary_ops.py +235 -0
  304. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_combine.py +653 -0
  305. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_compute.py +463 -0
  306. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_corrwith.py +86 -0
  307. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_cov.py +151 -0
  308. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_cumulative.py +139 -0
  309. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_describe.py +458 -0
  310. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_eval.py +86 -0
  311. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_melt.py +202 -0
  312. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_missing_data.py +520 -0
  313. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/computation/test_pivot.py +361 -0
  314. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/__init__.py +16 -0
  315. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/__init__.py +16 -0
  316. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_any_all.py +40 -0
  317. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_apply_func.py +42 -0
  318. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_binary_ops.py +40 -0
  319. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_combine.py +37 -0
  320. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_compute.py +60 -0
  321. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_corrwith.py +40 -0
  322. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_cov.py +40 -0
  323. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_cumulative.py +90 -0
  324. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_describe.py +40 -0
  325. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_eval.py +40 -0
  326. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_melt.py +40 -0
  327. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_missing_data.py +42 -0
  328. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/computation/test_parity_pivot.py +37 -0
  329. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/__init__.py +16 -0
  330. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_base.py +36 -0
  331. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_binary_ops.py +42 -0
  332. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_boolean_ops.py +47 -0
  333. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_categorical_ops.py +55 -0
  334. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_complex_ops.py +40 -0
  335. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_date_ops.py +47 -0
  336. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_datetime_ops.py +47 -0
  337. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_null_ops.py +42 -0
  338. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_num_arithmetic.py +43 -0
  339. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_num_ops.py +47 -0
  340. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_num_reverse.py +43 -0
  341. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_string_ops.py +47 -0
  342. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_timedelta_ops.py +47 -0
  343. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/test_parity_udt_ops.py +40 -0
  344. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/data_type_ops/testing_utils.py +226 -0
  345. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/__init__.py +16 -0
  346. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_align.py +39 -0
  347. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_basic_slow.py +55 -0
  348. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_cov_corrwith.py +39 -0
  349. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_dot_frame.py +39 -0
  350. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_dot_series.py +39 -0
  351. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_index.py +39 -0
  352. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_series.py +39 -0
  353. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_setitem_frame.py +43 -0
  354. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/diff_frames_ops/test_parity_setitem_series.py +43 -0
  355. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/__init__.py +16 -0
  356. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_attrs.py +40 -0
  357. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_constructor.py +39 -0
  358. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_conversion.py +42 -0
  359. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_reindexing.py +42 -0
  360. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_reshaping.py +37 -0
  361. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_spark.py +40 -0
  362. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_take.py +42 -0
  363. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_time_series.py +48 -0
  364. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/frame/test_parity_truncate.py +40 -0
  365. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/__init__.py +16 -0
  366. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_aggregate.py +40 -0
  367. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_apply_func.py +41 -0
  368. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_cumulative.py +67 -0
  369. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_describe.py +40 -0
  370. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_groupby.py +55 -0
  371. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_head_tail.py +40 -0
  372. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_index.py +38 -0
  373. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_missing_data.py +55 -0
  374. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_split_apply.py +39 -0
  375. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/groupby/test_parity_stat.py +38 -0
  376. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/__init__.py +16 -0
  377. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_align.py +40 -0
  378. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_base.py +50 -0
  379. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_category.py +73 -0
  380. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_datetime.py +39 -0
  381. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_indexing.py +40 -0
  382. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_reindex.py +40 -0
  383. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_rename.py +40 -0
  384. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_reset_index.py +48 -0
  385. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/indexes/test_parity_timedelta.py +39 -0
  386. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/io/__init__.py +16 -0
  387. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/io/test_parity_io.py +40 -0
  388. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/__init__.py +16 -0
  389. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_frame_plot.py +45 -0
  390. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_frame_plot_matplotlib.py +45 -0
  391. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_frame_plot_plotly.py +49 -0
  392. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_series_plot.py +37 -0
  393. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_series_plot_matplotlib.py +53 -0
  394. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/plot/test_parity_series_plot_plotly.py +45 -0
  395. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/__init__.py +16 -0
  396. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_all_any.py +38 -0
  397. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_arg_ops.py +37 -0
  398. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_as_of.py +37 -0
  399. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_as_type.py +38 -0
  400. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_compute.py +37 -0
  401. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_conversion.py +40 -0
  402. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_cumulative.py +40 -0
  403. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_index.py +38 -0
  404. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_missing_data.py +40 -0
  405. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_series.py +37 -0
  406. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_sort.py +38 -0
  407. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/series/test_parity_stat.py +38 -0
  408. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_categorical.py +66 -0
  409. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_config.py +37 -0
  410. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_csv.py +37 -0
  411. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_dataframe_conversion.py +42 -0
  412. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_dataframe_spark_io.py +39 -0
  413. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_default_index.py +49 -0
  414. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_ewm.py +37 -0
  415. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_expanding.py +39 -0
  416. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_extension.py +49 -0
  417. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_frame_spark.py +53 -0
  418. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_generic_functions.py +43 -0
  419. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_indexing.py +49 -0
  420. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_indexops_spark.py +39 -0
  421. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_internal.py +41 -0
  422. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_namespace.py +39 -0
  423. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_numpy_compat.py +60 -0
  424. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_ops_on_diff_frames.py +48 -0
  425. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_ops_on_diff_frames_groupby.py +39 -0
  426. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_ops_on_diff_frames_groupby_expanding.py +44 -0
  427. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_ops_on_diff_frames_groupby_rolling.py +84 -0
  428. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_repr.py +37 -0
  429. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_resample.py +45 -0
  430. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_reshape.py +39 -0
  431. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_rolling.py +39 -0
  432. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_scalars.py +37 -0
  433. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_series_conversion.py +39 -0
  434. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_series_datetime.py +39 -0
  435. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_series_string.py +39 -0
  436. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_spark_functions.py +39 -0
  437. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_sql.py +43 -0
  438. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_stats.py +37 -0
  439. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_typedef.py +36 -0
  440. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_utils.py +37 -0
  441. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/connect/test_parity_window.py +39 -0
  442. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/__init__.py +16 -0
  443. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_base.py +107 -0
  444. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_binary_ops.py +224 -0
  445. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_boolean_ops.py +825 -0
  446. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_categorical_ops.py +562 -0
  447. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_complex_ops.py +368 -0
  448. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_date_ops.py +257 -0
  449. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_datetime_ops.py +260 -0
  450. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_null_ops.py +178 -0
  451. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_num_arithmetic.py +184 -0
  452. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_num_ops.py +497 -0
  453. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_num_reverse.py +140 -0
  454. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_string_ops.py +354 -0
  455. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_timedelta_ops.py +219 -0
  456. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/test_udt_ops.py +192 -0
  457. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/data_type_ops/testing_utils.py +228 -0
  458. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/__init__.py +16 -0
  459. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_align.py +118 -0
  460. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_basic_slow.py +198 -0
  461. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_cov_corrwith.py +181 -0
  462. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_dot_frame.py +103 -0
  463. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_dot_series.py +141 -0
  464. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_index.py +109 -0
  465. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_series.py +136 -0
  466. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_setitem_frame.py +125 -0
  467. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/diff_frames_ops/test_setitem_series.py +217 -0
  468. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/__init__.py +16 -0
  469. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_attrs.py +384 -0
  470. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_constructor.py +598 -0
  471. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_conversion.py +73 -0
  472. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_reindexing.py +869 -0
  473. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_reshaping.py +487 -0
  474. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_spark.py +309 -0
  475. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_take.py +156 -0
  476. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_time_series.py +149 -0
  477. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/frame/test_truncate.py +163 -0
  478. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/__init__.py +16 -0
  479. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_aggregate.py +311 -0
  480. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_apply_func.py +524 -0
  481. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_cumulative.py +419 -0
  482. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_describe.py +144 -0
  483. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_groupby.py +979 -0
  484. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_head_tail.py +234 -0
  485. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_index.py +206 -0
  486. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_missing_data.py +421 -0
  487. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_split_apply.py +187 -0
  488. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/groupby/test_stat.py +397 -0
  489. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/__init__.py +16 -0
  490. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_align.py +100 -0
  491. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_base.py +2743 -0
  492. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_category.py +484 -0
  493. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_datetime.py +276 -0
  494. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_indexing.py +432 -0
  495. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_reindex.py +310 -0
  496. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_rename.py +257 -0
  497. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_reset_index.py +160 -0
  498. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/indexes/test_timedelta.py +128 -0
  499. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/io/__init__.py +16 -0
  500. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/io/test_io.py +137 -0
  501. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/__init__.py +16 -0
  502. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_frame_plot.py +170 -0
  503. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_frame_plot_matplotlib.py +547 -0
  504. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_frame_plot_plotly.py +285 -0
  505. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_series_plot.py +106 -0
  506. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_series_plot_matplotlib.py +409 -0
  507. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/plot/test_series_plot_plotly.py +247 -0
  508. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/__init__.py +16 -0
  509. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_all_any.py +105 -0
  510. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_arg_ops.py +197 -0
  511. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_as_of.py +137 -0
  512. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_as_type.py +227 -0
  513. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_compute.py +634 -0
  514. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_conversion.py +88 -0
  515. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_cumulative.py +139 -0
  516. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_index.py +475 -0
  517. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_missing_data.py +265 -0
  518. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_series.py +818 -0
  519. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_sort.py +162 -0
  520. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/series/test_stat.py +780 -0
  521. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_categorical.py +741 -0
  522. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_config.py +160 -0
  523. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_csv.py +453 -0
  524. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_dataframe_conversion.py +281 -0
  525. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_dataframe_spark_io.py +487 -0
  526. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_default_index.py +109 -0
  527. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_ewm.py +434 -0
  528. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_expanding.py +253 -0
  529. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_extension.py +152 -0
  530. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_frame_spark.py +162 -0
  531. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_generic_functions.py +234 -0
  532. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_indexing.py +1339 -0
  533. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_indexops_spark.py +82 -0
  534. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_internal.py +124 -0
  535. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_namespace.py +638 -0
  536. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_numpy_compat.py +200 -0
  537. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_ops_on_diff_frames.py +1355 -0
  538. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_ops_on_diff_frames_groupby.py +655 -0
  539. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_ops_on_diff_frames_groupby_expanding.py +113 -0
  540. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_ops_on_diff_frames_groupby_rolling.py +118 -0
  541. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_repr.py +192 -0
  542. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_resample.py +346 -0
  543. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_reshape.py +495 -0
  544. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_rolling.py +263 -0
  545. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_scalars.py +59 -0
  546. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_series_conversion.py +85 -0
  547. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_series_datetime.py +364 -0
  548. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_series_string.py +362 -0
  549. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_spark_functions.py +46 -0
  550. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_sql.py +123 -0
  551. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_stats.py +581 -0
  552. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_typedef.py +447 -0
  553. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_utils.py +301 -0
  554. snowflake/snowpark_connect/includes/python/pyspark/pandas/tests/test_window.py +465 -0
  555. snowflake/snowpark_connect/includes/python/pyspark/pandas/typedef/__init__.py +18 -0
  556. snowflake/snowpark_connect/includes/python/pyspark/pandas/typedef/typehints.py +874 -0
  557. snowflake/snowpark_connect/includes/python/pyspark/pandas/usage_logging/__init__.py +143 -0
  558. snowflake/snowpark_connect/includes/python/pyspark/pandas/usage_logging/usage_logger.py +132 -0
  559. snowflake/snowpark_connect/includes/python/pyspark/pandas/utils.py +1063 -0
  560. snowflake/snowpark_connect/includes/python/pyspark/pandas/window.py +2702 -0
  561. snowflake/snowpark_connect/includes/python/pyspark/profiler.py +489 -0
  562. snowflake/snowpark_connect/includes/python/pyspark/py.typed +1 -0
  563. snowflake/snowpark_connect/includes/python/pyspark/python/pyspark/shell.py +123 -0
  564. snowflake/snowpark_connect/includes/python/pyspark/rdd.py +5518 -0
  565. snowflake/snowpark_connect/includes/python/pyspark/rddsampler.py +115 -0
  566. snowflake/snowpark_connect/includes/python/pyspark/resource/__init__.py +38 -0
  567. snowflake/snowpark_connect/includes/python/pyspark/resource/information.py +69 -0
  568. snowflake/snowpark_connect/includes/python/pyspark/resource/profile.py +317 -0
  569. snowflake/snowpark_connect/includes/python/pyspark/resource/requests.py +539 -0
  570. snowflake/snowpark_connect/includes/python/pyspark/resource/tests/__init__.py +16 -0
  571. snowflake/snowpark_connect/includes/python/pyspark/resource/tests/test_resources.py +83 -0
  572. snowflake/snowpark_connect/includes/python/pyspark/resultiterable.py +45 -0
  573. snowflake/snowpark_connect/includes/python/pyspark/serializers.py +681 -0
  574. snowflake/snowpark_connect/includes/python/pyspark/shell.py +123 -0
  575. snowflake/snowpark_connect/includes/python/pyspark/shuffle.py +854 -0
  576. snowflake/snowpark_connect/includes/python/pyspark/sql/__init__.py +75 -0
  577. snowflake/snowpark_connect/includes/python/pyspark/sql/_typing.pyi +80 -0
  578. snowflake/snowpark_connect/includes/python/pyspark/sql/avro/__init__.py +18 -0
  579. snowflake/snowpark_connect/includes/python/pyspark/sql/avro/functions.py +188 -0
  580. snowflake/snowpark_connect/includes/python/pyspark/sql/catalog.py +1270 -0
  581. snowflake/snowpark_connect/includes/python/pyspark/sql/column.py +1431 -0
  582. snowflake/snowpark_connect/includes/python/pyspark/sql/conf.py +99 -0
  583. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/__init__.py +18 -0
  584. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/_typing.py +90 -0
  585. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/avro/__init__.py +18 -0
  586. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/avro/functions.py +107 -0
  587. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/catalog.py +356 -0
  588. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/client/__init__.py +22 -0
  589. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/client/artifact.py +412 -0
  590. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/client/core.py +1689 -0
  591. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/client/reattach.py +340 -0
  592. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/column.py +514 -0
  593. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/conf.py +128 -0
  594. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/conversion.py +490 -0
  595. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/dataframe.py +2172 -0
  596. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/expressions.py +1056 -0
  597. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/functions.py +3937 -0
  598. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/group.py +418 -0
  599. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/plan.py +2289 -0
  600. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/__init__.py +25 -0
  601. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/base_pb2.py +203 -0
  602. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/base_pb2.pyi +2718 -0
  603. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/base_pb2_grpc.py +423 -0
  604. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/catalog_pb2.py +109 -0
  605. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/catalog_pb2.pyi +1130 -0
  606. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/commands_pb2.py +141 -0
  607. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/commands_pb2.pyi +1766 -0
  608. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/common_pb2.py +47 -0
  609. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/common_pb2.pyi +123 -0
  610. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/example_plugins_pb2.py +53 -0
  611. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/example_plugins_pb2.pyi +112 -0
  612. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/expressions_pb2.py +107 -0
  613. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/expressions_pb2.pyi +1507 -0
  614. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/relations_pb2.py +195 -0
  615. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/relations_pb2.pyi +3613 -0
  616. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/types_pb2.py +95 -0
  617. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/proto/types_pb2.pyi +980 -0
  618. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/protobuf/__init__.py +18 -0
  619. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/protobuf/functions.py +166 -0
  620. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/readwriter.py +861 -0
  621. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/session.py +952 -0
  622. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/__init__.py +22 -0
  623. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/query.py +295 -0
  624. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/readwriter.py +618 -0
  625. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/worker/__init__.py +18 -0
  626. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/worker/foreach_batch_worker.py +87 -0
  627. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/streaming/worker/listener_worker.py +100 -0
  628. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/types.py +301 -0
  629. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/udf.py +296 -0
  630. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/udtf.py +200 -0
  631. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/utils.py +58 -0
  632. snowflake/snowpark_connect/includes/python/pyspark/sql/connect/window.py +266 -0
  633. snowflake/snowpark_connect/includes/python/pyspark/sql/context.py +818 -0
  634. snowflake/snowpark_connect/includes/python/pyspark/sql/dataframe.py +5973 -0
  635. snowflake/snowpark_connect/includes/python/pyspark/sql/functions.py +15889 -0
  636. snowflake/snowpark_connect/includes/python/pyspark/sql/group.py +547 -0
  637. snowflake/snowpark_connect/includes/python/pyspark/sql/observation.py +152 -0
  638. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/__init__.py +21 -0
  639. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/_typing/__init__.pyi +344 -0
  640. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/_typing/protocols/__init__.pyi +17 -0
  641. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/_typing/protocols/frame.pyi +20 -0
  642. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/_typing/protocols/series.pyi +20 -0
  643. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/conversion.py +671 -0
  644. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/functions.py +480 -0
  645. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/functions.pyi +132 -0
  646. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/group_ops.py +523 -0
  647. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/map_ops.py +216 -0
  648. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/serializers.py +1019 -0
  649. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/typehints.py +172 -0
  650. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/types.py +972 -0
  651. snowflake/snowpark_connect/includes/python/pyspark/sql/pandas/utils.py +86 -0
  652. snowflake/snowpark_connect/includes/python/pyspark/sql/protobuf/__init__.py +18 -0
  653. snowflake/snowpark_connect/includes/python/pyspark/sql/protobuf/functions.py +334 -0
  654. snowflake/snowpark_connect/includes/python/pyspark/sql/readwriter.py +2159 -0
  655. snowflake/snowpark_connect/includes/python/pyspark/sql/session.py +2088 -0
  656. snowflake/snowpark_connect/includes/python/pyspark/sql/sql_formatter.py +84 -0
  657. snowflake/snowpark_connect/includes/python/pyspark/sql/streaming/__init__.py +21 -0
  658. snowflake/snowpark_connect/includes/python/pyspark/sql/streaming/listener.py +1050 -0
  659. snowflake/snowpark_connect/includes/python/pyspark/sql/streaming/query.py +746 -0
  660. snowflake/snowpark_connect/includes/python/pyspark/sql/streaming/readwriter.py +1652 -0
  661. snowflake/snowpark_connect/includes/python/pyspark/sql/streaming/state.py +288 -0
  662. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/__init__.py +16 -0
  663. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/__init__.py +16 -0
  664. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/client/__init__.py +16 -0
  665. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/client/test_artifact.py +420 -0
  666. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/client/test_client.py +358 -0
  667. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/streaming/__init__.py +16 -0
  668. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/streaming/test_parity_foreach.py +36 -0
  669. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/streaming/test_parity_foreach_batch.py +44 -0
  670. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/streaming/test_parity_listener.py +116 -0
  671. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/streaming/test_parity_streaming.py +35 -0
  672. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_connect_basic.py +3612 -0
  673. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_connect_column.py +1042 -0
  674. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_connect_function.py +2381 -0
  675. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_connect_plan.py +1060 -0
  676. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_arrow.py +163 -0
  677. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_arrow_map.py +38 -0
  678. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_arrow_python_udf.py +48 -0
  679. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_catalog.py +36 -0
  680. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_column.py +55 -0
  681. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_conf.py +36 -0
  682. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_dataframe.py +96 -0
  683. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_datasources.py +44 -0
  684. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_errors.py +36 -0
  685. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_functions.py +59 -0
  686. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_group.py +36 -0
  687. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_cogrouped_map.py +59 -0
  688. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_grouped_map.py +74 -0
  689. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_grouped_map_with_state.py +62 -0
  690. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_map.py +58 -0
  691. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_udf.py +70 -0
  692. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_udf_grouped_agg.py +50 -0
  693. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_udf_scalar.py +68 -0
  694. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_pandas_udf_window.py +40 -0
  695. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_readwriter.py +46 -0
  696. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_serde.py +44 -0
  697. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_types.py +100 -0
  698. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_udf.py +100 -0
  699. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_parity_udtf.py +163 -0
  700. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_session.py +181 -0
  701. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/connect/test_utils.py +42 -0
  702. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/__init__.py +16 -0
  703. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_cogrouped_map.py +623 -0
  704. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_grouped_map.py +869 -0
  705. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_grouped_map_with_state.py +342 -0
  706. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_map.py +436 -0
  707. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf.py +363 -0
  708. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf_grouped_agg.py +592 -0
  709. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf_scalar.py +1503 -0
  710. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf_typehints.py +392 -0
  711. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf_typehints_with_future_annotations.py +375 -0
  712. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/pandas/test_pandas_udf_window.py +411 -0
  713. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/streaming/__init__.py +16 -0
  714. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/streaming/test_streaming.py +401 -0
  715. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/streaming/test_streaming_foreach.py +295 -0
  716. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/streaming/test_streaming_foreach_batch.py +106 -0
  717. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/streaming/test_streaming_listener.py +558 -0
  718. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_arrow.py +1346 -0
  719. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_arrow_map.py +182 -0
  720. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_arrow_python_udf.py +202 -0
  721. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_catalog.py +503 -0
  722. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_column.py +225 -0
  723. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_conf.py +83 -0
  724. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_context.py +201 -0
  725. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_dataframe.py +1931 -0
  726. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_datasources.py +256 -0
  727. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_errors.py +69 -0
  728. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_functions.py +1349 -0
  729. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_group.py +53 -0
  730. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_pandas_sqlmetrics.py +68 -0
  731. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_readwriter.py +283 -0
  732. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_serde.py +155 -0
  733. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_session.py +412 -0
  734. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_types.py +1581 -0
  735. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_udf.py +961 -0
  736. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_udf_profiler.py +165 -0
  737. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_udtf.py +1456 -0
  738. snowflake/snowpark_connect/includes/python/pyspark/sql/tests/test_utils.py +1686 -0
  739. snowflake/snowpark_connect/includes/python/pyspark/sql/types.py +2558 -0
  740. snowflake/snowpark_connect/includes/python/pyspark/sql/udf.py +714 -0
  741. snowflake/snowpark_connect/includes/python/pyspark/sql/udtf.py +325 -0
  742. snowflake/snowpark_connect/includes/python/pyspark/sql/utils.py +339 -0
  743. snowflake/snowpark_connect/includes/python/pyspark/sql/window.py +492 -0
  744. snowflake/snowpark_connect/includes/python/pyspark/statcounter.py +165 -0
  745. snowflake/snowpark_connect/includes/python/pyspark/status.py +112 -0
  746. snowflake/snowpark_connect/includes/python/pyspark/storagelevel.py +97 -0
  747. snowflake/snowpark_connect/includes/python/pyspark/streaming/__init__.py +22 -0
  748. snowflake/snowpark_connect/includes/python/pyspark/streaming/context.py +471 -0
  749. snowflake/snowpark_connect/includes/python/pyspark/streaming/dstream.py +933 -0
  750. snowflake/snowpark_connect/includes/python/pyspark/streaming/kinesis.py +205 -0
  751. snowflake/snowpark_connect/includes/python/pyspark/streaming/listener.py +83 -0
  752. snowflake/snowpark_connect/includes/python/pyspark/streaming/tests/__init__.py +16 -0
  753. snowflake/snowpark_connect/includes/python/pyspark/streaming/tests/test_context.py +184 -0
  754. snowflake/snowpark_connect/includes/python/pyspark/streaming/tests/test_dstream.py +706 -0
  755. snowflake/snowpark_connect/includes/python/pyspark/streaming/tests/test_kinesis.py +118 -0
  756. snowflake/snowpark_connect/includes/python/pyspark/streaming/tests/test_listener.py +160 -0
  757. snowflake/snowpark_connect/includes/python/pyspark/streaming/util.py +168 -0
  758. snowflake/snowpark_connect/includes/python/pyspark/taskcontext.py +502 -0
  759. snowflake/snowpark_connect/includes/python/pyspark/testing/__init__.py +21 -0
  760. snowflake/snowpark_connect/includes/python/pyspark/testing/connectutils.py +199 -0
  761. snowflake/snowpark_connect/includes/python/pyspark/testing/mllibutils.py +30 -0
  762. snowflake/snowpark_connect/includes/python/pyspark/testing/mlutils.py +275 -0
  763. snowflake/snowpark_connect/includes/python/pyspark/testing/objects.py +121 -0
  764. snowflake/snowpark_connect/includes/python/pyspark/testing/pandasutils.py +714 -0
  765. snowflake/snowpark_connect/includes/python/pyspark/testing/sqlutils.py +168 -0
  766. snowflake/snowpark_connect/includes/python/pyspark/testing/streamingutils.py +178 -0
  767. snowflake/snowpark_connect/includes/python/pyspark/testing/utils.py +636 -0
  768. snowflake/snowpark_connect/includes/python/pyspark/tests/__init__.py +16 -0
  769. snowflake/snowpark_connect/includes/python/pyspark/tests/test_appsubmit.py +306 -0
  770. snowflake/snowpark_connect/includes/python/pyspark/tests/test_broadcast.py +196 -0
  771. snowflake/snowpark_connect/includes/python/pyspark/tests/test_conf.py +44 -0
  772. snowflake/snowpark_connect/includes/python/pyspark/tests/test_context.py +346 -0
  773. snowflake/snowpark_connect/includes/python/pyspark/tests/test_daemon.py +89 -0
  774. snowflake/snowpark_connect/includes/python/pyspark/tests/test_install_spark.py +124 -0
  775. snowflake/snowpark_connect/includes/python/pyspark/tests/test_join.py +69 -0
  776. snowflake/snowpark_connect/includes/python/pyspark/tests/test_memory_profiler.py +167 -0
  777. snowflake/snowpark_connect/includes/python/pyspark/tests/test_pin_thread.py +194 -0
  778. snowflake/snowpark_connect/includes/python/pyspark/tests/test_profiler.py +168 -0
  779. snowflake/snowpark_connect/includes/python/pyspark/tests/test_rdd.py +939 -0
  780. snowflake/snowpark_connect/includes/python/pyspark/tests/test_rddbarrier.py +52 -0
  781. snowflake/snowpark_connect/includes/python/pyspark/tests/test_rddsampler.py +66 -0
  782. snowflake/snowpark_connect/includes/python/pyspark/tests/test_readwrite.py +368 -0
  783. snowflake/snowpark_connect/includes/python/pyspark/tests/test_serializers.py +257 -0
  784. snowflake/snowpark_connect/includes/python/pyspark/tests/test_shuffle.py +267 -0
  785. snowflake/snowpark_connect/includes/python/pyspark/tests/test_stage_sched.py +153 -0
  786. snowflake/snowpark_connect/includes/python/pyspark/tests/test_statcounter.py +130 -0
  787. snowflake/snowpark_connect/includes/python/pyspark/tests/test_taskcontext.py +350 -0
  788. snowflake/snowpark_connect/includes/python/pyspark/tests/test_util.py +97 -0
  789. snowflake/snowpark_connect/includes/python/pyspark/tests/test_worker.py +271 -0
  790. snowflake/snowpark_connect/includes/python/pyspark/traceback_utils.py +81 -0
  791. snowflake/snowpark_connect/includes/python/pyspark/util.py +416 -0
  792. snowflake/snowpark_connect/includes/python/pyspark/version.py +19 -0
  793. snowflake/snowpark_connect/includes/python/pyspark/worker.py +1307 -0
  794. snowflake/snowpark_connect/includes/python/pyspark/worker_util.py +46 -0
  795. snowflake/snowpark_connect/proto/__init__.py +10 -0
  796. snowflake/snowpark_connect/proto/control_pb2.py +35 -0
  797. snowflake/snowpark_connect/proto/control_pb2.pyi +38 -0
  798. snowflake/snowpark_connect/proto/control_pb2_grpc.py +183 -0
  799. snowflake/snowpark_connect/proto/snowflake_expression_ext_pb2.py +35 -0
  800. snowflake/snowpark_connect/proto/snowflake_expression_ext_pb2.pyi +53 -0
  801. snowflake/snowpark_connect/proto/snowflake_rdd_pb2.pyi +39 -0
  802. snowflake/snowpark_connect/proto/snowflake_relation_ext_pb2.py +47 -0
  803. snowflake/snowpark_connect/proto/snowflake_relation_ext_pb2.pyi +111 -0
  804. snowflake/snowpark_connect/relation/__init__.py +3 -0
  805. snowflake/snowpark_connect/relation/catalogs/__init__.py +12 -0
  806. snowflake/snowpark_connect/relation/catalogs/abstract_spark_catalog.py +287 -0
  807. snowflake/snowpark_connect/relation/catalogs/snowflake_catalog.py +467 -0
  808. snowflake/snowpark_connect/relation/catalogs/utils.py +51 -0
  809. snowflake/snowpark_connect/relation/io_utils.py +76 -0
  810. snowflake/snowpark_connect/relation/map_aggregate.py +322 -0
  811. snowflake/snowpark_connect/relation/map_catalog.py +151 -0
  812. snowflake/snowpark_connect/relation/map_column_ops.py +1068 -0
  813. snowflake/snowpark_connect/relation/map_crosstab.py +48 -0
  814. snowflake/snowpark_connect/relation/map_extension.py +412 -0
  815. snowflake/snowpark_connect/relation/map_join.py +341 -0
  816. snowflake/snowpark_connect/relation/map_local_relation.py +326 -0
  817. snowflake/snowpark_connect/relation/map_map_partitions.py +146 -0
  818. snowflake/snowpark_connect/relation/map_relation.py +253 -0
  819. snowflake/snowpark_connect/relation/map_row_ops.py +716 -0
  820. snowflake/snowpark_connect/relation/map_sample_by.py +35 -0
  821. snowflake/snowpark_connect/relation/map_show_string.py +50 -0
  822. snowflake/snowpark_connect/relation/map_sql.py +1874 -0
  823. snowflake/snowpark_connect/relation/map_stats.py +324 -0
  824. snowflake/snowpark_connect/relation/map_subquery_alias.py +32 -0
  825. snowflake/snowpark_connect/relation/map_udtf.py +288 -0
  826. snowflake/snowpark_connect/relation/read/__init__.py +7 -0
  827. snowflake/snowpark_connect/relation/read/jdbc_read_dbapi.py +668 -0
  828. snowflake/snowpark_connect/relation/read/map_read.py +367 -0
  829. snowflake/snowpark_connect/relation/read/map_read_csv.py +142 -0
  830. snowflake/snowpark_connect/relation/read/map_read_jdbc.py +108 -0
  831. snowflake/snowpark_connect/relation/read/map_read_json.py +344 -0
  832. snowflake/snowpark_connect/relation/read/map_read_parquet.py +194 -0
  833. snowflake/snowpark_connect/relation/read/map_read_socket.py +59 -0
  834. snowflake/snowpark_connect/relation/read/map_read_table.py +109 -0
  835. snowflake/snowpark_connect/relation/read/map_read_text.py +106 -0
  836. snowflake/snowpark_connect/relation/read/reader_config.py +399 -0
  837. snowflake/snowpark_connect/relation/read/utils.py +155 -0
  838. snowflake/snowpark_connect/relation/stage_locator.py +161 -0
  839. snowflake/snowpark_connect/relation/utils.py +219 -0
  840. snowflake/snowpark_connect/relation/write/__init__.py +3 -0
  841. snowflake/snowpark_connect/relation/write/jdbc_write_dbapi.py +339 -0
  842. snowflake/snowpark_connect/relation/write/map_write.py +436 -0
  843. snowflake/snowpark_connect/relation/write/map_write_jdbc.py +48 -0
  844. snowflake/snowpark_connect/resources/java_udfs-1.0-SNAPSHOT.jar +0 -0
  845. snowflake/snowpark_connect/resources_initializer.py +75 -0
  846. snowflake/snowpark_connect/server.py +1136 -0
  847. snowflake/snowpark_connect/start_server.py +32 -0
  848. snowflake/snowpark_connect/tcm.py +8 -0
  849. snowflake/snowpark_connect/type_mapping.py +1003 -0
  850. snowflake/snowpark_connect/typed_column.py +94 -0
  851. snowflake/snowpark_connect/utils/__init__.py +3 -0
  852. snowflake/snowpark_connect/utils/artifacts.py +48 -0
  853. snowflake/snowpark_connect/utils/attribute_handling.py +72 -0
  854. snowflake/snowpark_connect/utils/cache.py +84 -0
  855. snowflake/snowpark_connect/utils/concurrent.py +124 -0
  856. snowflake/snowpark_connect/utils/context.py +390 -0
  857. snowflake/snowpark_connect/utils/describe_query_cache.py +231 -0
  858. snowflake/snowpark_connect/utils/interrupt.py +85 -0
  859. snowflake/snowpark_connect/utils/io_utils.py +35 -0
  860. snowflake/snowpark_connect/utils/pandas_udtf_utils.py +117 -0
  861. snowflake/snowpark_connect/utils/profiling.py +47 -0
  862. snowflake/snowpark_connect/utils/session.py +180 -0
  863. snowflake/snowpark_connect/utils/snowpark_connect_logging.py +38 -0
  864. snowflake/snowpark_connect/utils/telemetry.py +513 -0
  865. snowflake/snowpark_connect/utils/udf_cache.py +392 -0
  866. snowflake/snowpark_connect/utils/udf_helper.py +328 -0
  867. snowflake/snowpark_connect/utils/udf_utils.py +310 -0
  868. snowflake/snowpark_connect/utils/udtf_helper.py +420 -0
  869. snowflake/snowpark_connect/utils/udtf_utils.py +799 -0
  870. snowflake/snowpark_connect/utils/xxhash64.py +247 -0
  871. snowflake/snowpark_connect/version.py +6 -0
  872. snowpark_connect-0.20.2.data/scripts/snowpark-connect +71 -0
  873. snowpark_connect-0.20.2.data/scripts/snowpark-session +11 -0
  874. snowpark_connect-0.20.2.data/scripts/snowpark-submit +354 -0
  875. snowpark_connect-0.20.2.dist-info/METADATA +37 -0
  876. snowpark_connect-0.20.2.dist-info/RECORD +879 -0
  877. snowpark_connect-0.20.2.dist-info/WHEEL +5 -0
  878. snowpark_connect-0.20.2.dist-info/licenses/LICENSE.txt +202 -0
  879. snowpark_connect-0.20.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1382 @@
1
+ #
2
+ # Licensed to the Apache Software Foundation (ASF) under one or more
3
+ # contributor license agreements. See the NOTICE file distributed with
4
+ # this work for additional information regarding copyright ownership.
5
+ # The ASF licenses this file to You under the Apache License, Version 2.0
6
+ # (the "License"); you may not use this file except in compliance with
7
+ # the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ """
19
+ MLlib utilities for linear algebra. For dense vectors, MLlib
20
+ uses the NumPy `array` type, so you can simply pass NumPy arrays
21
+ around. For sparse vectors, users can construct a :class:`SparseVector`
22
+ object from MLlib or pass SciPy `scipy.sparse` column vectors if
23
+ SciPy is available in their environment.
24
+ """
25
+
26
+ import sys
27
+ import array
28
+ import struct
29
+
30
+ import numpy as np
31
+
32
+ from pyspark.sql.types import (
33
+ UserDefinedType,
34
+ StructField,
35
+ StructType,
36
+ ArrayType,
37
+ DoubleType,
38
+ IntegerType,
39
+ ByteType,
40
+ BooleanType,
41
+ )
42
+
43
+ from typing import (
44
+ Any,
45
+ Callable,
46
+ cast,
47
+ Dict,
48
+ Iterable,
49
+ List,
50
+ Optional,
51
+ overload,
52
+ Sequence,
53
+ Tuple,
54
+ Type,
55
+ TYPE_CHECKING,
56
+ Union,
57
+ )
58
+
59
+
60
+ __all__ = [
61
+ "Vector",
62
+ "DenseVector",
63
+ "SparseVector",
64
+ "Vectors",
65
+ "Matrix",
66
+ "DenseMatrix",
67
+ "SparseMatrix",
68
+ "Matrices",
69
+ ]
70
+
71
+ if TYPE_CHECKING:
72
+ from pyspark.mllib._typing import NormType
73
+ from pyspark.ml._typing import VectorLike
74
+ from scipy.sparse import spmatrix
75
+
76
+
77
+ # Check whether we have SciPy. MLlib works without it too, but if we have it, some methods,
78
+ # such as _dot and _serialize_double_vector, start to support scipy.sparse matrices.
79
+
80
+ try:
81
+ import scipy.sparse
82
+
83
+ _have_scipy = True
84
+ except BaseException:
85
+ # No SciPy in environment, but that's okay
86
+ _have_scipy = False
87
+
88
+
89
+ def _convert_to_vector(d: Union["VectorLike", "spmatrix", range]) -> "Vector":
90
+ if isinstance(d, Vector):
91
+ return d
92
+ elif type(d) in (array.array, np.array, np.ndarray, list, tuple, range):
93
+ return DenseVector(d)
94
+ elif _have_scipy and scipy.sparse.issparse(d):
95
+ assert cast("spmatrix", d).shape[1] == 1, "Expected column vector"
96
+ # Make sure the converted csc_matrix has sorted indices.
97
+ csc = cast("spmatrix", d).tocsc()
98
+ if not csc.has_sorted_indices:
99
+ csc.sort_indices()
100
+ return SparseVector(cast("spmatrix", d).shape[0], csc.indices, csc.data)
101
+ else:
102
+ raise TypeError("Cannot convert type %s into Vector" % type(d))
103
+
104
+
105
+ def _vector_size(v: Union["VectorLike", "spmatrix", range]) -> int:
106
+ """
107
+ Returns the size of the vector.
108
+
109
+ Examples
110
+ --------
111
+ >>> _vector_size([1., 2., 3.])
112
+ 3
113
+ >>> _vector_size((1., 2., 3.))
114
+ 3
115
+ >>> _vector_size(array.array('d', [1., 2., 3.]))
116
+ 3
117
+ >>> _vector_size(np.zeros(3))
118
+ 3
119
+ >>> _vector_size(np.zeros((3, 1)))
120
+ 3
121
+ >>> _vector_size(np.zeros((1, 3)))
122
+ Traceback (most recent call last):
123
+ ...
124
+ ValueError: Cannot treat an ndarray of shape (1, 3) as a vector
125
+ """
126
+ if isinstance(v, Vector):
127
+ return len(v)
128
+ elif type(v) in (array.array, list, tuple, range):
129
+ return len(v)
130
+ elif type(v) == np.ndarray:
131
+ if v.ndim == 1 or (v.ndim == 2 and v.shape[1] == 1):
132
+ return len(v)
133
+ else:
134
+ raise ValueError("Cannot treat an ndarray of shape %s as a vector" % str(v.shape))
135
+ elif _have_scipy and scipy.sparse.issparse(v):
136
+ assert cast("spmatrix", v).shape[1] == 1, "Expected column vector"
137
+ return cast("spmatrix", v).shape[0]
138
+ else:
139
+ raise TypeError("Cannot treat type %s as a vector" % type(v))
140
+
141
+
142
+ def _format_float(f: float, digits: int = 4) -> str:
143
+ s = str(round(f, digits))
144
+ if "." in s:
145
+ s = s[: s.index(".") + 1 + digits]
146
+ return s
147
+
148
+
149
+ def _format_float_list(xs: Iterable[float]) -> List[str]:
150
+ return [_format_float(x) for x in xs]
151
+
152
+
153
+ def _double_to_long_bits(value: float) -> int:
154
+ if np.isnan(value):
155
+ value = float("nan")
156
+ # pack double into 64 bits, then unpack as long int
157
+ return struct.unpack("Q", struct.pack("d", value))[0]
158
+
159
+
160
+ class VectorUDT(UserDefinedType):
161
+ """
162
+ SQL user-defined type (UDT) for Vector.
163
+ """
164
+
165
+ @classmethod
166
+ def sqlType(cls) -> StructType:
167
+ return StructType(
168
+ [
169
+ StructField("type", ByteType(), False),
170
+ StructField("size", IntegerType(), True),
171
+ StructField("indices", ArrayType(IntegerType(), False), True),
172
+ StructField("values", ArrayType(DoubleType(), False), True),
173
+ ]
174
+ )
175
+
176
+ @classmethod
177
+ def module(cls) -> str:
178
+ return "pyspark.ml.linalg"
179
+
180
+ @classmethod
181
+ def scalaUDT(cls) -> str:
182
+ return "org.apache.spark.ml.linalg.VectorUDT"
183
+
184
+ def serialize(
185
+ self, obj: "Vector"
186
+ ) -> Tuple[int, Optional[int], Optional[List[int]], List[float]]:
187
+ if isinstance(obj, SparseVector):
188
+ indices = [int(i) for i in obj.indices]
189
+ values = [float(v) for v in obj.values]
190
+ return (0, obj.size, indices, values)
191
+ elif isinstance(obj, DenseVector):
192
+ values = [float(v) for v in obj] # type: ignore[attr-defined]
193
+ return (1, None, None, values)
194
+ else:
195
+ raise TypeError("cannot serialize %r of type %r" % (obj, type(obj)))
196
+
197
+ def deserialize(
198
+ self, datum: Tuple[int, Optional[int], Optional[List[int]], List[float]]
199
+ ) -> "Vector":
200
+ assert (
201
+ len(datum) == 4
202
+ ), "VectorUDT.deserialize given row with length %d but requires 4" % len(datum)
203
+ tpe = datum[0]
204
+ if tpe == 0:
205
+ return SparseVector(cast(int, datum[1]), cast(List[int], datum[2]), datum[3])
206
+ elif tpe == 1:
207
+ return DenseVector(datum[3])
208
+ else:
209
+ raise ValueError("do not recognize type %r" % tpe)
210
+
211
+ def simpleString(self) -> str:
212
+ return "vector"
213
+
214
+
215
+ class MatrixUDT(UserDefinedType):
216
+ """
217
+ SQL user-defined type (UDT) for Matrix.
218
+ """
219
+
220
+ @classmethod
221
+ def sqlType(cls) -> StructType:
222
+ return StructType(
223
+ [
224
+ StructField("type", ByteType(), False),
225
+ StructField("numRows", IntegerType(), False),
226
+ StructField("numCols", IntegerType(), False),
227
+ StructField("colPtrs", ArrayType(IntegerType(), False), True),
228
+ StructField("rowIndices", ArrayType(IntegerType(), False), True),
229
+ StructField("values", ArrayType(DoubleType(), False), True),
230
+ StructField("isTransposed", BooleanType(), False),
231
+ ]
232
+ )
233
+
234
+ @classmethod
235
+ def module(cls) -> str:
236
+ return "pyspark.ml.linalg"
237
+
238
+ @classmethod
239
+ def scalaUDT(cls) -> str:
240
+ return "org.apache.spark.ml.linalg.MatrixUDT"
241
+
242
+ def serialize(
243
+ self, obj: "Matrix"
244
+ ) -> Tuple[int, int, int, Optional[List[int]], Optional[List[int]], List[float], bool]:
245
+ if isinstance(obj, SparseMatrix):
246
+ colPtrs = [int(i) for i in obj.colPtrs]
247
+ rowIndices = [int(i) for i in obj.rowIndices]
248
+ values = [float(v) for v in obj.values]
249
+ return (
250
+ 0,
251
+ obj.numRows,
252
+ obj.numCols,
253
+ colPtrs,
254
+ rowIndices,
255
+ values,
256
+ bool(obj.isTransposed),
257
+ )
258
+ elif isinstance(obj, DenseMatrix):
259
+ values = [float(v) for v in obj.values]
260
+ return (1, obj.numRows, obj.numCols, None, None, values, bool(obj.isTransposed))
261
+ else:
262
+ raise TypeError("cannot serialize type %r" % (type(obj)))
263
+
264
+ def deserialize(
265
+ self,
266
+ datum: Tuple[int, int, int, Optional[List[int]], Optional[List[int]], List[float], bool],
267
+ ) -> "Matrix":
268
+ assert (
269
+ len(datum) == 7
270
+ ), "MatrixUDT.deserialize given row with length %d but requires 7" % len(datum)
271
+ tpe = datum[0]
272
+ if tpe == 0:
273
+ return SparseMatrix(*datum[1:]) # type: ignore[arg-type]
274
+ elif tpe == 1:
275
+ return DenseMatrix(datum[1], datum[2], datum[5], datum[6])
276
+ else:
277
+ raise ValueError("do not recognize type %r" % tpe)
278
+
279
+ def simpleString(self) -> str:
280
+ return "matrix"
281
+
282
+
283
+ class Vector:
284
+
285
+ __UDT__ = VectorUDT()
286
+
287
+ """
288
+ Abstract class for DenseVector and SparseVector
289
+ """
290
+
291
+ def toArray(self) -> np.ndarray:
292
+ """
293
+ Convert the vector into an numpy.ndarray
294
+
295
+ :return: numpy.ndarray
296
+ """
297
+ raise NotImplementedError
298
+
299
+ def __len__(self) -> int:
300
+ raise NotImplementedError
301
+
302
+
303
+ class DenseVector(Vector):
304
+ """
305
+ A dense vector represented by a value array. We use numpy array for
306
+ storage and arithmetics will be delegated to the underlying numpy
307
+ array.
308
+
309
+ Examples
310
+ --------
311
+ >>> v = Vectors.dense([1.0, 2.0])
312
+ >>> u = Vectors.dense([3.0, 4.0])
313
+ >>> v + u
314
+ DenseVector([4.0, 6.0])
315
+ >>> 2 - v
316
+ DenseVector([1.0, 0.0])
317
+ >>> v / 2
318
+ DenseVector([0.5, 1.0])
319
+ >>> v * u
320
+ DenseVector([3.0, 8.0])
321
+ >>> u / v
322
+ DenseVector([3.0, 2.0])
323
+ >>> u % 2
324
+ DenseVector([1.0, 0.0])
325
+ >>> -v
326
+ DenseVector([-1.0, -2.0])
327
+ """
328
+
329
+ def __init__(self, ar: Union[bytes, np.ndarray, Iterable[float]]):
330
+ ar_: np.ndarray
331
+ if isinstance(ar, bytes):
332
+ ar_ = np.frombuffer(ar, dtype=np.float64)
333
+ elif not isinstance(ar, np.ndarray):
334
+ ar_ = np.array(ar, dtype=np.float64)
335
+ else:
336
+ ar_ = ar.astype(np.float64) if ar.dtype != np.float64 else ar
337
+ self.array = ar_
338
+
339
+ def __reduce__(self) -> Tuple[Type["DenseVector"], Tuple[bytes]]:
340
+ return DenseVector, (self.array.tobytes(),)
341
+
342
+ def numNonzeros(self) -> int:
343
+ """
344
+ Number of nonzero elements. This scans all active values and count non zeros
345
+ """
346
+ return np.count_nonzero(self.array)
347
+
348
+ def norm(self, p: "NormType") -> np.float64:
349
+ """
350
+ Calculates the norm of a DenseVector.
351
+
352
+ Examples
353
+ --------
354
+ >>> a = DenseVector([0, -1, 2, -3])
355
+ >>> a.norm(2)
356
+ 3.7...
357
+ >>> a.norm(1)
358
+ 6.0
359
+ """
360
+ return np.linalg.norm(self.array, p)
361
+
362
+ def dot(self, other: Iterable[float]) -> np.float64:
363
+ """
364
+ Compute the dot product of two Vectors. We support
365
+ (Numpy array, list, SparseVector, or SciPy sparse)
366
+ and a target NumPy array that is either 1- or 2-dimensional.
367
+ Equivalent to calling numpy.dot of the two vectors.
368
+
369
+ Examples
370
+ --------
371
+ >>> dense = DenseVector(array.array('d', [1., 2.]))
372
+ >>> dense.dot(dense)
373
+ 5.0
374
+ >>> dense.dot(SparseVector(2, [0, 1], [2., 1.]))
375
+ 4.0
376
+ >>> dense.dot(range(1, 3))
377
+ 5.0
378
+ >>> dense.dot(np.array(range(1, 3)))
379
+ 5.0
380
+ >>> dense.dot([1.,])
381
+ Traceback (most recent call last):
382
+ ...
383
+ AssertionError: dimension mismatch
384
+ >>> dense.dot(np.reshape([1., 2., 3., 4.], (2, 2), order='F'))
385
+ array([ 5., 11.])
386
+ >>> dense.dot(np.reshape([1., 2., 3.], (3, 1), order='F'))
387
+ Traceback (most recent call last):
388
+ ...
389
+ AssertionError: dimension mismatch
390
+ """
391
+ if type(other) == np.ndarray:
392
+ if other.ndim > 1:
393
+ assert len(self) == other.shape[0], "dimension mismatch"
394
+ return np.dot(self.array, other)
395
+ elif _have_scipy and scipy.sparse.issparse(other):
396
+ assert len(self) == cast("spmatrix", other).shape[0], "dimension mismatch"
397
+ return cast("spmatrix", other).transpose().dot(self.toArray())
398
+ else:
399
+ assert len(self) == _vector_size(other), "dimension mismatch"
400
+ if isinstance(other, SparseVector):
401
+ return other.dot(self)
402
+ elif isinstance(other, Vector):
403
+ return np.dot(self.toArray(), other.toArray())
404
+ else:
405
+ return np.dot(self.toArray(), other) # type: ignore[call-overload]
406
+
407
+ def squared_distance(self, other: Iterable[float]) -> np.float64:
408
+ """
409
+ Squared distance of two Vectors.
410
+
411
+ Examples
412
+ --------
413
+ >>> dense1 = DenseVector(array.array('d', [1., 2.]))
414
+ >>> dense1.squared_distance(dense1)
415
+ 0.0
416
+ >>> dense2 = np.array([2., 1.])
417
+ >>> dense1.squared_distance(dense2)
418
+ 2.0
419
+ >>> dense3 = [2., 1.]
420
+ >>> dense1.squared_distance(dense3)
421
+ 2.0
422
+ >>> sparse1 = SparseVector(2, [0, 1], [2., 1.])
423
+ >>> dense1.squared_distance(sparse1)
424
+ 2.0
425
+ >>> dense1.squared_distance([1.,])
426
+ Traceback (most recent call last):
427
+ ...
428
+ AssertionError: dimension mismatch
429
+ >>> dense1.squared_distance(SparseVector(1, [0,], [1.,]))
430
+ Traceback (most recent call last):
431
+ ...
432
+ AssertionError: dimension mismatch
433
+ """
434
+ assert len(self) == _vector_size(other), "dimension mismatch"
435
+ if isinstance(other, SparseVector):
436
+ return other.squared_distance(self)
437
+ elif _have_scipy and scipy.sparse.issparse(other):
438
+ return _convert_to_vector(other).squared_distance(self) # type: ignore[attr-defined]
439
+
440
+ if isinstance(other, Vector):
441
+ other = other.toArray()
442
+ elif not isinstance(other, np.ndarray):
443
+ other = np.array(other)
444
+ diff: np.ndarray = self.toArray() - other
445
+ return np.dot(diff, diff)
446
+
447
+ def toArray(self) -> np.ndarray:
448
+ """
449
+ Returns the underlying numpy.ndarray
450
+ """
451
+ return self.array
452
+
453
+ @property
454
+ def values(self) -> np.ndarray:
455
+ """
456
+ Returns the underlying numpy.ndarray
457
+ """
458
+ return self.array
459
+
460
+ @overload
461
+ def __getitem__(self, item: int) -> np.float64:
462
+ ...
463
+
464
+ @overload
465
+ def __getitem__(self, item: slice) -> np.ndarray:
466
+ ...
467
+
468
+ def __getitem__(self, item: Union[int, slice]) -> Union[np.float64, np.ndarray]:
469
+ return self.array[item]
470
+
471
+ def __len__(self) -> int:
472
+ return len(self.array)
473
+
474
+ def __str__(self) -> str:
475
+ return "[" + ",".join([str(v) for v in self.array]) + "]"
476
+
477
+ def __repr__(self) -> str:
478
+ return "DenseVector([%s])" % (", ".join(_format_float(i) for i in self.array))
479
+
480
+ def __eq__(self, other: Any) -> bool:
481
+ if isinstance(other, DenseVector):
482
+ return np.array_equal(self.array, other.array)
483
+ elif isinstance(other, SparseVector):
484
+ if len(self) != other.size:
485
+ return False
486
+ return Vectors._equals(list(range(len(self))), self.array, other.indices, other.values)
487
+ return False
488
+
489
+ def __ne__(self, other: Any) -> bool:
490
+ return not self == other
491
+
492
+ def __hash__(self) -> int:
493
+ size = len(self)
494
+ result = 31 + size
495
+ nnz = 0
496
+ i = 0
497
+ while i < size and nnz < 128:
498
+ if self.array[i] != 0:
499
+ result = 31 * result + i
500
+ bits = _double_to_long_bits(self.array[i])
501
+ result = 31 * result + (bits ^ (bits >> 32))
502
+ nnz += 1
503
+ i += 1
504
+ return result
505
+
506
+ def __getattr__(self, item: str) -> Any:
507
+ return getattr(self.array, item)
508
+
509
+ def __neg__(self) -> "DenseVector":
510
+ return DenseVector(-self.array)
511
+
512
+ def _delegate(op: str) -> Callable[["DenseVector", Any], "DenseVector"]: # type: ignore[misc]
513
+ def func(self: "DenseVector", other: Any) -> "DenseVector":
514
+ if isinstance(other, DenseVector):
515
+ other = other.array
516
+ return DenseVector(getattr(self.array, op)(other))
517
+
518
+ return func
519
+
520
+ __add__ = _delegate("__add__")
521
+ __sub__ = _delegate("__sub__")
522
+ __mul__ = _delegate("__mul__")
523
+ __div__ = _delegate("__div__")
524
+ __truediv__ = _delegate("__truediv__")
525
+ __mod__ = _delegate("__mod__")
526
+ __radd__ = _delegate("__radd__")
527
+ __rsub__ = _delegate("__rsub__")
528
+ __rmul__ = _delegate("__rmul__")
529
+ __rdiv__ = _delegate("__rdiv__")
530
+ __rtruediv__ = _delegate("__rtruediv__")
531
+ __rmod__ = _delegate("__rmod__")
532
+
533
+
534
+ class SparseVector(Vector):
535
+ """
536
+ A simple sparse vector class for passing data to MLlib. Users may
537
+ alternatively pass SciPy's {scipy.sparse} data types.
538
+ """
539
+
540
+ @overload
541
+ def __init__(self, size: int, __indices: bytes, __values: bytes):
542
+ ...
543
+
544
+ @overload
545
+ def __init__(self, size: int, *args: Tuple[int, float]):
546
+ ...
547
+
548
+ @overload
549
+ def __init__(self, size: int, __indices: Iterable[int], __values: Iterable[float]):
550
+ ...
551
+
552
+ @overload
553
+ def __init__(self, size: int, __pairs: Iterable[Tuple[int, float]]):
554
+ ...
555
+
556
+ @overload
557
+ def __init__(self, size: int, __map: Dict[int, float]):
558
+ ...
559
+
560
+ def __init__(
561
+ self,
562
+ size: int,
563
+ *args: Union[
564
+ bytes, Tuple[int, float], Iterable[float], Iterable[Tuple[int, float]], Dict[int, float]
565
+ ],
566
+ ):
567
+ """
568
+ Create a sparse vector, using either a dictionary, a list of
569
+ (index, value) pairs, or two separate arrays of indices and
570
+ values (sorted by index).
571
+
572
+ Examples
573
+ --------
574
+ size : int
575
+ Size of the vector.
576
+ args
577
+ Active entries, as a dictionary {index: value, ...},
578
+ a list of tuples [(index, value), ...], or a list of strictly
579
+ increasing indices and a list of corresponding values [index, ...],
580
+ [value, ...]. Inactive entries are treated as zeros.
581
+
582
+ Examples
583
+ --------
584
+ >>> SparseVector(4, {1: 1.0, 3: 5.5})
585
+ SparseVector(4, {1: 1.0, 3: 5.5})
586
+ >>> SparseVector(4, [(1, 1.0), (3, 5.5)])
587
+ SparseVector(4, {1: 1.0, 3: 5.5})
588
+ >>> SparseVector(4, [1, 3], [1.0, 5.5])
589
+ SparseVector(4, {1: 1.0, 3: 5.5})
590
+ >>> SparseVector(4, {1:1.0, 6:2.0})
591
+ Traceback (most recent call last):
592
+ ...
593
+ AssertionError: Index 6 is out of the size of vector with size=4
594
+ >>> SparseVector(4, {-1:1.0})
595
+ Traceback (most recent call last):
596
+ ...
597
+ AssertionError: Contains negative index -1
598
+ """
599
+ self.size = int(size)
600
+ """ Size of the vector. """
601
+ assert 1 <= len(args) <= 2, "must pass either 2 or 3 arguments"
602
+ if len(args) == 1:
603
+ pairs = args[0]
604
+ if type(pairs) == dict:
605
+ pairs = pairs.items()
606
+ pairs = cast(Iterable[Tuple[int, float]], sorted(pairs))
607
+ self.indices = np.array([p[0] for p in pairs], dtype=np.int32)
608
+ """ A list of indices corresponding to active entries. """
609
+ self.values = np.array([p[1] for p in pairs], dtype=np.float64)
610
+ """ A list of values corresponding to active entries. """
611
+ else:
612
+ if isinstance(args[0], bytes):
613
+ assert isinstance(args[1], bytes), "values should be string too"
614
+ if args[0]:
615
+ self.indices = np.frombuffer(args[0], np.int32)
616
+ self.values = np.frombuffer(args[1], np.float64)
617
+ else:
618
+ # np.frombuffer() doesn't work well with empty string in older version
619
+ self.indices = np.array([], dtype=np.int32)
620
+ self.values = np.array([], dtype=np.float64)
621
+ else:
622
+ self.indices = np.array(args[0], dtype=np.int32)
623
+ self.values = np.array(args[1], dtype=np.float64)
624
+ assert len(self.indices) == len(self.values), "index and value arrays not same length"
625
+ for i in range(len(self.indices) - 1):
626
+ if self.indices[i] >= self.indices[i + 1]:
627
+ raise TypeError(
628
+ "Indices %s and %s are not strictly increasing"
629
+ % (self.indices[i], self.indices[i + 1])
630
+ )
631
+
632
+ if self.indices.size > 0:
633
+ assert (
634
+ np.max(self.indices) < self.size
635
+ ), "Index %d is out of the size of vector with size=%d" % (
636
+ np.max(self.indices),
637
+ self.size,
638
+ )
639
+ assert np.min(self.indices) >= 0, "Contains negative index %d" % (np.min(self.indices))
640
+
641
+ def numNonzeros(self) -> int:
642
+ """
643
+ Number of nonzero elements. This scans all active values and count non zeros.
644
+ """
645
+ return np.count_nonzero(self.values)
646
+
647
+ def norm(self, p: "NormType") -> np.float64:
648
+ """
649
+ Calculates the norm of a SparseVector.
650
+
651
+ Examples
652
+ --------
653
+ >>> a = SparseVector(4, [0, 1], [3., -4.])
654
+ >>> a.norm(1)
655
+ 7.0
656
+ >>> a.norm(2)
657
+ 5.0
658
+ """
659
+ return np.linalg.norm(self.values, p)
660
+
661
+ def __reduce__(self) -> Tuple[Type["SparseVector"], Tuple[int, bytes, bytes]]:
662
+ return (SparseVector, (self.size, self.indices.tobytes(), self.values.tobytes()))
663
+
664
+ def dot(self, other: Iterable[float]) -> np.float64:
665
+ """
666
+ Dot product with a SparseVector or 1- or 2-dimensional Numpy array.
667
+
668
+ Examples
669
+ --------
670
+ >>> a = SparseVector(4, [1, 3], [3.0, 4.0])
671
+ >>> a.dot(a)
672
+ 25.0
673
+ >>> a.dot(array.array('d', [1., 2., 3., 4.]))
674
+ 22.0
675
+ >>> b = SparseVector(4, [2], [1.0])
676
+ >>> a.dot(b)
677
+ 0.0
678
+ >>> a.dot(np.array([[1, 1], [2, 2], [3, 3], [4, 4]]))
679
+ array([ 22., 22.])
680
+ >>> a.dot([1., 2., 3.])
681
+ Traceback (most recent call last):
682
+ ...
683
+ AssertionError: dimension mismatch
684
+ >>> a.dot(np.array([1., 2.]))
685
+ Traceback (most recent call last):
686
+ ...
687
+ AssertionError: dimension mismatch
688
+ >>> a.dot(DenseVector([1., 2.]))
689
+ Traceback (most recent call last):
690
+ ...
691
+ AssertionError: dimension mismatch
692
+ >>> a.dot(np.zeros((3, 2)))
693
+ Traceback (most recent call last):
694
+ ...
695
+ AssertionError: dimension mismatch
696
+ """
697
+
698
+ if isinstance(other, np.ndarray):
699
+ if other.ndim not in [2, 1]:
700
+ raise ValueError("Cannot call dot with %d-dimensional array" % other.ndim)
701
+ assert len(self) == other.shape[0], "dimension mismatch"
702
+ return np.dot(self.values, other[self.indices])
703
+
704
+ assert len(self) == _vector_size(other), "dimension mismatch"
705
+
706
+ if isinstance(other, DenseVector):
707
+ return np.dot(other.array[self.indices], self.values)
708
+
709
+ elif isinstance(other, SparseVector):
710
+ # Find out common indices.
711
+ self_cmind = np.in1d(self.indices, other.indices, assume_unique=True)
712
+ self_values = self.values[self_cmind]
713
+ if self_values.size == 0:
714
+ return np.float64(0.0)
715
+ else:
716
+ other_cmind = np.in1d(other.indices, self.indices, assume_unique=True)
717
+ return np.dot(self_values, other.values[other_cmind])
718
+
719
+ else:
720
+ return self.dot(_convert_to_vector(other)) # type: ignore[arg-type]
721
+
722
+ def squared_distance(self, other: Iterable[float]) -> np.float64:
723
+ """
724
+ Squared distance from a SparseVector or 1-dimensional NumPy array.
725
+
726
+ Examples
727
+ --------
728
+ >>> a = SparseVector(4, [1, 3], [3.0, 4.0])
729
+ >>> a.squared_distance(a)
730
+ 0.0
731
+ >>> a.squared_distance(array.array('d', [1., 2., 3., 4.]))
732
+ 11.0
733
+ >>> a.squared_distance(np.array([1., 2., 3., 4.]))
734
+ 11.0
735
+ >>> b = SparseVector(4, [2], [1.0])
736
+ >>> a.squared_distance(b)
737
+ 26.0
738
+ >>> b.squared_distance(a)
739
+ 26.0
740
+ >>> b.squared_distance([1., 2.])
741
+ Traceback (most recent call last):
742
+ ...
743
+ AssertionError: dimension mismatch
744
+ >>> b.squared_distance(SparseVector(3, [1,], [1.0,]))
745
+ Traceback (most recent call last):
746
+ ...
747
+ AssertionError: dimension mismatch
748
+ """
749
+ assert len(self) == _vector_size(other), "dimension mismatch"
750
+
751
+ if isinstance(other, np.ndarray) or isinstance(other, DenseVector):
752
+ if isinstance(other, np.ndarray) and other.ndim != 1:
753
+ raise ValueError(
754
+ "Cannot call squared_distance with %d-dimensional array" % other.ndim
755
+ )
756
+ if isinstance(other, DenseVector):
757
+ other = other.array
758
+ sparse_ind = np.zeros(other.size, dtype=bool)
759
+ sparse_ind[self.indices] = True
760
+ dist = other[sparse_ind] - self.values
761
+ result = np.dot(dist, dist)
762
+
763
+ other_ind = other[~sparse_ind]
764
+ result += np.dot(other_ind, other_ind)
765
+ return result
766
+
767
+ elif isinstance(other, SparseVector):
768
+ result = 0.0
769
+ i, j = 0, 0
770
+ while i < len(self.indices) and j < len(other.indices):
771
+ if self.indices[i] == other.indices[j]:
772
+ diff = self.values[i] - other.values[j]
773
+ result += diff * diff
774
+ i += 1
775
+ j += 1
776
+ elif self.indices[i] < other.indices[j]:
777
+ result += self.values[i] * self.values[i]
778
+ i += 1
779
+ else:
780
+ result += other.values[j] * other.values[j]
781
+ j += 1
782
+ while i < len(self.indices):
783
+ result += self.values[i] * self.values[i]
784
+ i += 1
785
+ while j < len(other.indices):
786
+ result += other.values[j] * other.values[j]
787
+ j += 1
788
+ return result
789
+ else:
790
+ return self.squared_distance(_convert_to_vector(other)) # type: ignore[arg-type]
791
+
792
+ def toArray(self) -> np.ndarray:
793
+ """
794
+ Returns a copy of this SparseVector as a 1-dimensional numpy.ndarray.
795
+ """
796
+ arr = np.zeros((self.size,), dtype=np.float64)
797
+ arr[self.indices] = self.values
798
+ return arr
799
+
800
+ def __len__(self) -> int:
801
+ return self.size
802
+
803
+ def __str__(self) -> str:
804
+ inds = "[" + ",".join([str(i) for i in self.indices]) + "]"
805
+ vals = "[" + ",".join([str(v) for v in self.values]) + "]"
806
+ return "(" + ",".join((str(self.size), inds, vals)) + ")"
807
+
808
+ def __repr__(self) -> str:
809
+ inds = self.indices
810
+ vals = self.values
811
+ entries = ", ".join(
812
+ ["{0}: {1}".format(inds[i], _format_float(vals[i])) for i in range(len(inds))]
813
+ )
814
+ return "SparseVector({0}, {{{1}}})".format(self.size, entries)
815
+
816
+ def __eq__(self, other: Any) -> bool:
817
+ if isinstance(other, SparseVector):
818
+ return (
819
+ other.size == self.size
820
+ and np.array_equal(other.indices, self.indices)
821
+ and np.array_equal(other.values, self.values)
822
+ )
823
+ elif isinstance(other, DenseVector):
824
+ if self.size != len(other):
825
+ return False
826
+ return Vectors._equals(self.indices, self.values, list(range(len(other))), other.array)
827
+ return False
828
+
829
+ def __getitem__(self, index: int) -> np.float64:
830
+ inds = self.indices
831
+ vals = self.values
832
+ if not isinstance(index, int):
833
+ raise TypeError("Indices must be of type integer, got type %s" % type(index))
834
+
835
+ if index >= self.size or index < -self.size:
836
+ raise IndexError("Index %d out of bounds." % index)
837
+ if index < 0:
838
+ index += self.size
839
+
840
+ if (inds.size == 0) or (index > inds.item(-1)):
841
+ return np.float64(0.0)
842
+
843
+ insert_index = np.searchsorted(inds, index)
844
+ row_ind = inds[insert_index]
845
+ if row_ind == index:
846
+ return vals[insert_index]
847
+ return np.float64(0.0)
848
+
849
+ def __ne__(self, other: Any) -> bool:
850
+ return not self.__eq__(other)
851
+
852
+ def __hash__(self) -> int:
853
+ result = 31 + self.size
854
+ nnz = 0
855
+ i = 0
856
+ while i < len(self.values) and nnz < 128:
857
+ if self.values[i] != 0:
858
+ result = 31 * result + int(self.indices[i])
859
+ bits = _double_to_long_bits(self.values[i])
860
+ result = 31 * result + (bits ^ (bits >> 32))
861
+ nnz += 1
862
+ i += 1
863
+ return result
864
+
865
+
866
+ class Vectors:
867
+
868
+ """
869
+ Factory methods for working with vectors.
870
+
871
+ Notes
872
+ -----
873
+ Dense vectors are simply represented as NumPy array objects,
874
+ so there is no need to convert them for use in MLlib. For sparse vectors,
875
+ the factory methods in this class create an MLlib-compatible type, or users
876
+ can pass in SciPy's `scipy.sparse` column vectors.
877
+ """
878
+
879
+ @staticmethod
880
+ @overload
881
+ def sparse(size: int, __indices: bytes, __values: bytes) -> SparseVector:
882
+ ...
883
+
884
+ @staticmethod
885
+ @overload
886
+ def sparse(size: int, *args: Tuple[int, float]) -> SparseVector:
887
+ ...
888
+
889
+ @staticmethod
890
+ @overload
891
+ def sparse(size: int, __indices: Iterable[int], __values: Iterable[float]) -> SparseVector:
892
+ ...
893
+
894
+ @staticmethod
895
+ @overload
896
+ def sparse(size: int, __pairs: Iterable[Tuple[int, float]]) -> SparseVector:
897
+ ...
898
+
899
+ @staticmethod
900
+ @overload
901
+ def sparse(size: int, __map: Dict[int, float]) -> SparseVector:
902
+ ...
903
+
904
+ @staticmethod
905
+ def sparse(
906
+ size: int,
907
+ *args: Union[
908
+ bytes, Tuple[int, float], Iterable[float], Iterable[Tuple[int, float]], Dict[int, float]
909
+ ],
910
+ ) -> SparseVector:
911
+ """
912
+ Create a sparse vector, using either a dictionary, a list of
913
+ (index, value) pairs, or two separate arrays of indices and
914
+ values (sorted by index).
915
+
916
+ Parameters
917
+ ----------
918
+ size : int
919
+ Size of the vector.
920
+ args
921
+ Non-zero entries, as a dictionary, list of tuples,
922
+ or two sorted lists containing indices and values.
923
+
924
+ Examples
925
+ --------
926
+ >>> Vectors.sparse(4, {1: 1.0, 3: 5.5})
927
+ SparseVector(4, {1: 1.0, 3: 5.5})
928
+ >>> Vectors.sparse(4, [(1, 1.0), (3, 5.5)])
929
+ SparseVector(4, {1: 1.0, 3: 5.5})
930
+ >>> Vectors.sparse(4, [1, 3], [1.0, 5.5])
931
+ SparseVector(4, {1: 1.0, 3: 5.5})
932
+ """
933
+ return SparseVector(size, *args) # type: ignore[arg-type]
934
+
935
+ @overload
936
+ @staticmethod
937
+ def dense(*elements: float) -> DenseVector:
938
+ ...
939
+
940
+ @overload
941
+ @staticmethod
942
+ def dense(__arr: bytes) -> DenseVector:
943
+ ...
944
+
945
+ @overload
946
+ @staticmethod
947
+ def dense(__arr: Iterable[float]) -> DenseVector:
948
+ ...
949
+
950
+ @staticmethod
951
+ def dense(*elements: Union[float, bytes, np.ndarray, Iterable[float]]) -> DenseVector:
952
+ """
953
+ Create a dense vector of 64-bit floats from a Python list or numbers.
954
+
955
+ Examples
956
+ --------
957
+ >>> Vectors.dense([1, 2, 3])
958
+ DenseVector([1.0, 2.0, 3.0])
959
+ >>> Vectors.dense(1.0, 2.0)
960
+ DenseVector([1.0, 2.0])
961
+ """
962
+ if len(elements) == 1 and not isinstance(elements[0], (float, int)):
963
+ # it's list, numpy.array or other iterable object.
964
+ elements = elements[0] # type: ignore[assignment]
965
+ return DenseVector(cast(Iterable[float], elements))
966
+
967
+ @staticmethod
968
+ def squared_distance(v1: Vector, v2: Vector) -> np.float64:
969
+ """
970
+ Squared distance between two vectors.
971
+ a and b can be of type SparseVector, DenseVector, np.ndarray
972
+ or array.array.
973
+
974
+ Examples
975
+ --------
976
+ >>> a = Vectors.sparse(4, [(0, 1), (3, 4)])
977
+ >>> b = Vectors.dense([2, 5, 4, 1])
978
+ >>> a.squared_distance(b)
979
+ 51.0
980
+ """
981
+ v1, v2 = _convert_to_vector(v1), _convert_to_vector(v2)
982
+ return v1.squared_distance(v2) # type: ignore[attr-defined]
983
+
984
+ @staticmethod
985
+ def norm(vector: Vector, p: "NormType") -> np.float64:
986
+ """
987
+ Find norm of the given vector.
988
+ """
989
+ return _convert_to_vector(vector).norm(p) # type: ignore[attr-defined]
990
+
991
+ @staticmethod
992
+ def zeros(size: int) -> DenseVector:
993
+ return DenseVector(np.zeros(size))
994
+
995
+ @staticmethod
996
+ def _equals(
997
+ v1_indices: Union[Sequence[int], np.ndarray],
998
+ v1_values: Union[Sequence[float], np.ndarray],
999
+ v2_indices: Union[Sequence[int], np.ndarray],
1000
+ v2_values: Union[Sequence[float], np.ndarray],
1001
+ ) -> bool:
1002
+ """
1003
+ Check equality between sparse/dense vectors,
1004
+ v1_indices and v2_indices assume to be strictly increasing.
1005
+ """
1006
+ v1_size = len(v1_values)
1007
+ v2_size = len(v2_values)
1008
+ k1 = 0
1009
+ k2 = 0
1010
+ all_equal = True
1011
+ while all_equal:
1012
+ while k1 < v1_size and v1_values[k1] == 0:
1013
+ k1 += 1
1014
+ while k2 < v2_size and v2_values[k2] == 0:
1015
+ k2 += 1
1016
+
1017
+ if k1 >= v1_size or k2 >= v2_size:
1018
+ return k1 >= v1_size and k2 >= v2_size
1019
+
1020
+ all_equal = v1_indices[k1] == v2_indices[k2] and v1_values[k1] == v2_values[k2]
1021
+ k1 += 1
1022
+ k2 += 1
1023
+ return all_equal
1024
+
1025
+
1026
+ class Matrix:
1027
+
1028
+ __UDT__ = MatrixUDT()
1029
+
1030
+ """
1031
+ Represents a local matrix.
1032
+ """
1033
+
1034
+ def __init__(self, numRows: int, numCols: int, isTransposed: bool = False):
1035
+ self.numRows = numRows
1036
+ self.numCols = numCols
1037
+ self.isTransposed = isTransposed
1038
+
1039
+ def toArray(self) -> np.ndarray:
1040
+ """
1041
+ Returns its elements in a numpy.ndarray.
1042
+ """
1043
+ raise NotImplementedError
1044
+
1045
+ @staticmethod
1046
+ def _convert_to_array(array_like: Union[bytes, Iterable[float]], dtype: Any) -> np.ndarray:
1047
+ """
1048
+ Convert Matrix attributes which are array-like or buffer to array.
1049
+ """
1050
+ if isinstance(array_like, bytes):
1051
+ return np.frombuffer(array_like, dtype=dtype)
1052
+ return np.asarray(array_like, dtype=dtype)
1053
+
1054
+
1055
+ class DenseMatrix(Matrix):
1056
+ """
1057
+ Column-major dense matrix.
1058
+ """
1059
+
1060
+ def __init__(
1061
+ self,
1062
+ numRows: int,
1063
+ numCols: int,
1064
+ values: Union[bytes, Iterable[float]],
1065
+ isTransposed: bool = False,
1066
+ ):
1067
+ Matrix.__init__(self, numRows, numCols, isTransposed)
1068
+ values = self._convert_to_array(values, np.float64)
1069
+ assert len(values) == numRows * numCols
1070
+ self.values = values
1071
+
1072
+ def __reduce__(self) -> Tuple[Type["DenseMatrix"], Tuple[int, int, bytes, int]]:
1073
+ return DenseMatrix, (
1074
+ self.numRows,
1075
+ self.numCols,
1076
+ self.values.tobytes(),
1077
+ int(self.isTransposed),
1078
+ )
1079
+
1080
+ def __str__(self) -> str:
1081
+ """
1082
+ Pretty printing of a DenseMatrix
1083
+
1084
+ Examples
1085
+ --------
1086
+ >>> dm = DenseMatrix(2, 2, range(4))
1087
+ >>> print(dm)
1088
+ DenseMatrix([[ 0., 2.],
1089
+ [ 1., 3.]])
1090
+ >>> dm = DenseMatrix(2, 2, range(4), isTransposed=True)
1091
+ >>> print(dm)
1092
+ DenseMatrix([[ 0., 1.],
1093
+ [ 2., 3.]])
1094
+ """
1095
+ # Inspired by __repr__ in scipy matrices.
1096
+ array_lines = repr(self.toArray()).splitlines()
1097
+
1098
+ # We need to adjust six spaces which is the difference in number
1099
+ # of letters between "DenseMatrix" and "array"
1100
+ x = "\n".join([(" " * 6 + line) for line in array_lines[1:]])
1101
+ return array_lines[0].replace("array", "DenseMatrix") + "\n" + x
1102
+
1103
+ def __repr__(self) -> str:
1104
+ """
1105
+ Representation of a DenseMatrix
1106
+
1107
+ Examples
1108
+ --------
1109
+ >>> dm = DenseMatrix(2, 2, range(4))
1110
+ >>> dm
1111
+ DenseMatrix(2, 2, [0.0, 1.0, 2.0, 3.0], False)
1112
+ """
1113
+ # If the number of values are less than seventeen then return as it is.
1114
+ # Else return first eight values and last eight values.
1115
+ if len(self.values) < 17:
1116
+ entries = _format_float_list(self.values)
1117
+ else:
1118
+ entries = (
1119
+ _format_float_list(self.values[:8]) + ["..."] + _format_float_list(self.values[-8:])
1120
+ )
1121
+
1122
+ entries = ", ".join(entries) # type: ignore[assignment]
1123
+ return "DenseMatrix({0}, {1}, [{2}], {3})".format(
1124
+ self.numRows, self.numCols, entries, self.isTransposed
1125
+ )
1126
+
1127
+ def toArray(self) -> np.ndarray:
1128
+ """
1129
+ Return a :py:class:`numpy.ndarray`
1130
+
1131
+ Examples
1132
+ --------
1133
+ >>> m = DenseMatrix(2, 2, range(4))
1134
+ >>> m.toArray()
1135
+ array([[ 0., 2.],
1136
+ [ 1., 3.]])
1137
+ """
1138
+ if self.isTransposed:
1139
+ return np.asfortranarray(self.values.reshape((self.numRows, self.numCols)))
1140
+ else:
1141
+ return self.values.reshape((self.numRows, self.numCols), order="F")
1142
+
1143
+ def toSparse(self) -> "SparseMatrix":
1144
+ """Convert to SparseMatrix"""
1145
+ if self.isTransposed:
1146
+ values = np.ravel(self.toArray(), order="F")
1147
+ else:
1148
+ values = self.values
1149
+ indices = np.nonzero(values)[0]
1150
+ colCounts = np.bincount(indices // self.numRows)
1151
+ colPtrs = np.cumsum(np.hstack((0, colCounts, np.zeros(self.numCols - colCounts.size))))
1152
+ values = values[indices]
1153
+ rowIndices = indices % self.numRows
1154
+
1155
+ return SparseMatrix(self.numRows, self.numCols, colPtrs, rowIndices, values)
1156
+
1157
+ def __getitem__(self, indices: Tuple[int, int]) -> np.float64:
1158
+ i, j = indices
1159
+ if i < 0 or i >= self.numRows:
1160
+ raise IndexError("Row index %d is out of range [0, %d)" % (i, self.numRows))
1161
+ if j >= self.numCols or j < 0:
1162
+ raise IndexError("Column index %d is out of range [0, %d)" % (j, self.numCols))
1163
+
1164
+ if self.isTransposed:
1165
+ return self.values[i * self.numCols + j]
1166
+ else:
1167
+ return self.values[i + j * self.numRows]
1168
+
1169
+ def __eq__(self, other: Any) -> bool:
1170
+ if self.numRows != other.numRows or self.numCols != other.numCols:
1171
+ return False
1172
+ if isinstance(other, SparseMatrix):
1173
+ return np.all(self.toArray() == other.toArray()).tolist()
1174
+
1175
+ self_values = np.ravel(self.toArray(), order="F")
1176
+ other_values = np.ravel(other.toArray(), order="F")
1177
+ return np.all(self_values == other_values).tolist()
1178
+
1179
+
1180
+ class SparseMatrix(Matrix):
1181
+ """Sparse Matrix stored in CSC format."""
1182
+
1183
+ def __init__(
1184
+ self,
1185
+ numRows: int,
1186
+ numCols: int,
1187
+ colPtrs: Union[bytes, Iterable[int]],
1188
+ rowIndices: Union[bytes, Iterable[int]],
1189
+ values: Union[bytes, Iterable[float]],
1190
+ isTransposed: bool = False,
1191
+ ):
1192
+ Matrix.__init__(self, numRows, numCols, isTransposed)
1193
+ self.colPtrs = self._convert_to_array(colPtrs, np.int32)
1194
+ self.rowIndices = self._convert_to_array(rowIndices, np.int32)
1195
+ self.values = self._convert_to_array(values, np.float64)
1196
+
1197
+ if self.isTransposed:
1198
+ if self.colPtrs.size != numRows + 1:
1199
+ raise ValueError(
1200
+ "Expected colPtrs of size %d, got %d." % (numRows + 1, self.colPtrs.size)
1201
+ )
1202
+ else:
1203
+ if self.colPtrs.size != numCols + 1:
1204
+ raise ValueError(
1205
+ "Expected colPtrs of size %d, got %d." % (numCols + 1, self.colPtrs.size)
1206
+ )
1207
+ if self.rowIndices.size != self.values.size:
1208
+ raise ValueError(
1209
+ "Expected rowIndices of length %d, got %d."
1210
+ % (self.rowIndices.size, self.values.size)
1211
+ )
1212
+
1213
+ def __str__(self) -> str:
1214
+ """
1215
+ Pretty printing of a SparseMatrix
1216
+
1217
+ Examples
1218
+ --------
1219
+ >>> sm1 = SparseMatrix(2, 2, [0, 2, 3], [0, 1, 1], [2, 3, 4])
1220
+ >>> print(sm1)
1221
+ 2 X 2 CSCMatrix
1222
+ (0,0) 2.0
1223
+ (1,0) 3.0
1224
+ (1,1) 4.0
1225
+ >>> sm1 = SparseMatrix(2, 2, [0, 2, 3], [0, 1, 1], [2, 3, 4], True)
1226
+ >>> print(sm1)
1227
+ 2 X 2 CSRMatrix
1228
+ (0,0) 2.0
1229
+ (0,1) 3.0
1230
+ (1,1) 4.0
1231
+ """
1232
+ spstr = "{0} X {1} ".format(self.numRows, self.numCols)
1233
+ if self.isTransposed:
1234
+ spstr += "CSRMatrix\n"
1235
+ else:
1236
+ spstr += "CSCMatrix\n"
1237
+
1238
+ cur_col = 0
1239
+ smlist = []
1240
+
1241
+ # Display first 16 values.
1242
+ if len(self.values) <= 16:
1243
+ zipindval = zip(self.rowIndices, self.values)
1244
+ else:
1245
+ zipindval = zip(self.rowIndices[:16], self.values[:16])
1246
+ for i, (rowInd, value) in enumerate(zipindval):
1247
+ if self.colPtrs[cur_col + 1] <= i:
1248
+ cur_col += 1
1249
+ if self.isTransposed:
1250
+ smlist.append("({0},{1}) {2}".format(cur_col, rowInd, _format_float(value)))
1251
+ else:
1252
+ smlist.append("({0},{1}) {2}".format(rowInd, cur_col, _format_float(value)))
1253
+ spstr += "\n".join(smlist)
1254
+
1255
+ if len(self.values) > 16:
1256
+ spstr += "\n.." * 2
1257
+ return spstr
1258
+
1259
+ def __repr__(self) -> str:
1260
+ """
1261
+ Representation of a SparseMatrix
1262
+
1263
+ Examples
1264
+ --------
1265
+ >>> sm1 = SparseMatrix(2, 2, [0, 2, 3], [0, 1, 1], [2, 3, 4])
1266
+ >>> sm1
1267
+ SparseMatrix(2, 2, [0, 2, 3], [0, 1, 1], [2.0, 3.0, 4.0], False)
1268
+ """
1269
+ rowIndices = list(self.rowIndices)
1270
+ colPtrs = list(self.colPtrs)
1271
+
1272
+ if len(self.values) <= 16:
1273
+ values = _format_float_list(self.values)
1274
+
1275
+ else:
1276
+ values = (
1277
+ _format_float_list(self.values[:8]) + ["..."] + _format_float_list(self.values[-8:])
1278
+ )
1279
+ rowIndices = rowIndices[:8] + ["..."] + rowIndices[-8:]
1280
+
1281
+ if len(self.colPtrs) > 16:
1282
+ colPtrs = colPtrs[:8] + ["..."] + colPtrs[-8:]
1283
+
1284
+ values = ", ".join(values) # type: ignore[assignment]
1285
+ rowIndices = ", ".join([str(ind) for ind in rowIndices]) # type: ignore[assignment]
1286
+ colPtrs = ", ".join([str(ptr) for ptr in colPtrs]) # type: ignore[assignment]
1287
+ return "SparseMatrix({0}, {1}, [{2}], [{3}], [{4}], {5})".format(
1288
+ self.numRows, self.numCols, colPtrs, rowIndices, values, self.isTransposed
1289
+ )
1290
+
1291
+ def __reduce__(self) -> Tuple[Type["SparseMatrix"], Tuple[int, int, bytes, bytes, bytes, int]]:
1292
+ return SparseMatrix, (
1293
+ self.numRows,
1294
+ self.numCols,
1295
+ self.colPtrs.tobytes(),
1296
+ self.rowIndices.tobytes(),
1297
+ self.values.tobytes(),
1298
+ int(self.isTransposed),
1299
+ )
1300
+
1301
+ def __getitem__(self, indices: Tuple[int, int]) -> np.float64:
1302
+ i, j = indices
1303
+ if i < 0 or i >= self.numRows:
1304
+ raise IndexError("Row index %d is out of range [0, %d)" % (i, self.numRows))
1305
+ if j < 0 or j >= self.numCols:
1306
+ raise IndexError("Column index %d is out of range [0, %d)" % (j, self.numCols))
1307
+
1308
+ # If a CSR matrix is given, then the row index should be searched
1309
+ # for in ColPtrs, and the column index should be searched for in the
1310
+ # corresponding slice obtained from rowIndices.
1311
+ if self.isTransposed:
1312
+ j, i = i, j
1313
+
1314
+ colStart = self.colPtrs[j]
1315
+ colEnd = self.colPtrs[j + 1]
1316
+ nz = self.rowIndices[colStart:colEnd]
1317
+ ind = np.searchsorted(nz, i) + colStart
1318
+ if ind < colEnd and self.rowIndices[ind] == i:
1319
+ return self.values[ind]
1320
+ else:
1321
+ return np.float64(0.0)
1322
+
1323
+ def toArray(self) -> np.ndarray:
1324
+ """
1325
+ Return a numpy.ndarray
1326
+ """
1327
+ A = np.zeros((self.numRows, self.numCols), dtype=np.float64, order="F")
1328
+ for k in range(self.colPtrs.size - 1):
1329
+ startptr = self.colPtrs[k]
1330
+ endptr = self.colPtrs[k + 1]
1331
+ if self.isTransposed:
1332
+ A[k, self.rowIndices[startptr:endptr]] = self.values[startptr:endptr]
1333
+ else:
1334
+ A[self.rowIndices[startptr:endptr], k] = self.values[startptr:endptr]
1335
+ return A
1336
+
1337
+ def toDense(self) -> "DenseMatrix":
1338
+ densevals = np.ravel(self.toArray(), order="F")
1339
+ return DenseMatrix(self.numRows, self.numCols, densevals)
1340
+
1341
+ # TODO: More efficient implementation:
1342
+ def __eq__(self, other: Any) -> bool:
1343
+ return np.all(self.toArray() == other.toArray()).tolist()
1344
+
1345
+
1346
+ class Matrices:
1347
+ @staticmethod
1348
+ def dense(numRows: int, numCols: int, values: Union[bytes, Iterable[float]]) -> DenseMatrix:
1349
+ """
1350
+ Create a DenseMatrix
1351
+ """
1352
+ return DenseMatrix(numRows, numCols, values)
1353
+
1354
+ @staticmethod
1355
+ def sparse(
1356
+ numRows: int,
1357
+ numCols: int,
1358
+ colPtrs: Union[bytes, Iterable[int]],
1359
+ rowIndices: Union[bytes, Iterable[int]],
1360
+ values: Union[bytes, Iterable[float]],
1361
+ ) -> SparseMatrix:
1362
+ """
1363
+ Create a SparseMatrix
1364
+ """
1365
+ return SparseMatrix(numRows, numCols, colPtrs, rowIndices, values)
1366
+
1367
+
1368
+ def _test() -> None:
1369
+ import doctest
1370
+
1371
+ try:
1372
+ # Numpy 1.14+ changed it's string format.
1373
+ np.set_printoptions(legacy="1.13")
1374
+ except TypeError:
1375
+ pass
1376
+ (failure_count, test_count) = doctest.testmod(optionflags=doctest.ELLIPSIS)
1377
+ if failure_count:
1378
+ sys.exit(-1)
1379
+
1380
+
1381
+ if __name__ == "__main__":
1382
+ _test()