maxframe 2.2.0__cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.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 maxframe might be problematic. Click here for more details.

Files changed (1094) hide show
  1. maxframe/__init__.py +33 -0
  2. maxframe/_utils.cpython-312-aarch64-linux-gnu.so +0 -0
  3. maxframe/_utils.pxd +33 -0
  4. maxframe/_utils.pyi +21 -0
  5. maxframe/_utils.pyx +561 -0
  6. maxframe/codegen/__init__.py +27 -0
  7. maxframe/codegen/core.py +596 -0
  8. maxframe/codegen/spe/__init__.py +16 -0
  9. maxframe/codegen/spe/core.py +307 -0
  10. maxframe/codegen/spe/dataframe/__init__.py +38 -0
  11. maxframe/codegen/spe/dataframe/accessors/__init__.py +15 -0
  12. maxframe/codegen/spe/dataframe/accessors/base.py +71 -0
  13. maxframe/codegen/spe/dataframe/accessors/dict_.py +89 -0
  14. maxframe/codegen/spe/dataframe/accessors/list_.py +44 -0
  15. maxframe/codegen/spe/dataframe/accessors/struct_.py +28 -0
  16. maxframe/codegen/spe/dataframe/arithmetic.py +89 -0
  17. maxframe/codegen/spe/dataframe/datasource.py +181 -0
  18. maxframe/codegen/spe/dataframe/datastore.py +204 -0
  19. maxframe/codegen/spe/dataframe/extensions.py +63 -0
  20. maxframe/codegen/spe/dataframe/fetch.py +26 -0
  21. maxframe/codegen/spe/dataframe/groupby.py +312 -0
  22. maxframe/codegen/spe/dataframe/indexing.py +333 -0
  23. maxframe/codegen/spe/dataframe/merge.py +106 -0
  24. maxframe/codegen/spe/dataframe/misc.py +262 -0
  25. maxframe/codegen/spe/dataframe/missing.py +64 -0
  26. maxframe/codegen/spe/dataframe/reduction.py +165 -0
  27. maxframe/codegen/spe/dataframe/reshape.py +46 -0
  28. maxframe/codegen/spe/dataframe/sort.py +96 -0
  29. maxframe/codegen/spe/dataframe/statistics.py +46 -0
  30. maxframe/codegen/spe/dataframe/tests/__init__.py +13 -0
  31. maxframe/codegen/spe/dataframe/tests/accessors/__init__.py +13 -0
  32. maxframe/codegen/spe/dataframe/tests/accessors/test_base.py +33 -0
  33. maxframe/codegen/spe/dataframe/tests/accessors/test_dict.py +304 -0
  34. maxframe/codegen/spe/dataframe/tests/accessors/test_list.py +134 -0
  35. maxframe/codegen/spe/dataframe/tests/accessors/test_struct.py +75 -0
  36. maxframe/codegen/spe/dataframe/tests/indexing/__init__.py +13 -0
  37. maxframe/codegen/spe/dataframe/tests/indexing/conftest.py +58 -0
  38. maxframe/codegen/spe/dataframe/tests/indexing/test_getitem.py +124 -0
  39. maxframe/codegen/spe/dataframe/tests/indexing/test_iloc.py +95 -0
  40. maxframe/codegen/spe/dataframe/tests/indexing/test_indexing.py +39 -0
  41. maxframe/codegen/spe/dataframe/tests/indexing/test_loc.py +35 -0
  42. maxframe/codegen/spe/dataframe/tests/indexing/test_rename.py +51 -0
  43. maxframe/codegen/spe/dataframe/tests/indexing/test_reset_index.py +88 -0
  44. maxframe/codegen/spe/dataframe/tests/indexing/test_sample.py +45 -0
  45. maxframe/codegen/spe/dataframe/tests/indexing/test_set_axis.py +45 -0
  46. maxframe/codegen/spe/dataframe/tests/indexing/test_set_index.py +41 -0
  47. maxframe/codegen/spe/dataframe/tests/indexing/test_setitem.py +46 -0
  48. maxframe/codegen/spe/dataframe/tests/misc/__init__.py +13 -0
  49. maxframe/codegen/spe/dataframe/tests/misc/test_apply.py +133 -0
  50. maxframe/codegen/spe/dataframe/tests/misc/test_drop_duplicates.py +92 -0
  51. maxframe/codegen/spe/dataframe/tests/misc/test_misc.py +202 -0
  52. maxframe/codegen/spe/dataframe/tests/missing/__init__.py +13 -0
  53. maxframe/codegen/spe/dataframe/tests/missing/test_checkna.py +94 -0
  54. maxframe/codegen/spe/dataframe/tests/missing/test_dropna.py +50 -0
  55. maxframe/codegen/spe/dataframe/tests/missing/test_fillna.py +94 -0
  56. maxframe/codegen/spe/dataframe/tests/missing/test_replace.py +45 -0
  57. maxframe/codegen/spe/dataframe/tests/test_arithmetic.py +73 -0
  58. maxframe/codegen/spe/dataframe/tests/test_datasource.py +184 -0
  59. maxframe/codegen/spe/dataframe/tests/test_datastore.py +200 -0
  60. maxframe/codegen/spe/dataframe/tests/test_extensions.py +88 -0
  61. maxframe/codegen/spe/dataframe/tests/test_groupby.py +288 -0
  62. maxframe/codegen/spe/dataframe/tests/test_merge.py +426 -0
  63. maxframe/codegen/spe/dataframe/tests/test_reduction.py +104 -0
  64. maxframe/codegen/spe/dataframe/tests/test_reshape.py +79 -0
  65. maxframe/codegen/spe/dataframe/tests/test_sort.py +179 -0
  66. maxframe/codegen/spe/dataframe/tests/test_statistics.py +70 -0
  67. maxframe/codegen/spe/dataframe/tests/test_tseries.py +29 -0
  68. maxframe/codegen/spe/dataframe/tests/test_value_counts.py +60 -0
  69. maxframe/codegen/spe/dataframe/tests/test_window.py +69 -0
  70. maxframe/codegen/spe/dataframe/tseries.py +46 -0
  71. maxframe/codegen/spe/dataframe/udf.py +62 -0
  72. maxframe/codegen/spe/dataframe/value_counts.py +31 -0
  73. maxframe/codegen/spe/dataframe/window.py +65 -0
  74. maxframe/codegen/spe/learn/__init__.py +15 -0
  75. maxframe/codegen/spe/learn/contrib/__init__.py +15 -0
  76. maxframe/codegen/spe/learn/contrib/lightgbm.py +160 -0
  77. maxframe/codegen/spe/learn/contrib/models.py +41 -0
  78. maxframe/codegen/spe/learn/contrib/pytorch.py +49 -0
  79. maxframe/codegen/spe/learn/contrib/tests/__init__.py +13 -0
  80. maxframe/codegen/spe/learn/contrib/tests/test_lightgbm.py +123 -0
  81. maxframe/codegen/spe/learn/contrib/tests/test_models.py +41 -0
  82. maxframe/codegen/spe/learn/contrib/tests/test_pytorch.py +53 -0
  83. maxframe/codegen/spe/learn/contrib/tests/test_xgboost.py +99 -0
  84. maxframe/codegen/spe/learn/contrib/xgboost.py +152 -0
  85. maxframe/codegen/spe/learn/metrics/__init__.py +15 -0
  86. maxframe/codegen/spe/learn/metrics/_classification.py +120 -0
  87. maxframe/codegen/spe/learn/metrics/_ranking.py +76 -0
  88. maxframe/codegen/spe/learn/metrics/pairwise.py +51 -0
  89. maxframe/codegen/spe/learn/metrics/tests/__init__.py +13 -0
  90. maxframe/codegen/spe/learn/metrics/tests/test_classification.py +93 -0
  91. maxframe/codegen/spe/learn/metrics/tests/test_pairwise.py +36 -0
  92. maxframe/codegen/spe/learn/metrics/tests/test_ranking.py +59 -0
  93. maxframe/codegen/spe/learn/model_selection/__init__.py +13 -0
  94. maxframe/codegen/spe/learn/model_selection/tests/__init__.py +13 -0
  95. maxframe/codegen/spe/learn/model_selection/tests/test_split.py +41 -0
  96. maxframe/codegen/spe/learn/preprocessing/__init__.py +15 -0
  97. maxframe/codegen/spe/learn/preprocessing/_data.py +37 -0
  98. maxframe/codegen/spe/learn/preprocessing/_label.py +47 -0
  99. maxframe/codegen/spe/learn/preprocessing/tests/__init__.py +13 -0
  100. maxframe/codegen/spe/learn/preprocessing/tests/test_data.py +31 -0
  101. maxframe/codegen/spe/learn/preprocessing/tests/test_label.py +43 -0
  102. maxframe/codegen/spe/learn/utils/__init__.py +15 -0
  103. maxframe/codegen/spe/learn/utils/checks.py +55 -0
  104. maxframe/codegen/spe/learn/utils/multiclass.py +60 -0
  105. maxframe/codegen/spe/learn/utils/shuffle.py +85 -0
  106. maxframe/codegen/spe/learn/utils/sparsefuncs.py +35 -0
  107. maxframe/codegen/spe/learn/utils/tests/__init__.py +13 -0
  108. maxframe/codegen/spe/learn/utils/tests/test_checks.py +48 -0
  109. maxframe/codegen/spe/learn/utils/tests/test_multiclass.py +52 -0
  110. maxframe/codegen/spe/learn/utils/tests/test_shuffle.py +50 -0
  111. maxframe/codegen/spe/learn/utils/tests/test_sparsefuncs.py +34 -0
  112. maxframe/codegen/spe/learn/utils/tests/test_validation.py +44 -0
  113. maxframe/codegen/spe/learn/utils/validation.py +35 -0
  114. maxframe/codegen/spe/objects.py +26 -0
  115. maxframe/codegen/spe/remote.py +29 -0
  116. maxframe/codegen/spe/tensor/__init__.py +31 -0
  117. maxframe/codegen/spe/tensor/arithmetic.py +95 -0
  118. maxframe/codegen/spe/tensor/core.py +41 -0
  119. maxframe/codegen/spe/tensor/datasource.py +165 -0
  120. maxframe/codegen/spe/tensor/extensions.py +35 -0
  121. maxframe/codegen/spe/tensor/fetch.py +26 -0
  122. maxframe/codegen/spe/tensor/fft.py +74 -0
  123. maxframe/codegen/spe/tensor/indexing.py +63 -0
  124. maxframe/codegen/spe/tensor/linalg.py +90 -0
  125. maxframe/codegen/spe/tensor/merge.py +31 -0
  126. maxframe/codegen/spe/tensor/misc.py +175 -0
  127. maxframe/codegen/spe/tensor/random.py +29 -0
  128. maxframe/codegen/spe/tensor/reduction.py +39 -0
  129. maxframe/codegen/spe/tensor/reshape.py +26 -0
  130. maxframe/codegen/spe/tensor/sort.py +42 -0
  131. maxframe/codegen/spe/tensor/spatial.py +45 -0
  132. maxframe/codegen/spe/tensor/special.py +35 -0
  133. maxframe/codegen/spe/tensor/statistics.py +68 -0
  134. maxframe/codegen/spe/tensor/tests/__init__.py +13 -0
  135. maxframe/codegen/spe/tensor/tests/test_arithmetic.py +103 -0
  136. maxframe/codegen/spe/tensor/tests/test_datasource.py +99 -0
  137. maxframe/codegen/spe/tensor/tests/test_extensions.py +37 -0
  138. maxframe/codegen/spe/tensor/tests/test_fft.py +64 -0
  139. maxframe/codegen/spe/tensor/tests/test_indexing.py +44 -0
  140. maxframe/codegen/spe/tensor/tests/test_linalg.py +52 -0
  141. maxframe/codegen/spe/tensor/tests/test_merge.py +28 -0
  142. maxframe/codegen/spe/tensor/tests/test_misc.py +144 -0
  143. maxframe/codegen/spe/tensor/tests/test_random.py +55 -0
  144. maxframe/codegen/spe/tensor/tests/test_reduction.py +65 -0
  145. maxframe/codegen/spe/tensor/tests/test_reshape.py +39 -0
  146. maxframe/codegen/spe/tensor/tests/test_sort.py +49 -0
  147. maxframe/codegen/spe/tensor/tests/test_spatial.py +33 -0
  148. maxframe/codegen/spe/tensor/tests/test_special.py +28 -0
  149. maxframe/codegen/spe/tensor/tests/test_statistics.py +43 -0
  150. maxframe/codegen/spe/tests/__init__.py +13 -0
  151. maxframe/codegen/spe/tests/test_remote.py +29 -0
  152. maxframe/codegen/spe/tests/test_spe_codegen.py +135 -0
  153. maxframe/codegen/spe/utils.py +56 -0
  154. maxframe/codegen/tests/__init__.py +13 -0
  155. maxframe/codegen/tests/test_codegen.py +67 -0
  156. maxframe/config/__init__.py +15 -0
  157. maxframe/config/config.py +627 -0
  158. maxframe/config/tests/__init__.py +13 -0
  159. maxframe/config/tests/test_config.py +114 -0
  160. maxframe/config/tests/test_validators.py +46 -0
  161. maxframe/config/validators.py +142 -0
  162. maxframe/conftest.py +251 -0
  163. maxframe/core/__init__.py +53 -0
  164. maxframe/core/accessor.py +45 -0
  165. maxframe/core/base.py +156 -0
  166. maxframe/core/context.py +110 -0
  167. maxframe/core/entity/__init__.py +34 -0
  168. maxframe/core/entity/core.py +150 -0
  169. maxframe/core/entity/executable.py +337 -0
  170. maxframe/core/entity/objects.py +115 -0
  171. maxframe/core/entity/output_types.py +98 -0
  172. maxframe/core/entity/tests/__init__.py +13 -0
  173. maxframe/core/entity/tests/test_objects.py +42 -0
  174. maxframe/core/entity/tileables.py +367 -0
  175. maxframe/core/entity/utils.py +39 -0
  176. maxframe/core/graph/__init__.py +22 -0
  177. maxframe/core/graph/builder/__init__.py +15 -0
  178. maxframe/core/graph/builder/base.py +91 -0
  179. maxframe/core/graph/builder/tileable.py +34 -0
  180. maxframe/core/graph/builder/utils.py +37 -0
  181. maxframe/core/graph/core.cpython-312-aarch64-linux-gnu.so +0 -0
  182. maxframe/core/graph/core.pyx +478 -0
  183. maxframe/core/graph/entity.py +158 -0
  184. maxframe/core/graph/tests/__init__.py +13 -0
  185. maxframe/core/graph/tests/test_graph.py +205 -0
  186. maxframe/core/mode.py +96 -0
  187. maxframe/core/operator/__init__.py +32 -0
  188. maxframe/core/operator/base.py +480 -0
  189. maxframe/core/operator/core.py +307 -0
  190. maxframe/core/operator/fetch.py +40 -0
  191. maxframe/core/operator/objects.py +43 -0
  192. maxframe/core/operator/shuffle.py +45 -0
  193. maxframe/core/operator/tests/__init__.py +13 -0
  194. maxframe/core/operator/tests/test_core.py +64 -0
  195. maxframe/core/operator/utils.py +68 -0
  196. maxframe/core/tests/__init__.py +13 -0
  197. maxframe/core/tests/test_mode.py +75 -0
  198. maxframe/dataframe/__init__.py +89 -0
  199. maxframe/dataframe/accessors/__init__.py +15 -0
  200. maxframe/dataframe/accessors/compat.py +45 -0
  201. maxframe/dataframe/accessors/datetime_/__init__.py +35 -0
  202. maxframe/dataframe/accessors/datetime_/accessor.py +67 -0
  203. maxframe/dataframe/accessors/datetime_/core.py +82 -0
  204. maxframe/dataframe/accessors/datetime_/tests/__init__.py +13 -0
  205. maxframe/dataframe/accessors/datetime_/tests/test_datetime_accessor.py +41 -0
  206. maxframe/dataframe/accessors/dict_/__init__.py +43 -0
  207. maxframe/dataframe/accessors/dict_/accessor.py +39 -0
  208. maxframe/dataframe/accessors/dict_/contains.py +72 -0
  209. maxframe/dataframe/accessors/dict_/core.py +48 -0
  210. maxframe/dataframe/accessors/dict_/getitem.py +140 -0
  211. maxframe/dataframe/accessors/dict_/length.py +64 -0
  212. maxframe/dataframe/accessors/dict_/remove.py +75 -0
  213. maxframe/dataframe/accessors/dict_/setitem.py +79 -0
  214. maxframe/dataframe/accessors/dict_/tests/__init__.py +13 -0
  215. maxframe/dataframe/accessors/dict_/tests/test_dict_accessor.py +168 -0
  216. maxframe/dataframe/accessors/list_/__init__.py +37 -0
  217. maxframe/dataframe/accessors/list_/accessor.py +39 -0
  218. maxframe/dataframe/accessors/list_/core.py +48 -0
  219. maxframe/dataframe/accessors/list_/getitem.py +128 -0
  220. maxframe/dataframe/accessors/list_/length.py +64 -0
  221. maxframe/dataframe/accessors/list_/tests/__init__.py +13 -0
  222. maxframe/dataframe/accessors/list_/tests/test_list_accessor.py +81 -0
  223. maxframe/dataframe/accessors/plotting/__init__.py +40 -0
  224. maxframe/dataframe/accessors/plotting/core.py +78 -0
  225. maxframe/dataframe/accessors/plotting/tests/__init__.py +13 -0
  226. maxframe/dataframe/accessors/plotting/tests/test_plotting_accessor.py +136 -0
  227. maxframe/dataframe/accessors/string_/__init__.py +36 -0
  228. maxframe/dataframe/accessors/string_/accessor.py +215 -0
  229. maxframe/dataframe/accessors/string_/core.py +224 -0
  230. maxframe/dataframe/accessors/string_/tests/__init__.py +13 -0
  231. maxframe/dataframe/accessors/string_/tests/test_string_accessor.py +73 -0
  232. maxframe/dataframe/accessors/struct_/__init__.py +37 -0
  233. maxframe/dataframe/accessors/struct_/accessor.py +39 -0
  234. maxframe/dataframe/accessors/struct_/core.py +43 -0
  235. maxframe/dataframe/accessors/struct_/dtypes.py +53 -0
  236. maxframe/dataframe/accessors/struct_/field.py +123 -0
  237. maxframe/dataframe/accessors/struct_/tests/__init__.py +13 -0
  238. maxframe/dataframe/accessors/struct_/tests/test_struct_accessor.py +91 -0
  239. maxframe/dataframe/arithmetic/__init__.py +369 -0
  240. maxframe/dataframe/arithmetic/abs.py +33 -0
  241. maxframe/dataframe/arithmetic/add.py +60 -0
  242. maxframe/dataframe/arithmetic/arccos.py +28 -0
  243. maxframe/dataframe/arithmetic/arccosh.py +28 -0
  244. maxframe/dataframe/arithmetic/arcsin.py +28 -0
  245. maxframe/dataframe/arithmetic/arcsinh.py +28 -0
  246. maxframe/dataframe/arithmetic/arctan.py +28 -0
  247. maxframe/dataframe/arithmetic/arctanh.py +28 -0
  248. maxframe/dataframe/arithmetic/between.py +106 -0
  249. maxframe/dataframe/arithmetic/bitwise_and.py +46 -0
  250. maxframe/dataframe/arithmetic/bitwise_or.py +50 -0
  251. maxframe/dataframe/arithmetic/bitwise_xor.py +46 -0
  252. maxframe/dataframe/arithmetic/ceil.py +28 -0
  253. maxframe/dataframe/arithmetic/core.py +361 -0
  254. maxframe/dataframe/arithmetic/cos.py +28 -0
  255. maxframe/dataframe/arithmetic/cosh.py +28 -0
  256. maxframe/dataframe/arithmetic/degrees.py +28 -0
  257. maxframe/dataframe/arithmetic/docstring.py +416 -0
  258. maxframe/dataframe/arithmetic/dot.py +237 -0
  259. maxframe/dataframe/arithmetic/equal.py +58 -0
  260. maxframe/dataframe/arithmetic/exp.py +28 -0
  261. maxframe/dataframe/arithmetic/exp2.py +28 -0
  262. maxframe/dataframe/arithmetic/expm1.py +28 -0
  263. maxframe/dataframe/arithmetic/floor.py +28 -0
  264. maxframe/dataframe/arithmetic/floordiv.py +64 -0
  265. maxframe/dataframe/arithmetic/greater.py +59 -0
  266. maxframe/dataframe/arithmetic/greater_equal.py +59 -0
  267. maxframe/dataframe/arithmetic/invert.py +33 -0
  268. maxframe/dataframe/arithmetic/is_ufuncs.py +62 -0
  269. maxframe/dataframe/arithmetic/less.py +57 -0
  270. maxframe/dataframe/arithmetic/less_equal.py +59 -0
  271. maxframe/dataframe/arithmetic/log.py +28 -0
  272. maxframe/dataframe/arithmetic/log10.py +28 -0
  273. maxframe/dataframe/arithmetic/log2.py +28 -0
  274. maxframe/dataframe/arithmetic/mod.py +60 -0
  275. maxframe/dataframe/arithmetic/multiply.py +60 -0
  276. maxframe/dataframe/arithmetic/negative.py +33 -0
  277. maxframe/dataframe/arithmetic/not_equal.py +58 -0
  278. maxframe/dataframe/arithmetic/power.py +68 -0
  279. maxframe/dataframe/arithmetic/radians.py +28 -0
  280. maxframe/dataframe/arithmetic/round.py +144 -0
  281. maxframe/dataframe/arithmetic/sin.py +28 -0
  282. maxframe/dataframe/arithmetic/sinh.py +28 -0
  283. maxframe/dataframe/arithmetic/sqrt.py +28 -0
  284. maxframe/dataframe/arithmetic/subtract.py +64 -0
  285. maxframe/dataframe/arithmetic/tan.py +28 -0
  286. maxframe/dataframe/arithmetic/tanh.py +28 -0
  287. maxframe/dataframe/arithmetic/tests/__init__.py +13 -0
  288. maxframe/dataframe/arithmetic/tests/test_arithmetic.py +724 -0
  289. maxframe/dataframe/arithmetic/truediv.py +64 -0
  290. maxframe/dataframe/arithmetic/trunc.py +28 -0
  291. maxframe/dataframe/arrays.py +864 -0
  292. maxframe/dataframe/core.py +2393 -0
  293. maxframe/dataframe/datasource/__init__.py +33 -0
  294. maxframe/dataframe/datasource/core.py +88 -0
  295. maxframe/dataframe/datasource/dataframe.py +59 -0
  296. maxframe/dataframe/datasource/date_range.py +512 -0
  297. maxframe/dataframe/datasource/from_dict.py +124 -0
  298. maxframe/dataframe/datasource/from_index.py +58 -0
  299. maxframe/dataframe/datasource/from_records.py +191 -0
  300. maxframe/dataframe/datasource/from_tensor.py +498 -0
  301. maxframe/dataframe/datasource/index.py +117 -0
  302. maxframe/dataframe/datasource/read_csv.py +533 -0
  303. maxframe/dataframe/datasource/read_odps_query.py +513 -0
  304. maxframe/dataframe/datasource/read_odps_table.py +273 -0
  305. maxframe/dataframe/datasource/read_parquet.py +426 -0
  306. maxframe/dataframe/datasource/series.py +55 -0
  307. maxframe/dataframe/datasource/tests/__init__.py +13 -0
  308. maxframe/dataframe/datasource/tests/test_datasource.py +663 -0
  309. maxframe/dataframe/datastore/__init__.py +30 -0
  310. maxframe/dataframe/datastore/core.py +19 -0
  311. maxframe/dataframe/datastore/tests/__init__.py +13 -0
  312. maxframe/dataframe/datastore/tests/test_to_odps.py +99 -0
  313. maxframe/dataframe/datastore/to_csv.py +219 -0
  314. maxframe/dataframe/datastore/to_odps.py +258 -0
  315. maxframe/dataframe/extensions/__init__.py +70 -0
  316. maxframe/dataframe/extensions/accessor.py +35 -0
  317. maxframe/dataframe/extensions/apply_chunk.py +733 -0
  318. maxframe/dataframe/extensions/cartesian_chunk.py +153 -0
  319. maxframe/dataframe/extensions/collect_kv.py +126 -0
  320. maxframe/dataframe/extensions/extract_kv.py +177 -0
  321. maxframe/dataframe/extensions/flatjson.py +132 -0
  322. maxframe/dataframe/extensions/flatmap.py +329 -0
  323. maxframe/dataframe/extensions/map_reduce.py +263 -0
  324. maxframe/dataframe/extensions/rebalance.py +62 -0
  325. maxframe/dataframe/extensions/reshuffle.py +83 -0
  326. maxframe/dataframe/extensions/tests/__init__.py +13 -0
  327. maxframe/dataframe/extensions/tests/test_apply_chunk.py +194 -0
  328. maxframe/dataframe/extensions/tests/test_extensions.py +198 -0
  329. maxframe/dataframe/extensions/tests/test_map_reduce.py +135 -0
  330. maxframe/dataframe/fetch/__init__.py +15 -0
  331. maxframe/dataframe/fetch/core.py +97 -0
  332. maxframe/dataframe/groupby/__init__.py +101 -0
  333. maxframe/dataframe/groupby/aggregation.py +437 -0
  334. maxframe/dataframe/groupby/apply.py +235 -0
  335. maxframe/dataframe/groupby/apply_chunk.py +409 -0
  336. maxframe/dataframe/groupby/core.py +326 -0
  337. maxframe/dataframe/groupby/cum.py +102 -0
  338. maxframe/dataframe/groupby/expanding.py +264 -0
  339. maxframe/dataframe/groupby/extensions.py +26 -0
  340. maxframe/dataframe/groupby/fill.py +149 -0
  341. maxframe/dataframe/groupby/getitem.py +105 -0
  342. maxframe/dataframe/groupby/head.py +115 -0
  343. maxframe/dataframe/groupby/rank.py +136 -0
  344. maxframe/dataframe/groupby/rolling.py +206 -0
  345. maxframe/dataframe/groupby/sample.py +214 -0
  346. maxframe/dataframe/groupby/shift.py +114 -0
  347. maxframe/dataframe/groupby/tests/__init__.py +13 -0
  348. maxframe/dataframe/groupby/tests/test_groupby.py +373 -0
  349. maxframe/dataframe/groupby/transform.py +264 -0
  350. maxframe/dataframe/indexing/__init__.py +103 -0
  351. maxframe/dataframe/indexing/add_prefix_suffix.py +110 -0
  352. maxframe/dataframe/indexing/align.py +350 -0
  353. maxframe/dataframe/indexing/at.py +83 -0
  354. maxframe/dataframe/indexing/droplevel.py +195 -0
  355. maxframe/dataframe/indexing/filter.py +169 -0
  356. maxframe/dataframe/indexing/get_level_values.py +76 -0
  357. maxframe/dataframe/indexing/getitem.py +205 -0
  358. maxframe/dataframe/indexing/iat.py +82 -0
  359. maxframe/dataframe/indexing/iloc.py +711 -0
  360. maxframe/dataframe/indexing/insert.py +90 -0
  361. maxframe/dataframe/indexing/loc.py +694 -0
  362. maxframe/dataframe/indexing/reindex.py +541 -0
  363. maxframe/dataframe/indexing/rename.py +445 -0
  364. maxframe/dataframe/indexing/rename_axis.py +217 -0
  365. maxframe/dataframe/indexing/reorder_levels.py +143 -0
  366. maxframe/dataframe/indexing/reset_index.py +427 -0
  367. maxframe/dataframe/indexing/sample.py +232 -0
  368. maxframe/dataframe/indexing/set_axis.py +197 -0
  369. maxframe/dataframe/indexing/set_index.py +128 -0
  370. maxframe/dataframe/indexing/setitem.py +133 -0
  371. maxframe/dataframe/indexing/swaplevel.py +185 -0
  372. maxframe/dataframe/indexing/take.py +99 -0
  373. maxframe/dataframe/indexing/tests/__init__.py +13 -0
  374. maxframe/dataframe/indexing/tests/test_indexing.py +488 -0
  375. maxframe/dataframe/indexing/truncate.py +140 -0
  376. maxframe/dataframe/indexing/where.py +300 -0
  377. maxframe/dataframe/indexing/xs.py +148 -0
  378. maxframe/dataframe/initializer.py +298 -0
  379. maxframe/dataframe/merge/__init__.py +50 -0
  380. maxframe/dataframe/merge/append.py +120 -0
  381. maxframe/dataframe/merge/combine_first.py +120 -0
  382. maxframe/dataframe/merge/compare.py +387 -0
  383. maxframe/dataframe/merge/concat.py +500 -0
  384. maxframe/dataframe/merge/merge.py +806 -0
  385. maxframe/dataframe/merge/tests/__init__.py +13 -0
  386. maxframe/dataframe/merge/tests/test_merge.py +390 -0
  387. maxframe/dataframe/merge/update.py +271 -0
  388. maxframe/dataframe/misc/__init__.py +131 -0
  389. maxframe/dataframe/misc/_duplicate.py +56 -0
  390. maxframe/dataframe/misc/apply.py +730 -0
  391. maxframe/dataframe/misc/astype.py +237 -0
  392. maxframe/dataframe/misc/case_when.py +145 -0
  393. maxframe/dataframe/misc/check_monotonic.py +84 -0
  394. maxframe/dataframe/misc/check_unique.py +51 -0
  395. maxframe/dataframe/misc/clip.py +145 -0
  396. maxframe/dataframe/misc/cut.py +386 -0
  397. maxframe/dataframe/misc/describe.py +278 -0
  398. maxframe/dataframe/misc/diff.py +210 -0
  399. maxframe/dataframe/misc/drop.py +442 -0
  400. maxframe/dataframe/misc/drop_duplicates.py +251 -0
  401. maxframe/dataframe/misc/duplicated.py +292 -0
  402. maxframe/dataframe/misc/eval.py +730 -0
  403. maxframe/dataframe/misc/explode.py +171 -0
  404. maxframe/dataframe/misc/get_dummies.py +241 -0
  405. maxframe/dataframe/misc/isin.py +220 -0
  406. maxframe/dataframe/misc/map.py +347 -0
  407. maxframe/dataframe/misc/memory_usage.py +248 -0
  408. maxframe/dataframe/misc/pct_change.py +68 -0
  409. maxframe/dataframe/misc/qcut.py +104 -0
  410. maxframe/dataframe/misc/rechunk.py +59 -0
  411. maxframe/dataframe/misc/select_dtypes.py +104 -0
  412. maxframe/dataframe/misc/shift.py +259 -0
  413. maxframe/dataframe/misc/tests/__init__.py +13 -0
  414. maxframe/dataframe/misc/tests/test_misc.py +615 -0
  415. maxframe/dataframe/misc/to_numeric.py +181 -0
  416. maxframe/dataframe/misc/transform.py +346 -0
  417. maxframe/dataframe/misc/transpose.py +148 -0
  418. maxframe/dataframe/misc/valid_index.py +115 -0
  419. maxframe/dataframe/misc/value_counts.py +206 -0
  420. maxframe/dataframe/missing/__init__.py +53 -0
  421. maxframe/dataframe/missing/checkna.py +230 -0
  422. maxframe/dataframe/missing/dropna.py +294 -0
  423. maxframe/dataframe/missing/fillna.py +283 -0
  424. maxframe/dataframe/missing/replace.py +446 -0
  425. maxframe/dataframe/missing/tests/__init__.py +13 -0
  426. maxframe/dataframe/missing/tests/test_missing.py +90 -0
  427. maxframe/dataframe/operators.py +231 -0
  428. maxframe/dataframe/reduction/__init__.py +124 -0
  429. maxframe/dataframe/reduction/aggregation.py +499 -0
  430. maxframe/dataframe/reduction/all.py +78 -0
  431. maxframe/dataframe/reduction/any.py +78 -0
  432. maxframe/dataframe/reduction/argmax.py +100 -0
  433. maxframe/dataframe/reduction/argmin.py +100 -0
  434. maxframe/dataframe/reduction/core.py +898 -0
  435. maxframe/dataframe/reduction/count.py +63 -0
  436. maxframe/dataframe/reduction/cov.py +166 -0
  437. maxframe/dataframe/reduction/cummax.py +30 -0
  438. maxframe/dataframe/reduction/cummin.py +30 -0
  439. maxframe/dataframe/reduction/cumprod.py +30 -0
  440. maxframe/dataframe/reduction/cumsum.py +30 -0
  441. maxframe/dataframe/reduction/custom_reduction.py +42 -0
  442. maxframe/dataframe/reduction/idxmax.py +185 -0
  443. maxframe/dataframe/reduction/idxmin.py +185 -0
  444. maxframe/dataframe/reduction/kurtosis.py +111 -0
  445. maxframe/dataframe/reduction/max.py +65 -0
  446. maxframe/dataframe/reduction/mean.py +63 -0
  447. maxframe/dataframe/reduction/median.py +56 -0
  448. maxframe/dataframe/reduction/min.py +65 -0
  449. maxframe/dataframe/reduction/nunique.py +142 -0
  450. maxframe/dataframe/reduction/prod.py +81 -0
  451. maxframe/dataframe/reduction/reduction_size.py +36 -0
  452. maxframe/dataframe/reduction/sem.py +73 -0
  453. maxframe/dataframe/reduction/skew.py +93 -0
  454. maxframe/dataframe/reduction/std.py +53 -0
  455. maxframe/dataframe/reduction/str_concat.py +51 -0
  456. maxframe/dataframe/reduction/sum.py +81 -0
  457. maxframe/dataframe/reduction/tests/__init__.py +13 -0
  458. maxframe/dataframe/reduction/tests/test_reduction.py +529 -0
  459. maxframe/dataframe/reduction/unique.py +153 -0
  460. maxframe/dataframe/reduction/var.py +76 -0
  461. maxframe/dataframe/reshape/__init__.py +38 -0
  462. maxframe/dataframe/reshape/melt.py +169 -0
  463. maxframe/dataframe/reshape/pivot.py +233 -0
  464. maxframe/dataframe/reshape/pivot_table.py +275 -0
  465. maxframe/dataframe/reshape/stack.py +240 -0
  466. maxframe/dataframe/reshape/unstack.py +114 -0
  467. maxframe/dataframe/sort/__init__.py +42 -0
  468. maxframe/dataframe/sort/argsort.py +62 -0
  469. maxframe/dataframe/sort/core.py +37 -0
  470. maxframe/dataframe/sort/nlargest.py +238 -0
  471. maxframe/dataframe/sort/nsmallest.py +228 -0
  472. maxframe/dataframe/sort/sort_index.py +153 -0
  473. maxframe/dataframe/sort/sort_values.py +301 -0
  474. maxframe/dataframe/sort/tests/__init__.py +13 -0
  475. maxframe/dataframe/sort/tests/test_sort.py +81 -0
  476. maxframe/dataframe/statistics/__init__.py +33 -0
  477. maxframe/dataframe/statistics/corr.py +284 -0
  478. maxframe/dataframe/statistics/quantile.py +338 -0
  479. maxframe/dataframe/statistics/tests/__init__.py +13 -0
  480. maxframe/dataframe/statistics/tests/test_statistics.py +82 -0
  481. maxframe/dataframe/tests/__init__.py +13 -0
  482. maxframe/dataframe/tests/test_initializer.py +60 -0
  483. maxframe/dataframe/tests/test_typing.py +104 -0
  484. maxframe/dataframe/tests/test_utils.py +165 -0
  485. maxframe/dataframe/tseries/__init__.py +13 -0
  486. maxframe/dataframe/tseries/tests/__init__.py +13 -0
  487. maxframe/dataframe/tseries/tests/test_tseries.py +30 -0
  488. maxframe/dataframe/tseries/to_datetime.py +299 -0
  489. maxframe/dataframe/typing_.py +185 -0
  490. maxframe/dataframe/ufunc/__init__.py +27 -0
  491. maxframe/dataframe/ufunc/tensor.py +54 -0
  492. maxframe/dataframe/ufunc/ufunc.py +53 -0
  493. maxframe/dataframe/utils.py +1647 -0
  494. maxframe/dataframe/window/__init__.py +29 -0
  495. maxframe/dataframe/window/aggregation.py +100 -0
  496. maxframe/dataframe/window/core.py +82 -0
  497. maxframe/dataframe/window/ewm.py +247 -0
  498. maxframe/dataframe/window/expanding.py +151 -0
  499. maxframe/dataframe/window/rolling.py +389 -0
  500. maxframe/dataframe/window/tests/__init__.py +13 -0
  501. maxframe/dataframe/window/tests/test_ewm.py +70 -0
  502. maxframe/dataframe/window/tests/test_expanding.py +60 -0
  503. maxframe/dataframe/window/tests/test_rolling.py +57 -0
  504. maxframe/env.py +37 -0
  505. maxframe/errors.py +47 -0
  506. maxframe/extension.py +107 -0
  507. maxframe/io/__init__.py +13 -0
  508. maxframe/io/objects/__init__.py +24 -0
  509. maxframe/io/objects/core.py +156 -0
  510. maxframe/io/objects/tensor.py +132 -0
  511. maxframe/io/objects/tests/__init__.py +13 -0
  512. maxframe/io/objects/tests/test_object_io.py +79 -0
  513. maxframe/io/odpsio/__init__.py +23 -0
  514. maxframe/io/odpsio/arrow.py +161 -0
  515. maxframe/io/odpsio/schema.py +496 -0
  516. maxframe/io/odpsio/tableio.py +727 -0
  517. maxframe/io/odpsio/tests/__init__.py +13 -0
  518. maxframe/io/odpsio/tests/test_arrow.py +132 -0
  519. maxframe/io/odpsio/tests/test_schema.py +580 -0
  520. maxframe/io/odpsio/tests/test_tableio.py +205 -0
  521. maxframe/io/odpsio/tests/test_volumeio.py +75 -0
  522. maxframe/io/odpsio/volumeio.py +102 -0
  523. maxframe/learn/__init__.py +25 -0
  524. maxframe/learn/cluster/__init__.py +15 -0
  525. maxframe/learn/cluster/_kmeans.py +782 -0
  526. maxframe/learn/contrib/__init__.py +17 -0
  527. maxframe/learn/contrib/graph/__init__.py +15 -0
  528. maxframe/learn/contrib/graph/connected_components.py +216 -0
  529. maxframe/learn/contrib/graph/tests/__init__.py +13 -0
  530. maxframe/learn/contrib/graph/tests/test_connected_components.py +53 -0
  531. maxframe/learn/contrib/lightgbm/__init__.py +33 -0
  532. maxframe/learn/contrib/lightgbm/_predict.py +138 -0
  533. maxframe/learn/contrib/lightgbm/_train.py +163 -0
  534. maxframe/learn/contrib/lightgbm/callback.py +114 -0
  535. maxframe/learn/contrib/lightgbm/classifier.py +199 -0
  536. maxframe/learn/contrib/lightgbm/core.py +372 -0
  537. maxframe/learn/contrib/lightgbm/dataset.py +153 -0
  538. maxframe/learn/contrib/lightgbm/regressor.py +29 -0
  539. maxframe/learn/contrib/lightgbm/tests/__init__.py +13 -0
  540. maxframe/learn/contrib/lightgbm/tests/test_callback.py +58 -0
  541. maxframe/learn/contrib/llm/__init__.py +17 -0
  542. maxframe/learn/contrib/llm/core.py +77 -0
  543. maxframe/learn/contrib/llm/models/__init__.py +15 -0
  544. maxframe/learn/contrib/llm/models/dashscope.py +108 -0
  545. maxframe/learn/contrib/llm/models/managed.py +54 -0
  546. maxframe/learn/contrib/llm/multi_modal.py +135 -0
  547. maxframe/learn/contrib/llm/text.py +302 -0
  548. maxframe/learn/contrib/models.py +106 -0
  549. maxframe/learn/contrib/pytorch/__init__.py +16 -0
  550. maxframe/learn/contrib/pytorch/run_function.py +110 -0
  551. maxframe/learn/contrib/pytorch/run_script.py +102 -0
  552. maxframe/learn/contrib/pytorch/tests/__init__.py +13 -0
  553. maxframe/learn/contrib/pytorch/tests/test_pytorch.py +42 -0
  554. maxframe/learn/contrib/utils.py +108 -0
  555. maxframe/learn/contrib/xgboost/__init__.py +33 -0
  556. maxframe/learn/contrib/xgboost/callback.py +86 -0
  557. maxframe/learn/contrib/xgboost/classifier.py +117 -0
  558. maxframe/learn/contrib/xgboost/core.py +445 -0
  559. maxframe/learn/contrib/xgboost/dmatrix.py +157 -0
  560. maxframe/learn/contrib/xgboost/predict.py +131 -0
  561. maxframe/learn/contrib/xgboost/regressor.py +86 -0
  562. maxframe/learn/contrib/xgboost/tests/__init__.py +13 -0
  563. maxframe/learn/contrib/xgboost/tests/test_callback.py +41 -0
  564. maxframe/learn/contrib/xgboost/tests/test_core.py +43 -0
  565. maxframe/learn/contrib/xgboost/train.py +179 -0
  566. maxframe/learn/core.py +344 -0
  567. maxframe/learn/datasets/__init__.py +20 -0
  568. maxframe/learn/datasets/samples_generator.py +628 -0
  569. maxframe/learn/linear_model/__init__.py +15 -0
  570. maxframe/learn/linear_model/_base.py +220 -0
  571. maxframe/learn/linear_model/_lin_reg.py +175 -0
  572. maxframe/learn/metrics/__init__.py +31 -0
  573. maxframe/learn/metrics/_check_targets.py +95 -0
  574. maxframe/learn/metrics/_classification.py +1266 -0
  575. maxframe/learn/metrics/_ranking.py +477 -0
  576. maxframe/learn/metrics/_regression.py +256 -0
  577. maxframe/learn/metrics/_scorer.py +60 -0
  578. maxframe/learn/metrics/pairwise/__init__.py +21 -0
  579. maxframe/learn/metrics/pairwise/core.py +77 -0
  580. maxframe/learn/metrics/pairwise/cosine.py +115 -0
  581. maxframe/learn/metrics/pairwise/euclidean.py +176 -0
  582. maxframe/learn/metrics/pairwise/haversine.py +96 -0
  583. maxframe/learn/metrics/pairwise/manhattan.py +80 -0
  584. maxframe/learn/metrics/pairwise/pairwise.py +127 -0
  585. maxframe/learn/metrics/pairwise/pairwise_distances_topk.py +121 -0
  586. maxframe/learn/metrics/pairwise/rbf_kernel.py +51 -0
  587. maxframe/learn/metrics/tests/__init__.py +13 -0
  588. maxframe/learn/metrics/tests/test_scorer.py +26 -0
  589. maxframe/learn/model_selection/__init__.py +15 -0
  590. maxframe/learn/model_selection/_split.py +451 -0
  591. maxframe/learn/model_selection/tests/__init__.py +13 -0
  592. maxframe/learn/model_selection/tests/test_split.py +156 -0
  593. maxframe/learn/preprocessing/__init__.py +16 -0
  594. maxframe/learn/preprocessing/_data/__init__.py +17 -0
  595. maxframe/learn/preprocessing/_data/min_max_scaler.py +390 -0
  596. maxframe/learn/preprocessing/_data/normalize.py +127 -0
  597. maxframe/learn/preprocessing/_data/standard_scaler.py +503 -0
  598. maxframe/learn/preprocessing/_data/utils.py +79 -0
  599. maxframe/learn/preprocessing/_label/__init__.py +16 -0
  600. maxframe/learn/preprocessing/_label/_label_binarizer.py +599 -0
  601. maxframe/learn/preprocessing/_label/_label_encoder.py +174 -0
  602. maxframe/learn/utils/__init__.py +19 -0
  603. maxframe/learn/utils/_encode.py +314 -0
  604. maxframe/learn/utils/checks.py +160 -0
  605. maxframe/learn/utils/core.py +121 -0
  606. maxframe/learn/utils/extmath.py +213 -0
  607. maxframe/learn/utils/multiclass.py +292 -0
  608. maxframe/learn/utils/odpsio.py +193 -0
  609. maxframe/learn/utils/shuffle.py +114 -0
  610. maxframe/learn/utils/sparsefuncs.py +87 -0
  611. maxframe/learn/utils/validation.py +775 -0
  612. maxframe/lib/__init__.py +13 -0
  613. maxframe/lib/aio/__init__.py +27 -0
  614. maxframe/lib/aio/_runners.py +162 -0
  615. maxframe/lib/aio/_threads.py +35 -0
  616. maxframe/lib/aio/base.py +82 -0
  617. maxframe/lib/aio/file.py +85 -0
  618. maxframe/lib/aio/isolation.py +100 -0
  619. maxframe/lib/aio/lru.py +242 -0
  620. maxframe/lib/aio/parallelism.py +37 -0
  621. maxframe/lib/aio/tests/__init__.py +13 -0
  622. maxframe/lib/aio/tests/test_aio_file.py +55 -0
  623. maxframe/lib/compat.py +185 -0
  624. maxframe/lib/compression.py +55 -0
  625. maxframe/lib/cython/__init__.py +13 -0
  626. maxframe/lib/cython/libcpp.pxd +30 -0
  627. maxframe/lib/dtypes_extension/__init__.py +30 -0
  628. maxframe/lib/dtypes_extension/_fake_arrow_dtype.py +604 -0
  629. maxframe/lib/dtypes_extension/blob.py +304 -0
  630. maxframe/lib/dtypes_extension/dtypes.py +106 -0
  631. maxframe/lib/dtypes_extension/tests/__init__.py +13 -0
  632. maxframe/lib/dtypes_extension/tests/test_blob.py +88 -0
  633. maxframe/lib/dtypes_extension/tests/test_dtypes.py +63 -0
  634. maxframe/lib/dtypes_extension/tests/test_fake_arrow_dtype.py +75 -0
  635. maxframe/lib/filesystem/__init__.py +21 -0
  636. maxframe/lib/filesystem/_glob.py +173 -0
  637. maxframe/lib/filesystem/_oss_lib/__init__.py +13 -0
  638. maxframe/lib/filesystem/_oss_lib/common.py +270 -0
  639. maxframe/lib/filesystem/_oss_lib/glob.py +147 -0
  640. maxframe/lib/filesystem/_oss_lib/handle.py +152 -0
  641. maxframe/lib/filesystem/arrow.py +236 -0
  642. maxframe/lib/filesystem/base.py +263 -0
  643. maxframe/lib/filesystem/core.py +95 -0
  644. maxframe/lib/filesystem/fsmap.py +164 -0
  645. maxframe/lib/filesystem/hdfs.py +31 -0
  646. maxframe/lib/filesystem/local.py +112 -0
  647. maxframe/lib/filesystem/oss.py +226 -0
  648. maxframe/lib/filesystem/tests/__init__.py +13 -0
  649. maxframe/lib/filesystem/tests/test_filesystem.py +225 -0
  650. maxframe/lib/filesystem/tests/test_oss.py +220 -0
  651. maxframe/lib/functools_compat.py +81 -0
  652. maxframe/lib/mmh3.cpython-312-aarch64-linux-gnu.so +0 -0
  653. maxframe/lib/mmh3.pyi +43 -0
  654. maxframe/lib/mmh3_src/MurmurHash3.cpp +339 -0
  655. maxframe/lib/mmh3_src/MurmurHash3.h +43 -0
  656. maxframe/lib/mmh3_src/mmh3module.cpp +387 -0
  657. maxframe/lib/sparse/__init__.py +856 -0
  658. maxframe/lib/sparse/array.py +1616 -0
  659. maxframe/lib/sparse/core.py +90 -0
  660. maxframe/lib/sparse/linalg.py +31 -0
  661. maxframe/lib/sparse/matrix.py +244 -0
  662. maxframe/lib/sparse/tests/__init__.py +13 -0
  663. maxframe/lib/sparse/tests/test_sparse.py +476 -0
  664. maxframe/lib/sparse/vector.py +148 -0
  665. maxframe/lib/tblib/LICENSE +20 -0
  666. maxframe/lib/tblib/__init__.py +327 -0
  667. maxframe/lib/tblib/cpython.py +83 -0
  668. maxframe/lib/tblib/decorators.py +44 -0
  669. maxframe/lib/tblib/pickling_support.py +90 -0
  670. maxframe/lib/tests/__init__.py +13 -0
  671. maxframe/lib/tests/test_wrapped_pickle.py +51 -0
  672. maxframe/lib/version.py +620 -0
  673. maxframe/lib/wrapped_pickle.py +150 -0
  674. maxframe/mixin.py +157 -0
  675. maxframe/opcodes.py +649 -0
  676. maxframe/protocol.py +607 -0
  677. maxframe/remote/__init__.py +18 -0
  678. maxframe/remote/core.py +208 -0
  679. maxframe/remote/run_script.py +124 -0
  680. maxframe/serialization/__init__.py +39 -0
  681. maxframe/serialization/arrow.py +120 -0
  682. maxframe/serialization/blob.py +32 -0
  683. maxframe/serialization/core.cpython-312-aarch64-linux-gnu.so +0 -0
  684. maxframe/serialization/core.pxd +50 -0
  685. maxframe/serialization/core.pyi +66 -0
  686. maxframe/serialization/core.pyx +1265 -0
  687. maxframe/serialization/exception.py +84 -0
  688. maxframe/serialization/maxframe_objects.py +39 -0
  689. maxframe/serialization/numpy.py +110 -0
  690. maxframe/serialization/pandas.py +278 -0
  691. maxframe/serialization/scipy.py +71 -0
  692. maxframe/serialization/serializables/__init__.py +55 -0
  693. maxframe/serialization/serializables/core.py +469 -0
  694. maxframe/serialization/serializables/field.py +624 -0
  695. maxframe/serialization/serializables/field_type.py +592 -0
  696. maxframe/serialization/serializables/tests/__init__.py +13 -0
  697. maxframe/serialization/serializables/tests/test_field_type.py +119 -0
  698. maxframe/serialization/serializables/tests/test_serializable.py +313 -0
  699. maxframe/serialization/tests/__init__.py +13 -0
  700. maxframe/serialization/tests/test_serial.py +487 -0
  701. maxframe/session.py +1250 -0
  702. maxframe/sperunner.py +165 -0
  703. maxframe/tensor/__init__.py +325 -0
  704. maxframe/tensor/arithmetic/__init__.py +322 -0
  705. maxframe/tensor/arithmetic/abs.py +66 -0
  706. maxframe/tensor/arithmetic/absolute.py +66 -0
  707. maxframe/tensor/arithmetic/add.py +112 -0
  708. maxframe/tensor/arithmetic/angle.py +70 -0
  709. maxframe/tensor/arithmetic/arccos.py +101 -0
  710. maxframe/tensor/arithmetic/arccosh.py +89 -0
  711. maxframe/tensor/arithmetic/arcsin.py +92 -0
  712. maxframe/tensor/arithmetic/arcsinh.py +84 -0
  713. maxframe/tensor/arithmetic/arctan.py +104 -0
  714. maxframe/tensor/arithmetic/arctan2.py +126 -0
  715. maxframe/tensor/arithmetic/arctanh.py +84 -0
  716. maxframe/tensor/arithmetic/around.py +112 -0
  717. maxframe/tensor/arithmetic/bitand.py +93 -0
  718. maxframe/tensor/arithmetic/bitor.py +100 -0
  719. maxframe/tensor/arithmetic/bitxor.py +93 -0
  720. maxframe/tensor/arithmetic/cbrt.py +64 -0
  721. maxframe/tensor/arithmetic/ceil.py +69 -0
  722. maxframe/tensor/arithmetic/clip.py +165 -0
  723. maxframe/tensor/arithmetic/conj.py +72 -0
  724. maxframe/tensor/arithmetic/copysign.py +76 -0
  725. maxframe/tensor/arithmetic/core.py +552 -0
  726. maxframe/tensor/arithmetic/cos.py +83 -0
  727. maxframe/tensor/arithmetic/cosh.py +70 -0
  728. maxframe/tensor/arithmetic/deg2rad.py +70 -0
  729. maxframe/tensor/arithmetic/degrees.py +75 -0
  730. maxframe/tensor/arithmetic/divide.py +112 -0
  731. maxframe/tensor/arithmetic/equal.py +74 -0
  732. maxframe/tensor/arithmetic/exp.py +104 -0
  733. maxframe/tensor/arithmetic/exp2.py +65 -0
  734. maxframe/tensor/arithmetic/expm1.py +77 -0
  735. maxframe/tensor/arithmetic/fabs.py +72 -0
  736. maxframe/tensor/arithmetic/fix.py +67 -0
  737. maxframe/tensor/arithmetic/float_power.py +101 -0
  738. maxframe/tensor/arithmetic/floor.py +75 -0
  739. maxframe/tensor/arithmetic/floordiv.py +92 -0
  740. maxframe/tensor/arithmetic/fmax.py +103 -0
  741. maxframe/tensor/arithmetic/fmin.py +104 -0
  742. maxframe/tensor/arithmetic/fmod.py +97 -0
  743. maxframe/tensor/arithmetic/frexp.py +96 -0
  744. maxframe/tensor/arithmetic/greater.py +75 -0
  745. maxframe/tensor/arithmetic/greater_equal.py +67 -0
  746. maxframe/tensor/arithmetic/hypot.py +75 -0
  747. maxframe/tensor/arithmetic/i0.py +87 -0
  748. maxframe/tensor/arithmetic/imag.py +65 -0
  749. maxframe/tensor/arithmetic/invert.py +108 -0
  750. maxframe/tensor/arithmetic/isclose.py +114 -0
  751. maxframe/tensor/arithmetic/iscomplex.py +62 -0
  752. maxframe/tensor/arithmetic/iscomplexobj.py +53 -0
  753. maxframe/tensor/arithmetic/isfinite.py +104 -0
  754. maxframe/tensor/arithmetic/isinf.py +101 -0
  755. maxframe/tensor/arithmetic/isnan.py +80 -0
  756. maxframe/tensor/arithmetic/isreal.py +61 -0
  757. maxframe/tensor/arithmetic/ldexp.py +97 -0
  758. maxframe/tensor/arithmetic/less.py +67 -0
  759. maxframe/tensor/arithmetic/less_equal.py +67 -0
  760. maxframe/tensor/arithmetic/log.py +90 -0
  761. maxframe/tensor/arithmetic/log10.py +83 -0
  762. maxframe/tensor/arithmetic/log1p.py +93 -0
  763. maxframe/tensor/arithmetic/log2.py +83 -0
  764. maxframe/tensor/arithmetic/logaddexp.py +78 -0
  765. maxframe/tensor/arithmetic/logaddexp2.py +76 -0
  766. maxframe/tensor/arithmetic/logical_and.py +79 -0
  767. maxframe/tensor/arithmetic/logical_not.py +72 -0
  768. maxframe/tensor/arithmetic/logical_or.py +80 -0
  769. maxframe/tensor/arithmetic/logical_xor.py +86 -0
  770. maxframe/tensor/arithmetic/lshift.py +80 -0
  771. maxframe/tensor/arithmetic/maximum.py +106 -0
  772. maxframe/tensor/arithmetic/minimum.py +106 -0
  773. maxframe/tensor/arithmetic/mod.py +102 -0
  774. maxframe/tensor/arithmetic/modf.py +87 -0
  775. maxframe/tensor/arithmetic/multiply.py +114 -0
  776. maxframe/tensor/arithmetic/nan_to_num.py +97 -0
  777. maxframe/tensor/arithmetic/negative.py +63 -0
  778. maxframe/tensor/arithmetic/nextafter.py +66 -0
  779. maxframe/tensor/arithmetic/not_equal.py +70 -0
  780. maxframe/tensor/arithmetic/positive.py +45 -0
  781. maxframe/tensor/arithmetic/power.py +104 -0
  782. maxframe/tensor/arithmetic/rad2deg.py +69 -0
  783. maxframe/tensor/arithmetic/radians.py +75 -0
  784. maxframe/tensor/arithmetic/real.py +68 -0
  785. maxframe/tensor/arithmetic/reciprocal.py +78 -0
  786. maxframe/tensor/arithmetic/rint.py +66 -0
  787. maxframe/tensor/arithmetic/rshift.py +79 -0
  788. maxframe/tensor/arithmetic/setimag.py +27 -0
  789. maxframe/tensor/arithmetic/setreal.py +27 -0
  790. maxframe/tensor/arithmetic/sign.py +79 -0
  791. maxframe/tensor/arithmetic/signbit.py +63 -0
  792. maxframe/tensor/arithmetic/sin.py +96 -0
  793. maxframe/tensor/arithmetic/sinc.py +100 -0
  794. maxframe/tensor/arithmetic/sinh.py +91 -0
  795. maxframe/tensor/arithmetic/spacing.py +70 -0
  796. maxframe/tensor/arithmetic/sqrt.py +79 -0
  797. maxframe/tensor/arithmetic/square.py +67 -0
  798. maxframe/tensor/arithmetic/subtract.py +83 -0
  799. maxframe/tensor/arithmetic/tan.py +86 -0
  800. maxframe/tensor/arithmetic/tanh.py +90 -0
  801. maxframe/tensor/arithmetic/tests/__init__.py +13 -0
  802. maxframe/tensor/arithmetic/tests/test_arithmetic.py +458 -0
  803. maxframe/tensor/arithmetic/truediv.py +102 -0
  804. maxframe/tensor/arithmetic/trunc.py +70 -0
  805. maxframe/tensor/arithmetic/utils.py +91 -0
  806. maxframe/tensor/array_utils.py +164 -0
  807. maxframe/tensor/core.py +594 -0
  808. maxframe/tensor/datasource/__init__.py +40 -0
  809. maxframe/tensor/datasource/arange.py +154 -0
  810. maxframe/tensor/datasource/array.py +399 -0
  811. maxframe/tensor/datasource/core.py +114 -0
  812. maxframe/tensor/datasource/diag.py +140 -0
  813. maxframe/tensor/datasource/diagflat.py +69 -0
  814. maxframe/tensor/datasource/empty.py +167 -0
  815. maxframe/tensor/datasource/eye.py +95 -0
  816. maxframe/tensor/datasource/from_dataframe.py +68 -0
  817. maxframe/tensor/datasource/from_dense.py +37 -0
  818. maxframe/tensor/datasource/from_sparse.py +45 -0
  819. maxframe/tensor/datasource/full.py +184 -0
  820. maxframe/tensor/datasource/identity.py +54 -0
  821. maxframe/tensor/datasource/indices.py +115 -0
  822. maxframe/tensor/datasource/linspace.py +140 -0
  823. maxframe/tensor/datasource/meshgrid.py +135 -0
  824. maxframe/tensor/datasource/ones.py +178 -0
  825. maxframe/tensor/datasource/scalar.py +40 -0
  826. maxframe/tensor/datasource/tests/__init__.py +13 -0
  827. maxframe/tensor/datasource/tests/test_datasource.py +310 -0
  828. maxframe/tensor/datasource/tri_array.py +107 -0
  829. maxframe/tensor/datasource/zeros.py +192 -0
  830. maxframe/tensor/extensions/__init__.py +33 -0
  831. maxframe/tensor/extensions/accessor.py +25 -0
  832. maxframe/tensor/extensions/apply_chunk.py +137 -0
  833. maxframe/tensor/extensions/rebalance.py +65 -0
  834. maxframe/tensor/fetch/__init__.py +15 -0
  835. maxframe/tensor/fetch/core.py +54 -0
  836. maxframe/tensor/fft/__init__.py +32 -0
  837. maxframe/tensor/fft/core.py +168 -0
  838. maxframe/tensor/fft/fft.py +112 -0
  839. maxframe/tensor/fft/fft2.py +118 -0
  840. maxframe/tensor/fft/fftfreq.py +80 -0
  841. maxframe/tensor/fft/fftn.py +123 -0
  842. maxframe/tensor/fft/fftshift.py +79 -0
  843. maxframe/tensor/fft/hfft.py +112 -0
  844. maxframe/tensor/fft/ifft.py +114 -0
  845. maxframe/tensor/fft/ifft2.py +115 -0
  846. maxframe/tensor/fft/ifftn.py +123 -0
  847. maxframe/tensor/fft/ifftshift.py +73 -0
  848. maxframe/tensor/fft/ihfft.py +93 -0
  849. maxframe/tensor/fft/irfft.py +118 -0
  850. maxframe/tensor/fft/irfft2.py +62 -0
  851. maxframe/tensor/fft/irfftn.py +114 -0
  852. maxframe/tensor/fft/rfft.py +116 -0
  853. maxframe/tensor/fft/rfft2.py +63 -0
  854. maxframe/tensor/fft/rfftfreq.py +87 -0
  855. maxframe/tensor/fft/rfftn.py +113 -0
  856. maxframe/tensor/indexing/__init__.py +47 -0
  857. maxframe/tensor/indexing/choose.py +198 -0
  858. maxframe/tensor/indexing/compress.py +122 -0
  859. maxframe/tensor/indexing/core.py +190 -0
  860. maxframe/tensor/indexing/extract.py +69 -0
  861. maxframe/tensor/indexing/fill_diagonal.py +180 -0
  862. maxframe/tensor/indexing/flatnonzero.py +58 -0
  863. maxframe/tensor/indexing/getitem.py +144 -0
  864. maxframe/tensor/indexing/nonzero.py +118 -0
  865. maxframe/tensor/indexing/setitem.py +142 -0
  866. maxframe/tensor/indexing/slice.py +32 -0
  867. maxframe/tensor/indexing/take.py +128 -0
  868. maxframe/tensor/indexing/tests/__init__.py +13 -0
  869. maxframe/tensor/indexing/tests/test_indexing.py +232 -0
  870. maxframe/tensor/indexing/unravel_index.py +103 -0
  871. maxframe/tensor/lib/__init__.py +16 -0
  872. maxframe/tensor/lib/index_tricks.py +404 -0
  873. maxframe/tensor/linalg/__init__.py +43 -0
  874. maxframe/tensor/linalg/_einsumfunc.py +1025 -0
  875. maxframe/tensor/linalg/cholesky.py +117 -0
  876. maxframe/tensor/linalg/dot.py +145 -0
  877. maxframe/tensor/linalg/einsum.py +339 -0
  878. maxframe/tensor/linalg/inner.py +36 -0
  879. maxframe/tensor/linalg/inv.py +83 -0
  880. maxframe/tensor/linalg/lstsq.py +100 -0
  881. maxframe/tensor/linalg/lu.py +115 -0
  882. maxframe/tensor/linalg/matmul.py +225 -0
  883. maxframe/tensor/linalg/matrix_norm.py +75 -0
  884. maxframe/tensor/linalg/norm.py +249 -0
  885. maxframe/tensor/linalg/qr.py +124 -0
  886. maxframe/tensor/linalg/solve.py +72 -0
  887. maxframe/tensor/linalg/solve_triangular.py +103 -0
  888. maxframe/tensor/linalg/svd.py +167 -0
  889. maxframe/tensor/linalg/tensordot.py +213 -0
  890. maxframe/tensor/linalg/vdot.py +73 -0
  891. maxframe/tensor/linalg/vector_norm.py +113 -0
  892. maxframe/tensor/merge/__init__.py +21 -0
  893. maxframe/tensor/merge/append.py +74 -0
  894. maxframe/tensor/merge/column_stack.py +63 -0
  895. maxframe/tensor/merge/concatenate.py +103 -0
  896. maxframe/tensor/merge/dstack.py +71 -0
  897. maxframe/tensor/merge/hstack.py +70 -0
  898. maxframe/tensor/merge/stack.py +130 -0
  899. maxframe/tensor/merge/tests/__init__.py +13 -0
  900. maxframe/tensor/merge/tests/test_merge.py +79 -0
  901. maxframe/tensor/merge/vstack.py +74 -0
  902. maxframe/tensor/misc/__init__.py +72 -0
  903. maxframe/tensor/misc/argwhere.py +72 -0
  904. maxframe/tensor/misc/array_split.py +46 -0
  905. maxframe/tensor/misc/astype.py +121 -0
  906. maxframe/tensor/misc/atleast_1d.py +72 -0
  907. maxframe/tensor/misc/atleast_2d.py +70 -0
  908. maxframe/tensor/misc/atleast_3d.py +85 -0
  909. maxframe/tensor/misc/broadcast_arrays.py +57 -0
  910. maxframe/tensor/misc/broadcast_to.py +89 -0
  911. maxframe/tensor/misc/copy.py +64 -0
  912. maxframe/tensor/misc/copyto.py +130 -0
  913. maxframe/tensor/misc/delete.py +104 -0
  914. maxframe/tensor/misc/diff.py +115 -0
  915. maxframe/tensor/misc/dsplit.py +68 -0
  916. maxframe/tensor/misc/ediff1d.py +74 -0
  917. maxframe/tensor/misc/expand_dims.py +85 -0
  918. maxframe/tensor/misc/flatten.py +63 -0
  919. maxframe/tensor/misc/flip.py +90 -0
  920. maxframe/tensor/misc/fliplr.py +64 -0
  921. maxframe/tensor/misc/flipud.py +68 -0
  922. maxframe/tensor/misc/hsplit.py +85 -0
  923. maxframe/tensor/misc/in1d.py +94 -0
  924. maxframe/tensor/misc/insert.py +139 -0
  925. maxframe/tensor/misc/isin.py +130 -0
  926. maxframe/tensor/misc/moveaxis.py +83 -0
  927. maxframe/tensor/misc/ndim.py +53 -0
  928. maxframe/tensor/misc/ravel.py +90 -0
  929. maxframe/tensor/misc/repeat.py +129 -0
  930. maxframe/tensor/misc/result_type.py +88 -0
  931. maxframe/tensor/misc/roll.py +124 -0
  932. maxframe/tensor/misc/rollaxis.py +77 -0
  933. maxframe/tensor/misc/searchsorted.py +147 -0
  934. maxframe/tensor/misc/setdiff1d.py +58 -0
  935. maxframe/tensor/misc/shape.py +89 -0
  936. maxframe/tensor/misc/split.py +190 -0
  937. maxframe/tensor/misc/squeeze.py +117 -0
  938. maxframe/tensor/misc/swapaxes.py +113 -0
  939. maxframe/tensor/misc/tests/__init__.py +13 -0
  940. maxframe/tensor/misc/tests/test_misc.py +112 -0
  941. maxframe/tensor/misc/tile.py +109 -0
  942. maxframe/tensor/misc/transpose.py +133 -0
  943. maxframe/tensor/misc/trapezoid.py +123 -0
  944. maxframe/tensor/misc/unique.py +205 -0
  945. maxframe/tensor/misc/vsplit.py +74 -0
  946. maxframe/tensor/misc/where.py +129 -0
  947. maxframe/tensor/operators.py +83 -0
  948. maxframe/tensor/random/__init__.py +166 -0
  949. maxframe/tensor/random/beta.py +87 -0
  950. maxframe/tensor/random/binomial.py +135 -0
  951. maxframe/tensor/random/bytes.py +37 -0
  952. maxframe/tensor/random/chisquare.py +108 -0
  953. maxframe/tensor/random/choice.py +187 -0
  954. maxframe/tensor/random/core.py +249 -0
  955. maxframe/tensor/random/dirichlet.py +121 -0
  956. maxframe/tensor/random/exponential.py +92 -0
  957. maxframe/tensor/random/f.py +133 -0
  958. maxframe/tensor/random/gamma.py +126 -0
  959. maxframe/tensor/random/geometric.py +91 -0
  960. maxframe/tensor/random/gumbel.py +165 -0
  961. maxframe/tensor/random/hypergeometric.py +146 -0
  962. maxframe/tensor/random/laplace.py +131 -0
  963. maxframe/tensor/random/logistic.py +127 -0
  964. maxframe/tensor/random/lognormal.py +157 -0
  965. maxframe/tensor/random/logseries.py +120 -0
  966. maxframe/tensor/random/multinomial.py +131 -0
  967. maxframe/tensor/random/multivariate_normal.py +190 -0
  968. maxframe/tensor/random/negative_binomial.py +123 -0
  969. maxframe/tensor/random/noncentral_chisquare.py +130 -0
  970. maxframe/tensor/random/noncentral_f.py +124 -0
  971. maxframe/tensor/random/normal.py +141 -0
  972. maxframe/tensor/random/pareto.py +138 -0
  973. maxframe/tensor/random/permutation.py +107 -0
  974. maxframe/tensor/random/poisson.py +109 -0
  975. maxframe/tensor/random/power.py +140 -0
  976. maxframe/tensor/random/rand.py +80 -0
  977. maxframe/tensor/random/randint.py +119 -0
  978. maxframe/tensor/random/randn.py +94 -0
  979. maxframe/tensor/random/random_integers.py +121 -0
  980. maxframe/tensor/random/random_sample.py +84 -0
  981. maxframe/tensor/random/rayleigh.py +108 -0
  982. maxframe/tensor/random/shuffle.py +61 -0
  983. maxframe/tensor/random/standard_cauchy.py +103 -0
  984. maxframe/tensor/random/standard_exponential.py +70 -0
  985. maxframe/tensor/random/standard_gamma.py +118 -0
  986. maxframe/tensor/random/standard_normal.py +72 -0
  987. maxframe/tensor/random/standard_t.py +133 -0
  988. maxframe/tensor/random/tests/__init__.py +13 -0
  989. maxframe/tensor/random/tests/test_random.py +165 -0
  990. maxframe/tensor/random/triangular.py +117 -0
  991. maxframe/tensor/random/uniform.py +129 -0
  992. maxframe/tensor/random/vonmises.py +129 -0
  993. maxframe/tensor/random/wald.py +112 -0
  994. maxframe/tensor/random/weibull.py +138 -0
  995. maxframe/tensor/random/zipf.py +120 -0
  996. maxframe/tensor/rechunk/__init__.py +26 -0
  997. maxframe/tensor/rechunk/rechunk.py +43 -0
  998. maxframe/tensor/reduction/__init__.py +64 -0
  999. maxframe/tensor/reduction/all.py +101 -0
  1000. maxframe/tensor/reduction/allclose.py +86 -0
  1001. maxframe/tensor/reduction/any.py +103 -0
  1002. maxframe/tensor/reduction/argmax.py +101 -0
  1003. maxframe/tensor/reduction/argmin.py +101 -0
  1004. maxframe/tensor/reduction/array_equal.py +63 -0
  1005. maxframe/tensor/reduction/core.py +166 -0
  1006. maxframe/tensor/reduction/count_nonzero.py +80 -0
  1007. maxframe/tensor/reduction/cumprod.py +95 -0
  1008. maxframe/tensor/reduction/cumsum.py +99 -0
  1009. maxframe/tensor/reduction/max.py +118 -0
  1010. maxframe/tensor/reduction/mean.py +122 -0
  1011. maxframe/tensor/reduction/min.py +118 -0
  1012. maxframe/tensor/reduction/nanargmax.py +80 -0
  1013. maxframe/tensor/reduction/nanargmin.py +74 -0
  1014. maxframe/tensor/reduction/nancumprod.py +89 -0
  1015. maxframe/tensor/reduction/nancumsum.py +92 -0
  1016. maxframe/tensor/reduction/nanmax.py +109 -0
  1017. maxframe/tensor/reduction/nanmean.py +105 -0
  1018. maxframe/tensor/reduction/nanmin.py +109 -0
  1019. maxframe/tensor/reduction/nanprod.py +92 -0
  1020. maxframe/tensor/reduction/nanstd.py +124 -0
  1021. maxframe/tensor/reduction/nansum.py +113 -0
  1022. maxframe/tensor/reduction/nanvar.py +149 -0
  1023. maxframe/tensor/reduction/prod.py +128 -0
  1024. maxframe/tensor/reduction/std.py +132 -0
  1025. maxframe/tensor/reduction/sum.py +123 -0
  1026. maxframe/tensor/reduction/tests/__init__.py +13 -0
  1027. maxframe/tensor/reduction/tests/test_reduction.py +189 -0
  1028. maxframe/tensor/reduction/var.py +176 -0
  1029. maxframe/tensor/reshape/__init__.py +15 -0
  1030. maxframe/tensor/reshape/reshape.py +192 -0
  1031. maxframe/tensor/reshape/tests/__init__.py +13 -0
  1032. maxframe/tensor/reshape/tests/test_reshape.py +35 -0
  1033. maxframe/tensor/sort/__init__.py +18 -0
  1034. maxframe/tensor/sort/argpartition.py +98 -0
  1035. maxframe/tensor/sort/argsort.py +150 -0
  1036. maxframe/tensor/sort/partition.py +228 -0
  1037. maxframe/tensor/sort/sort.py +295 -0
  1038. maxframe/tensor/spatial/__init__.py +15 -0
  1039. maxframe/tensor/spatial/distance/__init__.py +17 -0
  1040. maxframe/tensor/spatial/distance/cdist.py +421 -0
  1041. maxframe/tensor/spatial/distance/pdist.py +398 -0
  1042. maxframe/tensor/spatial/distance/squareform.py +153 -0
  1043. maxframe/tensor/special/__init__.py +175 -0
  1044. maxframe/tensor/special/airy.py +55 -0
  1045. maxframe/tensor/special/bessel.py +199 -0
  1046. maxframe/tensor/special/core.py +99 -0
  1047. maxframe/tensor/special/ellip_func_integrals.py +155 -0
  1048. maxframe/tensor/special/ellip_harm.py +55 -0
  1049. maxframe/tensor/special/err_fresnel.py +223 -0
  1050. maxframe/tensor/special/gamma_funcs.py +303 -0
  1051. maxframe/tensor/special/hypergeometric_funcs.py +69 -0
  1052. maxframe/tensor/special/info_theory.py +189 -0
  1053. maxframe/tensor/special/misc.py +163 -0
  1054. maxframe/tensor/special/statistical.py +56 -0
  1055. maxframe/tensor/statistics/__init__.py +24 -0
  1056. maxframe/tensor/statistics/average.py +143 -0
  1057. maxframe/tensor/statistics/bincount.py +133 -0
  1058. maxframe/tensor/statistics/corrcoef.py +77 -0
  1059. maxframe/tensor/statistics/cov.py +222 -0
  1060. maxframe/tensor/statistics/digitize.py +126 -0
  1061. maxframe/tensor/statistics/histogram.py +520 -0
  1062. maxframe/tensor/statistics/median.py +85 -0
  1063. maxframe/tensor/statistics/percentile.py +175 -0
  1064. maxframe/tensor/statistics/ptp.py +89 -0
  1065. maxframe/tensor/statistics/quantile.py +290 -0
  1066. maxframe/tensor/ufunc/__init__.py +24 -0
  1067. maxframe/tensor/ufunc/ufunc.py +198 -0
  1068. maxframe/tensor/utils.py +716 -0
  1069. maxframe/tests/__init__.py +13 -0
  1070. maxframe/tests/test_protocol.py +178 -0
  1071. maxframe/tests/test_utils.py +615 -0
  1072. maxframe/tests/utils.py +245 -0
  1073. maxframe/typing_.py +42 -0
  1074. maxframe/udf.py +260 -0
  1075. maxframe/utils.py +1721 -0
  1076. maxframe-2.2.0.dist-info/METADATA +110 -0
  1077. maxframe-2.2.0.dist-info/RECORD +1094 -0
  1078. maxframe-2.2.0.dist-info/WHEEL +6 -0
  1079. maxframe-2.2.0.dist-info/top_level.txt +3 -0
  1080. maxframe_client/__init__.py +16 -0
  1081. maxframe_client/clients/__init__.py +13 -0
  1082. maxframe_client/clients/framedriver.py +137 -0
  1083. maxframe_client/conftest.py +15 -0
  1084. maxframe_client/fetcher.py +411 -0
  1085. maxframe_client/session/__init__.py +22 -0
  1086. maxframe_client/session/consts.py +39 -0
  1087. maxframe_client/session/graph.py +125 -0
  1088. maxframe_client/session/odps.py +802 -0
  1089. maxframe_client/session/task.py +322 -0
  1090. maxframe_client/session/tests/__init__.py +13 -0
  1091. maxframe_client/session/tests/test_task.py +115 -0
  1092. maxframe_client/tests/__init__.py +13 -0
  1093. maxframe_client/tests/test_fetcher.py +180 -0
  1094. maxframe_client/tests/test_session.py +385 -0
maxframe/utils.py ADDED
@@ -0,0 +1,1721 @@
1
+ # Copyright 1999-2025 Alibaba Group Holding Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import asyncio.events
16
+ import concurrent.futures
17
+ import contextvars
18
+ import copy
19
+ import dataclasses
20
+ import datetime
21
+ import enum
22
+ import functools
23
+ import importlib
24
+ import inspect
25
+ import io
26
+ import itertools
27
+ import logging
28
+ import math
29
+ import numbers
30
+ import os
31
+ import pkgutil
32
+ import random
33
+ import re
34
+ import struct
35
+ import sys
36
+ import tempfile
37
+ import threading
38
+ import time
39
+ import tokenize as pytokenize
40
+ import types
41
+ import warnings
42
+ import weakref
43
+ import zlib
44
+ from collections.abc import Hashable, Mapping
45
+ from contextlib import contextmanager
46
+ from typing import (
47
+ Any,
48
+ Awaitable,
49
+ Callable,
50
+ Dict,
51
+ Generator,
52
+ Iterable,
53
+ List,
54
+ Optional,
55
+ Tuple,
56
+ Type,
57
+ TypeVar,
58
+ Union,
59
+ )
60
+
61
+ import msgpack
62
+ import numpy as np
63
+ import pandas as pd
64
+ import traitlets
65
+ from tornado import httpclient, web
66
+ from tornado.simple_httpclient import HTTPTimeoutError
67
+
68
+ from ._utils import ( # noqa: F401 # pylint: disable=unused-import
69
+ NamedType,
70
+ Timer,
71
+ TypeDispatcher,
72
+ ceildiv,
73
+ get_user_call_point,
74
+ new_random_id,
75
+ register_tokenizer,
76
+ reset_id_random_seed,
77
+ to_binary,
78
+ to_str,
79
+ to_text,
80
+ tokenize,
81
+ tokenize_int,
82
+ )
83
+ from .lib.version import parse as parse_version
84
+ from .typing_ import TileableType, TimeoutType
85
+
86
+ # make flake8 happy by referencing these imports
87
+ NamedType = NamedType
88
+ TypeDispatcher = TypeDispatcher
89
+ tokenize = tokenize
90
+ register_tokenizer = register_tokenizer
91
+ ceildiv = ceildiv
92
+ reset_id_random_seed = reset_id_random_seed
93
+ new_random_id = new_random_id
94
+ get_user_call_point = get_user_call_point
95
+ _is_ci = (os.environ.get("CI") or "0").lower() in ("1", "true")
96
+ pd_release_version: Tuple[int] = parse_version(pd.__version__).release
97
+
98
+ logger = logging.getLogger(__name__)
99
+
100
+ try:
101
+ from pandas._libs import lib as _pd__libs_lib
102
+ from pandas._libs.lib import NoDefault, no_default
103
+
104
+ _raw__reduce__ = type(NoDefault).__reduce__
105
+
106
+ def _no_default__reduce__(self):
107
+ if self is not NoDefault:
108
+ return _raw__reduce__(self)
109
+ else: # pragma: no cover
110
+ return getattr, (_pd__libs_lib, "NoDefault")
111
+
112
+ if hasattr(_pd__libs_lib, "_NoDefault"): # pragma: no cover
113
+ # need to patch __reduce__ to make sure it can be properly unpickled
114
+ type(NoDefault).__reduce__ = _no_default__reduce__
115
+ else:
116
+ # introduced in pandas 1.5.0 : register for pickle compatibility
117
+ _pd__libs_lib._NoDefault = NoDefault
118
+ except ImportError: # pragma: no cover
119
+
120
+ class NoDefault(enum.Enum):
121
+ no_default = "NO_DEFAULT"
122
+
123
+ def __repr__(self) -> str:
124
+ return "<no_default>"
125
+
126
+ no_default = NoDefault.no_default
127
+
128
+ try:
129
+ # register for pickle compatibility
130
+ from pandas._libs import lib as _pd__libs_lib
131
+
132
+ _pd__libs_lib.NoDefault = NoDefault
133
+ except (ImportError, AttributeError):
134
+ pass
135
+
136
+ try:
137
+ import pyarrow as pa
138
+ except ImportError:
139
+ pa = None
140
+
141
+ try:
142
+ from pandas import ArrowDtype as PandasArrowDtype # noqa: F401
143
+
144
+ ARROW_DTYPE_NOT_SUPPORTED = False
145
+ except ImportError:
146
+ ARROW_DTYPE_NOT_SUPPORTED = True
147
+
148
+
149
+ class classproperty:
150
+ def __init__(self, f):
151
+ self.f = f
152
+
153
+ def __get__(self, obj, owner):
154
+ return self.f(owner)
155
+
156
+
157
+ def implements(f: Callable):
158
+ def decorator(g):
159
+ g.__doc__ = f.__doc__
160
+ return g
161
+
162
+ return decorator
163
+
164
+
165
+ class AttributeDict(dict):
166
+ def __getattr__(self, item):
167
+ try:
168
+ return self[item]
169
+ except KeyError:
170
+ raise AttributeError(f"'AttributeDict' object has no attribute {item}")
171
+
172
+
173
+ def on_serialize_shape(shape: Tuple[int]):
174
+ def _to_shape_num(x):
175
+ if np.isnan(x):
176
+ return -1
177
+ if isinstance(x, np.generic):
178
+ return x.item()
179
+ return x
180
+
181
+ if shape:
182
+ return tuple(_to_shape_num(s) for s in shape)
183
+ return shape
184
+
185
+
186
+ def on_deserialize_shape(shape: Tuple[int]):
187
+ if shape:
188
+ return tuple(s if s != -1 else np.nan for s in shape)
189
+ return shape
190
+
191
+
192
+ def on_serialize_numpy_type(value: np.dtype):
193
+ if value is pd.NaT:
194
+ value = None
195
+ return value.item() if isinstance(value, np.generic) else value
196
+
197
+
198
+ def on_serialize_nsplits(value: Tuple[Tuple[int]]):
199
+ if value is None:
200
+ return None
201
+ new_nsplits = []
202
+ for dim_splits in value:
203
+ new_nsplits.append(tuple(None if pd.isna(v) else v for v in dim_splits))
204
+ return tuple(new_nsplits)
205
+
206
+
207
+ def has_unknown_shape(*tiled_tileables: TileableType) -> bool:
208
+ for tileable in tiled_tileables:
209
+ if getattr(tileable, "shape", None) is None:
210
+ continue
211
+ if any(pd.isnull(s) for s in tileable.shape):
212
+ return True
213
+ if any(pd.isnull(s) for s in itertools.chain(*tileable.nsplits)):
214
+ return True
215
+ return False
216
+
217
+
218
+ def calc_nsplits(chunk_idx_to_shape: Dict[Tuple[int], Tuple[int]]) -> Tuple[Tuple[int]]:
219
+ """
220
+ Calculate a tiled entity's nsplits.
221
+
222
+ Parameters
223
+ ----------
224
+ chunk_idx_to_shape : Dict type, {chunk_idx: chunk_shape}
225
+
226
+ Returns
227
+ -------
228
+ nsplits
229
+ """
230
+ ndim = len(next(iter(chunk_idx_to_shape)))
231
+ tileable_nsplits = []
232
+ # for each dimension, record chunk shape whose index is zero on other dimensions
233
+ for i in range(ndim):
234
+ splits = []
235
+ for index, shape in chunk_idx_to_shape.items():
236
+ if all(idx == 0 for j, idx in enumerate(index) if j != i):
237
+ splits.append(shape[i])
238
+ tileable_nsplits.append(tuple(splits))
239
+ return tuple(tileable_nsplits)
240
+
241
+
242
+ def copy_tileables(tileables: List[TileableType], **kwargs):
243
+ inputs = kwargs.pop("inputs", None)
244
+ copy_key = kwargs.pop("copy_key", True)
245
+ copy_id = kwargs.pop("copy_id", True)
246
+ if kwargs:
247
+ raise TypeError(f"got un unexpected keyword argument '{next(iter(kwargs))}'")
248
+ if len(tileables) > 1:
249
+ # cannot handle tileables with different operators here
250
+ # try to copy separately if so
251
+ if len({t.op for t in tileables}) != 1:
252
+ raise TypeError("All tileables' operators should be same.")
253
+
254
+ op = tileables[0].op.copy().reset_key()
255
+ if copy_key:
256
+ op._key = tileables[0].op.key
257
+ kws = []
258
+ for t in tileables:
259
+ params = t.params.copy()
260
+ if copy_key:
261
+ params["_key"] = t.key
262
+ if copy_id:
263
+ params["_id"] = t.id
264
+ params.update(t.extra_params)
265
+ kws.append(params)
266
+ inputs = inputs or op.inputs
267
+ return op.new_tileables(inputs, kws=kws, output_limit=len(kws))
268
+
269
+
270
+ def make_dtype(dtype: Union[np.dtype, pd.api.extensions.ExtensionDtype]):
271
+ if dtype is None:
272
+ return None
273
+ elif (
274
+ isinstance(dtype, str) and dtype == "category"
275
+ ) or pd.api.types.is_extension_array_dtype(dtype):
276
+ # return string dtype directly as legacy python version
277
+ # does not support ExtensionDtype
278
+ return dtype
279
+ elif dtype is pd.Timestamp or dtype is datetime.datetime:
280
+ return np.dtype("datetime64[ns]")
281
+ elif dtype is pd.Timedelta or dtype is datetime.timedelta:
282
+ return np.dtype("timedelta64[ns]")
283
+ else:
284
+ return np.dtype(dtype)
285
+
286
+
287
+ def make_dtypes(
288
+ dtypes: Union[
289
+ list, dict, str, np.dtype, pd.Series, pd.api.extensions.ExtensionDtype
290
+ ],
291
+ make_series: bool = True,
292
+ ):
293
+ if dtypes is None:
294
+ return None
295
+ elif isinstance(dtypes, np.dtype):
296
+ return dtypes
297
+ elif isinstance(dtypes, list):
298
+ val = [make_dtype(dt) for dt in dtypes]
299
+ return val if not make_series else pd.Series(val)
300
+ elif isinstance(dtypes, dict):
301
+ val = {k: make_dtype(v) for k, v in dtypes.items()}
302
+ return val if not make_series else pd.Series(val)
303
+ elif isinstance(dtypes, pd.Series):
304
+ return dtypes.map(make_dtype)
305
+ else:
306
+ return make_dtype(dtypes)
307
+
308
+
309
+ def serialize_serializable(serializable, compress: bool = False):
310
+ from .serialization import serialize
311
+
312
+ bio = io.BytesIO()
313
+ header, buffers = serialize(serializable)
314
+ buf_sizes = [getattr(buf, "nbytes", len(buf)) for buf in buffers]
315
+ header[0]["buf_sizes"] = buf_sizes
316
+
317
+ def encode_np_num(obj):
318
+ if isinstance(obj, np.generic) and obj.shape == () and not np.isnan(obj):
319
+ return obj.item()
320
+ return obj
321
+
322
+ s_header = msgpack.dumps(header, default=encode_np_num)
323
+
324
+ bio.write(struct.pack("<Q", len(s_header)))
325
+ bio.write(s_header)
326
+ for buf in buffers:
327
+ bio.write(buf)
328
+ ser_graph = bio.getvalue()
329
+
330
+ if compress:
331
+ ser_graph = zlib.compress(ser_graph)
332
+ return ser_graph
333
+
334
+
335
+ def deserialize_serializable(ser_serializable: bytes):
336
+ from .serialization import deserialize
337
+
338
+ bio = io.BytesIO(ser_serializable)
339
+ s_header_length = struct.unpack("Q", bio.read(8))[0]
340
+ header2 = msgpack.loads(bio.read(s_header_length))
341
+ buffers2 = [bio.read(s) for s in header2[0]["buf_sizes"]]
342
+ return deserialize(header2, buffers2)
343
+
344
+
345
+ def skip_na_call(func: Callable):
346
+ @functools.wraps(func)
347
+ def new_func(x):
348
+ return func(x) if x is not None else None
349
+
350
+ return new_func
351
+
352
+
353
+ def url_path_join(*pieces):
354
+ """Join components of url into a relative url
355
+
356
+ Use to prevent double slash when joining subpath. This will leave the
357
+ initial and final / in place
358
+ """
359
+ initial = pieces[0].startswith("/")
360
+ final = pieces[-1].endswith("/")
361
+ stripped = [s.strip("/") for s in pieces]
362
+ result = "/".join(s for s in stripped if s)
363
+ if initial:
364
+ result = "/" + result
365
+ if final:
366
+ result = result + "/"
367
+ if result == "//":
368
+ result = "/"
369
+ return result
370
+
371
+
372
+ def random_ports(port: int, n: int):
373
+ """Generate a list of n random ports near the given port.
374
+
375
+ The first 5 ports will be sequential, and the remaining n-5 will be
376
+ randomly selected in the range [port-2*n, port+2*n].
377
+ """
378
+ for i in range(min(5, n)):
379
+ yield port + i
380
+ for i in range(n - 5):
381
+ yield max(1, port + random.randint(-2 * n, 2 * n))
382
+
383
+
384
+ def build_temp_table_name(session_id: str, tileable_key: str) -> str:
385
+ return f"tmp_mf_{session_id}_{tileable_key}"
386
+
387
+
388
+ def build_temp_intermediate_table_name(session_id: str, tileable_key: str) -> str:
389
+ temp_table = build_temp_table_name(session_id, tileable_key)
390
+ return f"{temp_table}_intermediate"
391
+
392
+
393
+ def build_session_volume_name(session_id: str) -> str:
394
+ return f"mf_vol_{session_id.replace('-', '_')}"
395
+
396
+
397
+ async def wait_http_response(
398
+ url: str, *, request_timeout: TimeoutType = None, **kwargs
399
+ ) -> httpclient.HTTPResponse:
400
+ start_time = time.time()
401
+ while request_timeout is None or time.time() - start_time < request_timeout:
402
+ timeout_left = min(10.0, time.time() - start_time) if request_timeout else None
403
+ try:
404
+ return await httpclient.AsyncHTTPClient().fetch(
405
+ url, request_timeout=timeout_left, **kwargs
406
+ )
407
+ except HTTPTimeoutError:
408
+ pass
409
+ raise TimeoutError
410
+
411
+
412
+ def get_handler_timeout_value(handler: web.RequestHandler) -> TimeoutType:
413
+ wait = bool(int(handler.get_argument("wait", "0")))
414
+ timeout = float(handler.get_argument("timeout", "0"))
415
+ if wait and abs(timeout) < 1e-6:
416
+ timeout = None
417
+ elif not wait:
418
+ timeout = 0
419
+ return timeout
420
+
421
+
422
+ def format_timeout_params(timeout: TimeoutType) -> str:
423
+ if timeout is None:
424
+ return "?wait=1"
425
+ elif abs(timeout) < 1e-6:
426
+ return "?wait=0"
427
+ else:
428
+ return f"?wait=1&timeout={timeout}"
429
+
430
+
431
+ def unwrap_partial_function(func):
432
+ while isinstance(func, functools.partial):
433
+ func = func.func
434
+ return func
435
+
436
+
437
+ _PrimitiveType = TypeVar("_PrimitiveType")
438
+
439
+
440
+ def create_sync_primitive(
441
+ cls: Type[_PrimitiveType], loop: asyncio.AbstractEventLoop
442
+ ) -> _PrimitiveType:
443
+ """
444
+ Create an asyncio sync primitive (locks, events, etc.)
445
+ in a certain event loop.
446
+ """
447
+ if sys.version_info[1] < 10:
448
+ return cls(loop=loop)
449
+
450
+ # From Python3.10 the loop parameter has been removed. We should work around here.
451
+ old_loop = asyncio.get_event_loop()
452
+ try:
453
+ asyncio.set_event_loop(loop)
454
+ primitive = cls()
455
+ finally:
456
+ asyncio.set_event_loop(old_loop)
457
+ return primitive
458
+
459
+
460
+ class ToThreadCancelledError(asyncio.CancelledError):
461
+ def __init__(self, *args, result=None):
462
+ super().__init__(*args)
463
+ self._result = result
464
+
465
+ @property
466
+ def result(self):
467
+ return self._result
468
+
469
+
470
+ _ToThreadRetType = TypeVar("_ToThreadRetType")
471
+
472
+
473
+ class ToThreadMixin:
474
+ _thread_pool_size = 1
475
+ _counter = itertools.count().__next__
476
+
477
+ def __del__(self):
478
+ if hasattr(self, "_pool"):
479
+ kw = {"wait": False}
480
+ if sys.version_info[:2] >= (3, 9):
481
+ kw["cancel_futures"] = True
482
+ self._pool.shutdown(**kw)
483
+
484
+ async def to_thread(
485
+ self,
486
+ func: Callable[..., _ToThreadRetType],
487
+ *args,
488
+ wait_on_cancel: bool = False,
489
+ timeout: float = None,
490
+ debug_task_name: Optional[str] = None,
491
+ **kwargs,
492
+ ) -> _ToThreadRetType:
493
+ if not hasattr(self, "_pool"):
494
+ self._pool = concurrent.futures.ThreadPoolExecutor(
495
+ self._thread_pool_size,
496
+ thread_name_prefix=f"{type(self).__name__}Pool-{self._counter()}",
497
+ )
498
+
499
+ loop = asyncio.events.get_running_loop()
500
+ ctx = contextvars.copy_context()
501
+ func_call = functools.partial(ctx.run, func, *args, **kwargs)
502
+ fut = loop.run_in_executor(self._pool, func_call)
503
+
504
+ if loop.get_debug():
505
+ # create a task and mark its name
506
+ default_task_name = None
507
+ try:
508
+ unwrapped = unwrap_partial_function(func)
509
+ default_task_name = unwrapped.__qualname__
510
+ if getattr(unwrapped, "__module__", None):
511
+ default_task_name = unwrapped.__module__ + "#" + default_task_name
512
+ except: # noqa # pragma: no cover
513
+ try:
514
+ default_task_name = repr(func)
515
+ except: # noqa
516
+ pass
517
+ debug_task_name = debug_task_name or default_task_name
518
+
519
+ async def _wait_fut(aio_fut):
520
+ return await aio_fut
521
+
522
+ fut = asyncio.create_task(_wait_fut(fut))
523
+ if sys.version_info[:2] == (3, 7):
524
+ # In Python3.7 we should hack the task name to print it in debug logs.
525
+ setattr(fut, "fd_task_name", debug_task_name)
526
+ else:
527
+ fut.set_name(debug_task_name)
528
+
529
+ try:
530
+ coro = fut
531
+ if wait_on_cancel:
532
+ coro = asyncio.shield(coro)
533
+ if timeout is not None:
534
+ coro = asyncio.wait_for(coro, timeout)
535
+ return await coro
536
+ except (asyncio.CancelledError, asyncio.TimeoutError) as ex:
537
+ if not wait_on_cancel:
538
+ raise
539
+ result = await fut
540
+ raise ToThreadCancelledError(*ex.args, result=result)
541
+
542
+ def ensure_async_call(
543
+ self,
544
+ func: Callable[..., _ToThreadRetType],
545
+ *args,
546
+ wait_on_cancel: bool = False,
547
+ **kwargs,
548
+ ) -> Awaitable[_ToThreadRetType]:
549
+ if asyncio.iscoroutinefunction(func):
550
+ return func(*args, **kwargs)
551
+ return self.to_thread(func, *args, wait_on_cancel=wait_on_cancel, **kwargs)
552
+
553
+
554
+ class PatchableMixin:
555
+ """Patch not None field to dest_obj"""
556
+
557
+ __slots__ = ()
558
+
559
+ _patchable_attrs = tuple()
560
+
561
+ def patch_to(self, dest_obj) -> None:
562
+ for attr in self._patchable_attrs:
563
+ val = getattr(self, attr, None)
564
+ if val is not None:
565
+ setattr(dest_obj, attr, val)
566
+
567
+
568
+ def config_odps_default_options():
569
+ from odps import options as odps_options
570
+
571
+ odps_options.sql.settings = {
572
+ "odps.longtime.instance": "false",
573
+ "odps.sql.session.select.only": "false",
574
+ "metaservice.client.cache.enable": "false",
575
+ "odps.sql.session.result.cache.enable": "false",
576
+ "odps.sql.submit.mode": "script",
577
+ "odps.sql.job.max.time.hours": 72,
578
+ }
579
+
580
+
581
+ def to_hashable(obj: Any) -> Hashable:
582
+ if isinstance(obj, Mapping):
583
+ items = type(obj)((k, to_hashable(v)) for k, v in obj.items())
584
+ elif not isinstance(obj, str) and isinstance(obj, Iterable):
585
+ items = tuple(to_hashable(item) for item in obj)
586
+ elif isinstance(obj, Hashable):
587
+ items = obj
588
+ else:
589
+ raise TypeError(type(obj))
590
+ return items
591
+
592
+
593
+ def estimate_pandas_size(
594
+ pd_obj, max_samples: int = 10, min_sample_rows: int = 100
595
+ ) -> int:
596
+ if len(pd_obj) <= min_sample_rows or isinstance(pd_obj, pd.RangeIndex):
597
+ return sys.getsizeof(pd_obj)
598
+ if isinstance(pd_obj, pd.MultiIndex):
599
+ # MultiIndex's sample size can't be used to estimate
600
+ return sys.getsizeof(pd_obj)
601
+
602
+ from .dataframe.arrays import ArrowDtype
603
+
604
+ def _is_fast_dtype(dtype):
605
+ if isinstance(dtype, np.dtype):
606
+ return np.issubdtype(dtype, np.number)
607
+ else:
608
+ return isinstance(dtype, ArrowDtype)
609
+
610
+ dtypes = []
611
+ is_series = False
612
+ if isinstance(pd_obj, pd.DataFrame):
613
+ dtypes.extend(pd_obj.dtypes)
614
+ index_obj = pd_obj.index
615
+ elif isinstance(pd_obj, pd.Series):
616
+ dtypes.append(pd_obj.dtype)
617
+ index_obj = pd_obj.index
618
+ is_series = True
619
+ else:
620
+ index_obj = pd_obj
621
+
622
+ # handling possible MultiIndex
623
+ if hasattr(index_obj, "dtypes"):
624
+ dtypes.extend(index_obj.dtypes)
625
+ else:
626
+ dtypes.append(index_obj.dtype)
627
+
628
+ if all(_is_fast_dtype(dtype) for dtype in dtypes):
629
+ return sys.getsizeof(pd_obj)
630
+
631
+ indices = np.sort(np.random.choice(len(pd_obj), size=max_samples, replace=False))
632
+ iloc = pd_obj if isinstance(pd_obj, pd.Index) else pd_obj.iloc
633
+ if isinstance(index_obj, pd.MultiIndex):
634
+ # MultiIndex's sample size is much greater than expected, thus we calculate
635
+ # the size separately.
636
+ index_size = sys.getsizeof(pd_obj.index)
637
+ if is_series:
638
+ sample_frame_size = iloc[indices].memory_usage(deep=True, index=False)
639
+ else:
640
+ sample_frame_size = iloc[indices].memory_usage(deep=True, index=False).sum()
641
+ return index_size + sample_frame_size * len(pd_obj) // max_samples
642
+ else:
643
+ sample_size = sys.getsizeof(iloc[indices])
644
+ return sample_size * len(pd_obj) // max_samples
645
+
646
+
647
+ def estimate_table_size(odps_entry, full_table_name: str, partitions: List[str] = None):
648
+ try:
649
+ data_src = odps_entry.get_table(full_table_name)
650
+ if isinstance(partitions, str):
651
+ partitions = [partitions]
652
+ if not partitions:
653
+ size_mul = 1
654
+ else:
655
+ size_mul = len(partitions)
656
+ data_src = data_src.partitions[partitions[0]]
657
+ return size_mul * data_src.size
658
+ except:
659
+ return float("inf")
660
+
661
+
662
+ class ModulePlaceholder:
663
+ def __init__(self, mod_name: str):
664
+ self._mod_name = mod_name
665
+
666
+ def _raises(self):
667
+ raise AttributeError(f"{self._mod_name} is required but not installed.")
668
+
669
+ def __getattr__(self, key):
670
+ self._raises()
671
+
672
+ def __call__(self, *_args, **_kwargs):
673
+ self._raises()
674
+
675
+
676
+ def lazy_import(
677
+ name: str,
678
+ package: str = None,
679
+ globals: Dict = None, # pylint: disable=redefined-builtin
680
+ locals: Dict = None, # pylint: disable=redefined-builtin
681
+ rename: str = None,
682
+ placeholder: bool = False,
683
+ ):
684
+ rename = rename or name
685
+ prefix_name = name.split(".", 1)[0]
686
+ globals = globals or inspect.currentframe().f_back.f_globals
687
+
688
+ class LazyModule(object):
689
+ def __init__(self):
690
+ self._on_loads = []
691
+
692
+ def __getattr__(self, item):
693
+ if item.startswith("_pytest") or item in ("__bases__", "__test__"):
694
+ raise AttributeError(item)
695
+
696
+ real_mod = importlib.import_module(name, package=package)
697
+ if rename in globals:
698
+ globals[rename] = real_mod
699
+ elif locals is not None:
700
+ locals[rename] = real_mod
701
+ ret = getattr(real_mod, item)
702
+ for on_load_func in self._on_loads:
703
+ on_load_func()
704
+ # make sure on_load hooks only executed once
705
+ self._on_loads = []
706
+ return ret
707
+
708
+ def add_load_handler(self, func: Callable):
709
+ self._on_loads.append(func)
710
+ return func
711
+
712
+ if pkgutil.find_loader(prefix_name) is not None:
713
+ return LazyModule()
714
+ elif placeholder:
715
+ return ModulePlaceholder(prefix_name)
716
+ else:
717
+ return None
718
+
719
+
720
+ def sbytes(x: Any) -> bytes:
721
+ # NB: bytes() in Python 3 has different semantic with Python 2, see: help(bytes)
722
+ from numbers import Number
723
+
724
+ if x is None or isinstance(x, Number):
725
+ return bytes(str(x), encoding="ascii")
726
+ elif isinstance(x, list):
727
+ return bytes("[" + ", ".join([str(k) for k in x]) + "]", encoding="utf-8")
728
+ elif isinstance(x, tuple):
729
+ return bytes("(" + ", ".join([str(k) for k in x]) + ")", encoding="utf-8")
730
+ elif isinstance(x, str):
731
+ return bytes(x, encoding="utf-8")
732
+ else:
733
+ try:
734
+ return bytes(x)
735
+ except TypeError:
736
+ return bytes(str(x), encoding="utf-8")
737
+
738
+
739
+ def is_full_slice(slc: Any) -> bool:
740
+ """Check if the input is a full slice ((:) or (0:))"""
741
+ return (
742
+ isinstance(slc, slice)
743
+ and (slc.start == 0 or slc.start is None)
744
+ and slc.stop is None
745
+ and slc.step is None
746
+ )
747
+
748
+
749
+ _enter_counter = 0
750
+ _initial_session = None
751
+
752
+
753
+ def enter_current_session(func: Callable):
754
+ @functools.wraps(func)
755
+ def wrapped(cls, ctx, op):
756
+ from .session import AbstractSession, get_default_session
757
+
758
+ global _enter_counter, _initial_session
759
+ # skip in some test cases
760
+ if not hasattr(ctx, "get_current_session"):
761
+ return func(cls, ctx, op)
762
+
763
+ with AbstractSession._lock:
764
+ if _enter_counter == 0:
765
+ # to handle nested call, only set initial session
766
+ # in first call
767
+ session = ctx.get_current_session()
768
+ _initial_session = get_default_session()
769
+ session.as_default()
770
+ _enter_counter += 1
771
+
772
+ try:
773
+ result = func(cls, ctx, op)
774
+ finally:
775
+ with AbstractSession._lock:
776
+ _enter_counter -= 1
777
+ if _enter_counter == 0:
778
+ # set previous session when counter is 0
779
+ if _initial_session:
780
+ _initial_session.as_default()
781
+ else:
782
+ AbstractSession.reset_default()
783
+ return result
784
+
785
+ return wrapped
786
+
787
+
788
+ _func_token_cache = weakref.WeakKeyDictionary()
789
+
790
+
791
+ def _get_func_token_values(func):
792
+ if hasattr(func, "__code__"):
793
+ tokens = [func.__code__.co_code]
794
+ if func.__closure__ is not None:
795
+ cvars = tuple(x.cell_contents for x in func.__closure__)
796
+ tokens.append(cvars)
797
+ return tokens
798
+ else:
799
+ tokens = []
800
+ while isinstance(func, functools.partial):
801
+ tokens.extend([func.args, func.keywords])
802
+ func = func.func
803
+ if hasattr(func, "__code__"):
804
+ tokens.extend(_get_func_token_values(func))
805
+ elif isinstance(func, types.BuiltinFunctionType):
806
+ tokens.extend([func.__module__, func.__qualname__])
807
+ else:
808
+ tokens.append(func)
809
+ return tokens
810
+
811
+
812
+ def get_func_token(func):
813
+ try:
814
+ token = _func_token_cache.get(func)
815
+ if token is None:
816
+ fields = _get_func_token_values(func)
817
+ token = tokenize(*fields)
818
+ _func_token_cache[func] = token
819
+ return token
820
+ except TypeError: # cannot create weak reference to func like 'numpy.ufunc'
821
+ return tokenize(*_get_func_token_values(func))
822
+
823
+
824
+ _io_quiet_local = threading.local()
825
+ _io_quiet_lock = threading.Lock()
826
+
827
+
828
+ class _QuietIOWrapper:
829
+ def __init__(self, wrapped):
830
+ self.wrapped = wrapped
831
+
832
+ def __getattr__(self, item):
833
+ return getattr(self.wrapped, item)
834
+
835
+ def write(self, d):
836
+ if getattr(_io_quiet_local, "is_wrapped", False):
837
+ return 0
838
+ return self.wrapped.write(d)
839
+
840
+
841
+ @contextmanager
842
+ def quiet_stdio():
843
+ """Quiets standard outputs when inferring types of functions"""
844
+ with _io_quiet_lock:
845
+ _io_quiet_local.is_wrapped = True
846
+ sys.stdout = _QuietIOWrapper(sys.stdout)
847
+ sys.stderr = _QuietIOWrapper(sys.stderr)
848
+
849
+ try:
850
+ yield
851
+ finally:
852
+ with _io_quiet_lock:
853
+ sys.stdout = sys.stdout.wrapped
854
+ sys.stderr = sys.stderr.wrapped
855
+ if not isinstance(sys.stdout, _QuietIOWrapper):
856
+ _io_quiet_local.is_wrapped = False
857
+
858
+
859
+ # from https://github.com/ericvsmith/dataclasses/blob/master/dataclass_tools.py
860
+ # released under Apache License 2.0
861
+ def dataslots(cls):
862
+ # Need to create a new class, since we can't set __slots__
863
+ # after a class has been created.
864
+
865
+ # Make sure __slots__ isn't already set.
866
+ if "__slots__" in cls.__dict__: # pragma: no cover
867
+ raise TypeError(f"{cls.__name__} already specifies __slots__")
868
+
869
+ # Create a new dict for our new class.
870
+ cls_dict = dict(cls.__dict__)
871
+ field_names = tuple(f.name for f in dataclasses.fields(cls))
872
+ cls_dict["__slots__"] = field_names
873
+ for field_name in field_names:
874
+ # Remove our attributes, if present. They'll still be
875
+ # available in _MARKER.
876
+ cls_dict.pop(field_name, None)
877
+ # Remove __dict__ itself.
878
+ cls_dict.pop("__dict__", None)
879
+ # And finally create the class.
880
+ qualname = getattr(cls, "__qualname__", None)
881
+ cls = type(cls)(cls.__name__, cls.__bases__, cls_dict)
882
+ if qualname is not None:
883
+ cls.__qualname__ = qualname
884
+ return cls
885
+
886
+
887
+ def adapt_docstring(doc: str) -> str:
888
+ """
889
+ Adapt numpy-style docstrings to MaxFrame docstring.
890
+
891
+ This util function will add MaxFrame imports, replace object references
892
+ and add execute calls. Note that check is needed after replacement.
893
+ """
894
+ if doc is None:
895
+ return None
896
+
897
+ lines = []
898
+ first_prompt = True
899
+ prev_prompt = False
900
+ has_numpy = "np." in doc
901
+ has_pandas = "pd." in doc
902
+
903
+ for line in doc.splitlines():
904
+ sp = line.strip()
905
+ if sp.startswith(">>>") or sp.startswith("..."):
906
+ prev_prompt = True
907
+ if first_prompt:
908
+ first_prompt = False
909
+ indent = "".join(itertools.takewhile(lambda x: x in (" ", "\t"), line))
910
+ if has_numpy:
911
+ lines.extend([indent + ">>> import maxframe.tensor as mt"])
912
+ if has_pandas:
913
+ lines.extend([indent + ">>> import maxframe.dataframe as md"])
914
+ line = line.replace("np.", "mt.").replace("pd.", "md.")
915
+ elif prev_prompt:
916
+ prev_prompt = False
917
+ if sp and lines[-1].strip().strip("."):
918
+ # need prev line contains chars other than dots
919
+ lines[-1] += ".execute()"
920
+ lines.append(line)
921
+ return "\n".join(lines)
922
+
923
+
924
+ def stringify_path(path: Union[str, os.PathLike]) -> str:
925
+ """
926
+ Convert *path* to a string or unicode path if possible.
927
+ """
928
+ if isinstance(path, str):
929
+ return path
930
+
931
+ # checking whether path implements the filesystem protocol
932
+ try:
933
+ return path.__fspath__()
934
+ except AttributeError:
935
+ raise TypeError("not a path-like object")
936
+
937
+
938
+ _memory_size_indices = {"": 0, "b": 0, "k": 1, "m": 2, "g": 3, "t": 4}
939
+
940
+ _size_pattern = re.compile(r"^([0-9.-]+)\s*([a-z]*)$")
941
+
942
+
943
+ def parse_readable_size(value: Union[str, int, float]) -> Tuple[float, bool]:
944
+ """
945
+ Parse a human-readable size representation into a numeric value.
946
+
947
+ This function converts various size formats into their corresponding
948
+ float values. It supports:
949
+ - Raw numbers (e.g., 1024)
950
+ - Percentages (e.g., "50%")
951
+ - Size units (e.g., "10KB", "5.5GB", "2MiB")
952
+
953
+ The function recognizes standard binary prefixes (K, M, G, T, etc.) and
954
+ handles different suffix variations (B, iB, etc.).
955
+
956
+ Parameters
957
+ ----------
958
+ value : Union[str, int, float]
959
+ The size value to parse, can be a string, int, or float
960
+
961
+ Returns
962
+ -------
963
+ Tuple[float, bool]
964
+ A tuple of (parsed_value, is_percentage)
965
+ - parsed_value: The parsed numeric value
966
+ - is_percentage: True if the input was a percentage, False otherwise
967
+ """
968
+ if isinstance(value, numbers.Number):
969
+ return float(value), False
970
+
971
+ if not isinstance(value, str):
972
+ raise TypeError(f"Expected string or number, got {type(value).__name__}")
973
+
974
+ value = value.strip().lower()
975
+
976
+ # Handle percentage values
977
+ if value.endswith("%"):
978
+ return float(value[:-1]) / 100, True
979
+
980
+ # Parse the value into numeric and unit parts
981
+ match = _size_pattern.match(value)
982
+ if not match:
983
+ raise ValueError(f"Cannot parse size value: {value}")
984
+
985
+ number_str, unit = match.groups()
986
+
987
+ # convert to float
988
+ number = float(number_str)
989
+
990
+ # if no unit, return the number
991
+ if not unit:
992
+ return number, False
993
+
994
+ # Validate the unit prefix
995
+ if unit[0] not in _memory_size_indices:
996
+ valid_prefixes = ", ".join(sorted(_memory_size_indices.keys()))
997
+ raise ValueError(
998
+ f"Unknown unit prefix: '{unit[0]}', valid prefixes are {valid_prefixes}"
999
+ )
1000
+
1001
+ # Check for valid unit suffix
1002
+ if len(unit) > 1 and unit[1:] not in ("ib", "b", "i", ""):
1003
+ raise ValueError(f"Invalid size unit suffix: {unit}")
1004
+
1005
+ is_binary_unit = "i" in unit.lower()
1006
+ # calc the multiplier
1007
+ base = 1024 if is_binary_unit else 1000
1008
+ multiplier = base ** _memory_size_indices[unit[0]]
1009
+
1010
+ return number * multiplier, False
1011
+
1012
+
1013
+ def parse_size_to_megabytes(
1014
+ value: Union[str, int, float], default_number_unit: str = "GiB"
1015
+ ) -> float:
1016
+ try:
1017
+ value = float(value)
1018
+ except BaseException:
1019
+ pass
1020
+
1021
+ if isinstance(value, numbers.Number):
1022
+ if not default_number_unit:
1023
+ raise ValueError(
1024
+ "`default_number_unit` must be provided when give a number value"
1025
+ )
1026
+ return parse_size_to_megabytes(
1027
+ f"{value}{default_number_unit}", default_number_unit
1028
+ )
1029
+
1030
+ bytes_number, is_percentage = parse_readable_size(value)
1031
+ if is_percentage:
1032
+ raise ValueError("Percentage size is not supported to parse")
1033
+
1034
+ return bytes_number / (1024**2) # convert to megabytes
1035
+
1036
+
1037
+ def remove_suffix(value: str, suffix: str) -> Tuple[str, bool]:
1038
+ """
1039
+ Remove a suffix from a given string if it exists.
1040
+
1041
+ Parameters
1042
+ ----------
1043
+ value : str
1044
+ The original string.
1045
+ suffix : str
1046
+ The suffix to be removed.
1047
+
1048
+ Returns
1049
+ -------
1050
+ Tuple[str, bool]
1051
+ A tuple containing the modified string and a boolean indicating whether the suffix was found.
1052
+ """
1053
+
1054
+ # Check if the suffix is an empty string
1055
+ if len(suffix) == 0:
1056
+ # If the suffix is empty, return the original string with True
1057
+ return value, True
1058
+
1059
+ # Check if the length of the value is less than the length of the suffix
1060
+ if len(value) < len(suffix):
1061
+ # If the value is shorter than the suffix, it cannot have the suffix
1062
+ return value, False
1063
+
1064
+ # Check if the suffix matches the end of the value
1065
+ match = value.endswith(suffix)
1066
+
1067
+ # If the suffix is found, remove it; otherwise, return the original string
1068
+ if match:
1069
+ return value[: -len(suffix)], match
1070
+ else:
1071
+ return value, match
1072
+
1073
+
1074
+ def find_objects(
1075
+ nested: Union[List, Dict],
1076
+ types: Union[None, Type, Tuple[Type]] = None,
1077
+ checker: Callable[..., bool] = None,
1078
+ ) -> List:
1079
+ found = []
1080
+ stack = [nested]
1081
+
1082
+ while len(stack) > 0:
1083
+ it = stack.pop()
1084
+ if (types is not None and isinstance(it, types)) or (
1085
+ checker is not None and checker(it)
1086
+ ):
1087
+ found.append(it)
1088
+ continue
1089
+
1090
+ if isinstance(it, (list, tuple, set)):
1091
+ stack.extend(list(it)[::-1])
1092
+ elif isinstance(it, dict):
1093
+ stack.extend(list(it.values())[::-1])
1094
+
1095
+ return found
1096
+
1097
+
1098
+ def replace_objects(nested: Union[List, Dict], mapping: Mapping) -> Union[List, Dict]:
1099
+ if not mapping:
1100
+ return nested
1101
+
1102
+ if isinstance(nested, dict):
1103
+ vals = list(nested.values())
1104
+ else:
1105
+ vals = list(nested)
1106
+
1107
+ new_vals = []
1108
+ for val in vals:
1109
+ if isinstance(val, (dict, list, tuple, set)):
1110
+ new_val = replace_objects(val, mapping)
1111
+ else:
1112
+ try:
1113
+ new_val = mapping.get(val, val)
1114
+ except TypeError:
1115
+ new_val = val
1116
+ new_vals.append(new_val)
1117
+
1118
+ if isinstance(nested, dict):
1119
+ return type(nested)((k, v) for k, v in zip(nested.keys(), new_vals))
1120
+ else:
1121
+ return type(nested)(new_vals)
1122
+
1123
+
1124
+ def trait_from_env(
1125
+ trait_name: str, env: str, trait: Optional[traitlets.TraitType] = None
1126
+ ):
1127
+ if trait is None:
1128
+ prev_locals = inspect.stack()[1].frame.f_locals
1129
+ trait = prev_locals[trait_name]
1130
+
1131
+ default_value = trait.default_value
1132
+ sub_trait: traitlets.TraitType = getattr(trait, "_trait", None)
1133
+
1134
+ def default_value_simple(self):
1135
+ env_val = os.getenv(env, default_value)
1136
+ if isinstance(env_val, (str, bytes)):
1137
+ return trait.from_string(env_val)
1138
+ return env_val
1139
+
1140
+ def default_value_list(self):
1141
+ env_val = os.getenv(env, default_value)
1142
+ if env_val is None or isinstance(env_val, traitlets.Sentinel):
1143
+ return env_val
1144
+
1145
+ parts = env_val.split(",") if env_val else []
1146
+ if sub_trait:
1147
+ return [sub_trait.from_string(s) for s in parts]
1148
+ else:
1149
+ return parts
1150
+
1151
+ if isinstance(trait, traitlets.List):
1152
+ default_value_fun = default_value_list
1153
+ else: # pragma: no cover
1154
+ default_value_fun = default_value_simple
1155
+
1156
+ default_value_fun.__name__ = trait_name + "_default"
1157
+ return traitlets.default(trait_name)(default_value_fun)
1158
+
1159
+
1160
+ def relay_future(
1161
+ dest: Union[asyncio.Future, concurrent.futures.Future],
1162
+ src: Union[asyncio.Future, concurrent.futures.Future],
1163
+ ) -> None:
1164
+ def cb(fut: Union[asyncio.Future, concurrent.futures.Future]):
1165
+ try:
1166
+ dest.set_result(fut.result())
1167
+ except BaseException as ex:
1168
+ dest.set_exception(ex)
1169
+
1170
+ src.add_done_callback(cb)
1171
+
1172
+
1173
+ _arrow_type_constructors = {}
1174
+ if pa:
1175
+ _arrow_type_constructors = {
1176
+ "bool": pa.bool_,
1177
+ "list": lambda x: pa.list_(dict(x)["item"]),
1178
+ "map": lambda x: pa.map_(*x),
1179
+ "struct": pa.struct,
1180
+ "fixed_size_binary": pa.binary,
1181
+ "halffloat": pa.float16,
1182
+ "float": pa.float32,
1183
+ "double": pa.float64,
1184
+ "decimal": pa.decimal128,
1185
+ }
1186
+ _plain_arrow_types = """
1187
+ null
1188
+ int8 int16 int32 int64
1189
+ uint8 uint16 uint32 uint64
1190
+ float16 float32 float64
1191
+ date32 date64
1192
+ decimal128 decimal256
1193
+ string utf8 binary
1194
+ time32 time64 duration timestamp
1195
+ month_day_nano_interval
1196
+ """
1197
+ for _type_name in _plain_arrow_types.split():
1198
+ try:
1199
+ _arrow_type_constructors[_type_name] = getattr(pa, _type_name)
1200
+ except AttributeError: # pragma: no cover
1201
+ pass
1202
+
1203
+
1204
+ def arrow_type_from_str(type_str: str) -> pa.DataType:
1205
+ """
1206
+ Convert arrow type representations (for inst., list<item: int64>)
1207
+ into arrow DataType instances
1208
+ """
1209
+ # enable consecutive brackets to be tokenized
1210
+ type_str = type_str.replace("<", "< ").replace(">", " >")
1211
+ token_iter = pytokenize.tokenize(io.BytesIO(type_str.encode()).readline)
1212
+ value_stack, op_stack = [], []
1213
+
1214
+ def _pop_make_type(with_args: bool = False, combined: bool = True):
1215
+ """
1216
+ Pops tops of value stacks, creates a DataType instance and push back
1217
+
1218
+ Parameters
1219
+ ----------
1220
+ with_args: bool
1221
+ if True, will contain next item (parameter list) in
1222
+ the value stack as parameters
1223
+ combined: bool
1224
+ if True, will use first element of the top of the value stack
1225
+ in DataType constructors
1226
+ """
1227
+ args = () if not with_args else (value_stack.pop(-1),)
1228
+ if not combined:
1229
+ args = args[0]
1230
+ type_name = value_stack.pop(-1)
1231
+ if isinstance(type_name, pa.DataType):
1232
+ value_stack.append(type_name)
1233
+ elif type_name in _arrow_type_constructors:
1234
+ value_stack.append(_arrow_type_constructors[type_name](*args))
1235
+ else: # pragma: no cover
1236
+ value_stack.append(type_name)
1237
+
1238
+ def _pop_make_struct_field():
1239
+ """parameterized sub-types need to be represented as tuples"""
1240
+ nonlocal value_stack
1241
+
1242
+ op_stack.pop(-1)
1243
+ if isinstance(value_stack[-1], str) and value_stack[-1].lower() in (
1244
+ "null",
1245
+ "not null",
1246
+ ):
1247
+ values = value_stack[-3:]
1248
+ value_stack = value_stack[:-3]
1249
+ values[-1] = values[-1] == "null"
1250
+ else:
1251
+ values = value_stack[-2:]
1252
+ value_stack = value_stack[:-2]
1253
+ value_stack.append(tuple(values))
1254
+
1255
+ for token in token_iter:
1256
+ if token.type == pytokenize.OP:
1257
+ if token.string == ":":
1258
+ op_stack.append(token.string)
1259
+ elif token.string == ",":
1260
+ # gather previous sub-types
1261
+ if op_stack[-1] in ("<", ":"):
1262
+ _pop_make_type()
1263
+ if op_stack[-1] == ":":
1264
+ _pop_make_struct_field()
1265
+
1266
+ # put generated item into the parameter list
1267
+ val = value_stack.pop(-1)
1268
+ value_stack[-1].append(val)
1269
+ elif token.string in ("<", "[", "("):
1270
+ # pushes an empty parameter list for future use
1271
+ value_stack.append([])
1272
+ op_stack.append(token.string)
1273
+ elif token.string in (")", "]"):
1274
+ # put generated item into the parameter list
1275
+ val = value_stack.pop(-1)
1276
+ value_stack[-1].append(val)
1277
+ # make DataType (i.e., fixed_size_binary / decimal) given args
1278
+ _pop_make_type(with_args=True, combined=False)
1279
+ op_stack.pop(-1)
1280
+ elif token.string == ">":
1281
+ _pop_make_type()
1282
+ if op_stack[-1] == ":":
1283
+ _pop_make_struct_field()
1284
+
1285
+ # put generated item into the parameter list
1286
+ val = value_stack.pop(-1)
1287
+ value_stack[-1].append(val)
1288
+ # make DataType (i.e., list / map / struct) given args
1289
+ _pop_make_type(with_args=True)
1290
+ op_stack.pop(-1)
1291
+ elif token.type == pytokenize.NAME:
1292
+ if value_stack and value_stack[-1] == "not":
1293
+ value_stack[-1] += " " + token.string
1294
+ else:
1295
+ value_stack.append(token.string)
1296
+ elif token.type == pytokenize.NUMBER:
1297
+ value_stack.append(int(token.string))
1298
+ elif token.type == pytokenize.ENDMARKER:
1299
+ # make final type
1300
+ _pop_make_type()
1301
+ if len(value_stack) > 1:
1302
+ raise ValueError(f"Cannot parse type {type_str}")
1303
+ return value_stack[-1]
1304
+
1305
+
1306
+ def get_python_tag():
1307
+ # todo add implementation suffix for non-GIL tags when PEP703 is ready
1308
+ version_info = sys.version_info
1309
+ return f"cp{version_info[0]}{version_info[1]}"
1310
+
1311
+
1312
+ def get_item_if_scalar(val: Any) -> Any:
1313
+ if isinstance(val, np.ndarray) and val.shape == ():
1314
+ return val.item()
1315
+ return val
1316
+
1317
+
1318
+ def collect_leaf_operators(root) -> List[Type]:
1319
+ result = []
1320
+
1321
+ def _collect(op_type):
1322
+ if len(op_type.__subclasses__()) == 0:
1323
+ result.append(op_type)
1324
+ for subclass in op_type.__subclasses__():
1325
+ _collect(subclass)
1326
+
1327
+ _collect(root)
1328
+ return result
1329
+
1330
+
1331
+ @contextmanager
1332
+ def sync_pyodps_options():
1333
+ from odps.config import option_context as pyodps_option_context
1334
+
1335
+ from .config import options
1336
+
1337
+ with pyodps_option_context() as cfg:
1338
+ cfg.local_timezone = options.local_timezone
1339
+ if options.session.enable_schema:
1340
+ cfg.enable_schema = options.session.enable_schema
1341
+ yield
1342
+
1343
+
1344
+ def str_to_bool(s: Optional[str]) -> Optional[bool]:
1345
+ return s.lower().strip() in ("true", "1") if isinstance(s, str) else s
1346
+
1347
+
1348
+ def is_empty(val):
1349
+ if isinstance(val, (pd.DataFrame, pd.Series, pd.Index)):
1350
+ return val.empty
1351
+ return not bool(val)
1352
+
1353
+
1354
+ def extract_class_name(cls):
1355
+ return cls.__module__ + "#" + cls.__qualname__
1356
+
1357
+
1358
+ def flatten(nested_iterable: Union[List, Tuple]) -> List:
1359
+ """
1360
+ Flatten a nested iterable into a list.
1361
+
1362
+ Parameters
1363
+ ----------
1364
+ nested_iterable : list or tuple
1365
+ an iterable which can contain other iterables
1366
+
1367
+ Returns
1368
+ -------
1369
+ flattened : list
1370
+
1371
+ Examples
1372
+ --------
1373
+ >>> flatten([[0, 1], [2, 3]])
1374
+ [0, 1, 2, 3]
1375
+ >>> flatten([[0, 1], [[3], [4, 5]]])
1376
+ [0, 1, 3, 4, 5]
1377
+ """
1378
+
1379
+ flattened = []
1380
+ stack = list(nested_iterable)[::-1]
1381
+ while len(stack) > 0:
1382
+ inp = stack.pop()
1383
+ if isinstance(inp, (tuple, list)):
1384
+ stack.extend(inp[::-1])
1385
+ else:
1386
+ flattened.append(inp)
1387
+ return flattened
1388
+
1389
+
1390
+ def stack_back(flattened: List, raw: Union[List, Tuple]) -> Union[List, Tuple]:
1391
+ """
1392
+ Organize a new iterable from a flattened list according to raw iterable.
1393
+
1394
+ Parameters
1395
+ ----------
1396
+ flattened : list
1397
+ flattened list
1398
+ raw: list
1399
+ raw iterable
1400
+
1401
+ Returns
1402
+ -------
1403
+ ret : list
1404
+
1405
+ Examples
1406
+ --------
1407
+ >>> raw = [[0, 1], [2, [3, 4]]]
1408
+ >>> flattened = flatten(raw)
1409
+ >>> flattened
1410
+ [0, 1, 2, 3, 4]
1411
+ >>> a = [f + 1 for f in flattened]
1412
+ >>> a
1413
+ [1, 2, 3, 4, 5]
1414
+ >>> stack_back(a, raw)
1415
+ [[1, 2], [3, [4, 5]]]
1416
+ """
1417
+ flattened_iter = iter(flattened)
1418
+ result = list()
1419
+
1420
+ def _stack(container, items):
1421
+ for item in items:
1422
+ if not isinstance(item, (list, tuple)):
1423
+ container.append(next(flattened_iter))
1424
+ else:
1425
+ new_container = list()
1426
+ container.append(new_container)
1427
+ _stack(new_container, item)
1428
+
1429
+ return container
1430
+
1431
+ return _stack(result, raw)
1432
+
1433
+
1434
+ _RetryRetType = TypeVar("_RetryRetType")
1435
+
1436
+
1437
+ def call_with_retry(
1438
+ func: Callable[..., _RetryRetType],
1439
+ *args,
1440
+ retry_times: Optional[int] = None,
1441
+ retry_timeout: TimeoutType = None,
1442
+ delay: TimeoutType = None,
1443
+ reset_func: Optional[Callable] = None,
1444
+ exc_type: Union[
1445
+ Type[BaseException], Tuple[Type[BaseException], ...]
1446
+ ] = BaseException,
1447
+ allow_interrupt: bool = True,
1448
+ no_raise: bool = False,
1449
+ is_func_async: Optional[bool] = None,
1450
+ **kwargs,
1451
+ ) -> _RetryRetType:
1452
+ """
1453
+ Retry calling function given specified times or timeout.
1454
+
1455
+ Parameters
1456
+ ----------
1457
+ func: Callable
1458
+ function to be retried
1459
+ args
1460
+ arguments to be passed to the function
1461
+ retry_times: Optional[int]
1462
+ times to retry the function
1463
+ retry_timeout: TimeoutType
1464
+ timeout in seconds to retry the function
1465
+ delay: TimeoutType
1466
+ delay in seconds between every trial
1467
+ reset_func: Callable
1468
+ Function to call after every trial
1469
+ exc_type: Type[BaseException] | Tuple[Type[BaseException], ...]
1470
+ Exception type for retrial
1471
+ allow_interrupt: bool
1472
+ If True, KeyboardInterrupt will stop the retry
1473
+ no_raise: bool
1474
+ If True, no exception will be raised even if all trials failed
1475
+ is_func_async: bool
1476
+ If True, func will be treated as async
1477
+ kwargs
1478
+ keyword arguments to be passed to the function
1479
+
1480
+ Returns
1481
+ -------
1482
+ Return value of the original function
1483
+ """
1484
+ from .config import options
1485
+
1486
+ retry_num = 0
1487
+ retry_times = retry_times if retry_times is not None else options.retry_times
1488
+ delay = delay if delay is not None else options.retry_delay
1489
+ start_time = time.monotonic() if retry_timeout is not None else None
1490
+
1491
+ def raise_or_continue(exc: BaseException):
1492
+ nonlocal retry_num
1493
+ retry_num += 1
1494
+ if allow_interrupt and isinstance(exc, KeyboardInterrupt):
1495
+ raise exc from None
1496
+ if (retry_times is not None and retry_num > retry_times) or (
1497
+ retry_timeout is not None
1498
+ and start_time is not None
1499
+ and time.monotonic() - start_time > retry_timeout
1500
+ ):
1501
+ if no_raise:
1502
+ return sys.exc_info()
1503
+ raise exc from None
1504
+
1505
+ async def async_retry():
1506
+ while True:
1507
+ try:
1508
+ return await func(*args, **kwargs)
1509
+ except exc_type as ex:
1510
+ await asyncio.sleep(delay)
1511
+ res = raise_or_continue(ex)
1512
+ if res is not None:
1513
+ return res
1514
+
1515
+ if callable(reset_func):
1516
+ reset_res = reset_func()
1517
+ if asyncio.iscoroutine(reset_res):
1518
+ await reset_res
1519
+
1520
+ def sync_retry():
1521
+ while True:
1522
+ try:
1523
+ return func(*args, **kwargs)
1524
+ except exc_type as ex:
1525
+ time.sleep(delay)
1526
+ res = raise_or_continue(ex)
1527
+ if res is not None:
1528
+ return res
1529
+ if callable(reset_func):
1530
+ reset_func()
1531
+
1532
+ unwrap_func = func
1533
+ if is_func_async is None:
1534
+ # unwrap to get true result if func is async
1535
+ while isinstance(unwrap_func, functools.partial):
1536
+ unwrap_func = unwrap_func.func
1537
+
1538
+ if is_func_async or asyncio.iscoroutinefunction(unwrap_func):
1539
+ return async_retry()
1540
+ else:
1541
+ return sync_retry()
1542
+
1543
+
1544
+ def update_wlm_quota_settings(session_id: str, engine_settings: Dict[str, Any]):
1545
+ from .config import options
1546
+
1547
+ engine_quota = engine_settings.get("odps.task.wlm.quota", None)
1548
+ session_quota = options.session.quota_name or None
1549
+ if engine_quota != session_quota and engine_quota:
1550
+ logger.warning(
1551
+ "[Session=%s] Session quota (%s) is different to SubDag engine quota (%s)",
1552
+ session_id,
1553
+ session_quota,
1554
+ engine_quota,
1555
+ )
1556
+ raise ValueError(
1557
+ "Quota name cannot be changed after sessions are created, "
1558
+ f"session_quota={session_quota}, engine_quota={engine_quota}"
1559
+ )
1560
+
1561
+ if session_quota:
1562
+ engine_settings["odps.task.wlm.quota"] = session_quota
1563
+ elif "odps.task.wlm.quota" in engine_settings:
1564
+ engine_settings.pop("odps.task.wlm.quota")
1565
+
1566
+
1567
+ def get_default_table_properties():
1568
+ return {"storagestrategy": "archive"}
1569
+
1570
+
1571
+ def copy_if_possible(obj: Any, deep=False) -> Any:
1572
+ try:
1573
+ return copy.deepcopy(obj) if deep else copy.copy(obj)
1574
+ except: # pragma: no cover
1575
+ return obj
1576
+
1577
+
1578
+ def cache_tileables(*tileables):
1579
+ from .core import ENTITY_TYPE
1580
+
1581
+ if len(tileables) == 1 and isinstance(tileables[0], (tuple, list)):
1582
+ tileables = tileables[0]
1583
+ for t in tileables:
1584
+ if isinstance(t, ENTITY_TYPE):
1585
+ t.cache = True
1586
+
1587
+
1588
+ def ignore_warning(func: Callable):
1589
+ @functools.wraps(func)
1590
+ def inner(*args, **kwargs):
1591
+ with warnings.catch_warnings():
1592
+ warnings.simplefilter("ignore")
1593
+ return func(*args, **kwargs)
1594
+
1595
+ return inner
1596
+
1597
+
1598
+ class ServiceLoggerAdapter(logging.LoggerAdapter):
1599
+ extra_key_mapping = {}
1600
+
1601
+ def process(self, msg, kwargs):
1602
+ merged_extra = (self.extra or {}).copy()
1603
+ merged_extra.update(kwargs)
1604
+
1605
+ prefix = " ".join(
1606
+ f"{self.extra_key_mapping.get(k) or k.capitalize()}={merged_extra[k]}"
1607
+ for k in merged_extra.keys()
1608
+ )
1609
+ msg = f"[{prefix}] {msg}"
1610
+ return msg, kwargs
1611
+
1612
+
1613
+ @contextmanager
1614
+ def atomic_writer(filename, mode="w", **kwargs):
1615
+ """
1616
+ Write to a file in an atomic way.
1617
+ """
1618
+ temp_fd, temp_path = tempfile.mkstemp(dir=os.path.dirname(filename) or ".")
1619
+ os.chmod(temp_path, 0o644)
1620
+ os.close(temp_fd) # Close the file descriptor immediately and we reopen this later.
1621
+
1622
+ try:
1623
+ # Write to temp file.
1624
+ with open(temp_path, mode, **kwargs) as temp_file:
1625
+ yield temp_file
1626
+
1627
+ # Replace the original file with the temp file atomically.
1628
+ os.replace(temp_path, filename)
1629
+ finally:
1630
+ try:
1631
+ os.remove(temp_path)
1632
+ except OSError:
1633
+ pass
1634
+
1635
+
1636
+ def prevent_called_from_pandas(level=2):
1637
+ """Prevent method from being called from pandas"""
1638
+ frame = sys._getframe(level)
1639
+ called_frame = sys._getframe(1)
1640
+ pd_pack_location = os.path.dirname(pd.__file__)
1641
+ if frame.f_code.co_filename.startswith(pd_pack_location):
1642
+ raise AttributeError(called_frame.f_code.co_name)
1643
+
1644
+
1645
+ def combine_error_message_and_traceback(
1646
+ messages: List[str], tracebacks: List[List[str]]
1647
+ ) -> str:
1648
+ tbs = []
1649
+ for msg, tb in zip(messages, tracebacks):
1650
+ tbs.append("".join([msg + "\n"] + tb))
1651
+ return "\nCaused by:\n".join(tbs)
1652
+
1653
+
1654
+ def generate_unique_id(byte_len: int) -> Generator[str, None, None]:
1655
+ """
1656
+ The ids are ensured to be unique in one generator.
1657
+ DO NOT use this generator in global scope or singleton class members,
1658
+ as it may not free the set.
1659
+ """
1660
+ generated_ids = set()
1661
+ while True:
1662
+ new_id = new_random_id(byte_len).hex()
1663
+ if new_id not in generated_ids:
1664
+ generated_ids.add(new_id)
1665
+ yield new_id
1666
+
1667
+
1668
+ def validate_and_adjust_resource_ratio(
1669
+ expect_resources: Dict[str, Any],
1670
+ max_memory_cpu_ratio: float = None,
1671
+ adjust: bool = False,
1672
+ ) -> Tuple[Dict[str, Any], bool]:
1673
+ """
1674
+ Validate and optionally adjust CPU:memory ratio to meet maximum requirements.
1675
+
1676
+ Args:
1677
+ expect_resources: Dictionary containing resource specifications
1678
+ max_memory_cpu_ratio: Maximum memory/cpu ratio (if None, will use config value)
1679
+ adjust: Whether to automatically adjust resources to meet ratio
1680
+
1681
+ Returns:
1682
+ Tuple of (adjusted_resources, was_adjusted)
1683
+ """
1684
+ cpu = expect_resources.get("cpu") or 1
1685
+ memory = expect_resources.get("memory")
1686
+
1687
+ if cpu is None or memory is None or max_memory_cpu_ratio is None:
1688
+ return expect_resources, False
1689
+
1690
+ # Convert memory to GiB if it's a string
1691
+ cpu = max(cpu, 1)
1692
+ memory_gib = parse_size_to_megabytes(memory, default_number_unit="GiB") / 1024
1693
+ current_ratio = memory_gib / cpu
1694
+
1695
+ if current_ratio > max_memory_cpu_ratio:
1696
+ # Adjust CPU to meet maximum ratio, don't reduce resources
1697
+ recommended_cpu = math.ceil(memory_gib / max_memory_cpu_ratio)
1698
+ new_ratio = memory_gib / recommended_cpu
1699
+ if adjust:
1700
+ adjusted_resources = expect_resources.copy()
1701
+ adjusted_resources["cpu"] = recommended_cpu
1702
+
1703
+ warnings.warn(
1704
+ f"UDF resource auto-adjustment: Current UDF settings"
1705
+ f" (CPU: {cpu}, Memory: {memory_gib}Gib, Ratio: {current_ratio:.2f})"
1706
+ f" exceed maximum allowed ratio {max_memory_cpu_ratio:.1f}. "
1707
+ f"Automatically adjusted to (CPU: {recommended_cpu},"
1708
+ f" Memory: {memory_gib:.2f}:1Gib,"
1709
+ f" Ratio: {new_ratio:.2f}:1) to meet requirements."
1710
+ )
1711
+ return adjusted_resources, True
1712
+ else:
1713
+ warnings.warn(
1714
+ f"UDF resource ratio warning: Current UDF settings"
1715
+ f" (CPU: {cpu}, Memory: {memory_gib}Gib, Ratio: {current_ratio:.2f})"
1716
+ f" exceed maximum allowed ratio {max_memory_cpu_ratio:.1f}. "
1717
+ f"Consider adjusting CPU to at least {recommended_cpu}"
1718
+ f" (which would result in Ratio: {new_ratio:.2f}) to meet requirements."
1719
+ )
1720
+
1721
+ return expect_resources, False