teradataml 20.0.0.0__py3-none-any.whl → 20.0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of teradataml might be problematic. Click here for more details.

Files changed (263) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/LICENSE.pdf +0 -0
  3. teradataml/README.md +183 -0
  4. teradataml/__init__.py +6 -3
  5. teradataml/_version.py +2 -2
  6. teradataml/analytics/__init__.py +3 -2
  7. teradataml/analytics/analytic_function_executor.py +275 -40
  8. teradataml/analytics/analytic_query_generator.py +92 -0
  9. teradataml/analytics/byom/__init__.py +3 -2
  10. teradataml/analytics/json_parser/metadata.py +1 -0
  11. teradataml/analytics/json_parser/utils.py +17 -21
  12. teradataml/analytics/meta_class.py +40 -1
  13. teradataml/analytics/sqle/DecisionTreePredict.py +1 -1
  14. teradataml/analytics/sqle/__init__.py +10 -2
  15. teradataml/analytics/table_operator/__init__.py +3 -2
  16. teradataml/analytics/uaf/__init__.py +21 -2
  17. teradataml/analytics/utils.py +62 -1
  18. teradataml/analytics/valib.py +1 -1
  19. teradataml/automl/__init__.py +1553 -319
  20. teradataml/automl/custom_json_utils.py +139 -61
  21. teradataml/automl/data_preparation.py +276 -319
  22. teradataml/automl/data_transformation.py +163 -81
  23. teradataml/automl/feature_engineering.py +402 -239
  24. teradataml/automl/feature_exploration.py +9 -2
  25. teradataml/automl/model_evaluation.py +48 -51
  26. teradataml/automl/model_training.py +291 -189
  27. teradataml/catalog/byom.py +8 -8
  28. teradataml/catalog/model_cataloging_utils.py +1 -1
  29. teradataml/clients/auth_client.py +133 -0
  30. teradataml/clients/pkce_client.py +1 -1
  31. teradataml/common/aed_utils.py +3 -2
  32. teradataml/common/constants.py +48 -6
  33. teradataml/common/deprecations.py +13 -7
  34. teradataml/common/garbagecollector.py +156 -120
  35. teradataml/common/messagecodes.py +6 -1
  36. teradataml/common/messages.py +3 -1
  37. teradataml/common/sqlbundle.py +1 -1
  38. teradataml/common/utils.py +103 -11
  39. teradataml/common/wrapper_utils.py +1 -1
  40. teradataml/context/context.py +121 -31
  41. teradataml/data/advertising.csv +201 -0
  42. teradataml/data/bank_marketing.csv +11163 -0
  43. teradataml/data/bike_sharing.csv +732 -0
  44. teradataml/data/boston2cols.csv +721 -0
  45. teradataml/data/breast_cancer.csv +570 -0
  46. teradataml/data/complaints_test_tokenized.csv +353 -0
  47. teradataml/data/complaints_tokens_model.csv +348 -0
  48. teradataml/data/covid_confirm_sd.csv +83 -0
  49. teradataml/data/customer_segmentation_test.csv +2628 -0
  50. teradataml/data/customer_segmentation_train.csv +8069 -0
  51. teradataml/data/dataframe_example.json +10 -0
  52. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingFit.py +3 -1
  53. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +6 -0
  54. teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +5 -1
  55. teradataml/data/docs/sqle/docs_17_20/ANOVA.py +61 -1
  56. teradataml/data/docs/sqle/docs_17_20/CFilter.py +132 -0
  57. teradataml/data/docs/sqle/docs_17_20/ColumnTransformer.py +2 -0
  58. teradataml/data/docs/sqle/docs_17_20/FTest.py +105 -26
  59. teradataml/data/docs/sqle/docs_17_20/GLM.py +162 -1
  60. teradataml/data/docs/sqle/docs_17_20/GetFutileColumns.py +5 -3
  61. teradataml/data/docs/sqle/docs_17_20/KMeans.py +48 -1
  62. teradataml/data/docs/sqle/docs_17_20/NaiveBayes.py +162 -0
  63. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +3 -2
  64. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingFit.py +5 -0
  65. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +6 -0
  66. teradataml/data/docs/sqle/docs_17_20/OutlierFilterFit.py +2 -0
  67. teradataml/data/docs/sqle/docs_17_20/Pivoting.py +279 -0
  68. teradataml/data/docs/sqle/docs_17_20/ROC.py +3 -2
  69. teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +13 -2
  70. teradataml/data/docs/sqle/docs_17_20/ScaleFit.py +119 -1
  71. teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +93 -1
  72. teradataml/data/docs/sqle/docs_17_20/Shap.py +197 -0
  73. teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +163 -1
  74. teradataml/data/docs/sqle/docs_17_20/TDNaiveBayesPredict.py +189 -0
  75. teradataml/data/docs/sqle/docs_17_20/TFIDF.py +142 -0
  76. teradataml/data/docs/sqle/docs_17_20/Unpivoting.py +216 -0
  77. teradataml/data/docs/sqle/docs_17_20/XGBoost.py +12 -4
  78. teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +7 -1
  79. teradataml/data/docs/sqle/docs_17_20/ZTest.py +72 -7
  80. teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -10
  81. teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +1 -1
  82. teradataml/data/docs/uaf/docs_17_20/ArimaForecast.py +35 -5
  83. teradataml/data/docs/uaf/docs_17_20/ArimaValidate.py +3 -1
  84. teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +293 -0
  85. teradataml/data/docs/uaf/docs_17_20/AutoArima.py +354 -0
  86. teradataml/data/docs/uaf/docs_17_20/BreuschGodfrey.py +3 -2
  87. teradataml/data/docs/uaf/docs_17_20/BreuschPaganGodfrey.py +1 -1
  88. teradataml/data/docs/uaf/docs_17_20/Convolve.py +13 -10
  89. teradataml/data/docs/uaf/docs_17_20/Convolve2.py +4 -1
  90. teradataml/data/docs/uaf/docs_17_20/CumulPeriodogram.py +5 -4
  91. teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +4 -4
  92. teradataml/data/docs/uaf/docs_17_20/DWT.py +235 -0
  93. teradataml/data/docs/uaf/docs_17_20/DWT2D.py +214 -0
  94. teradataml/data/docs/uaf/docs_17_20/DurbinWatson.py +1 -1
  95. teradataml/data/docs/uaf/docs_17_20/ExtractResults.py +1 -1
  96. teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +160 -0
  97. teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +1 -1
  98. teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +9 -31
  99. teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +4 -2
  100. teradataml/data/docs/uaf/docs_17_20/IDFFT2.py +1 -8
  101. teradataml/data/docs/uaf/docs_17_20/IDWT.py +236 -0
  102. teradataml/data/docs/uaf/docs_17_20/IDWT2D.py +226 -0
  103. teradataml/data/docs/uaf/docs_17_20/IQR.py +134 -0
  104. teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
  105. teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +2 -2
  106. teradataml/data/docs/uaf/docs_17_20/MAMean.py +3 -3
  107. teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +297 -0
  108. teradataml/data/docs/uaf/docs_17_20/MatrixMultiply.py +15 -6
  109. teradataml/data/docs/uaf/docs_17_20/PACF.py +0 -1
  110. teradataml/data/docs/uaf/docs_17_20/Portman.py +2 -2
  111. teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
  112. teradataml/data/docs/uaf/docs_17_20/Resample.py +9 -1
  113. teradataml/data/docs/uaf/docs_17_20/SAX.py +246 -0
  114. teradataml/data/docs/uaf/docs_17_20/SeasonalNormalize.py +17 -10
  115. teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
  116. teradataml/data/docs/uaf/docs_17_20/WhitesGeneral.py +3 -1
  117. teradataml/data/docs/uaf/docs_17_20/WindowDFFT.py +368 -0
  118. teradataml/data/dwt2d_dataTable.csv +65 -0
  119. teradataml/data/dwt_dataTable.csv +8 -0
  120. teradataml/data/dwt_filterTable.csv +3 -0
  121. teradataml/data/finance_data4.csv +13 -0
  122. teradataml/data/glm_example.json +28 -1
  123. teradataml/data/grocery_transaction.csv +19 -0
  124. teradataml/data/housing_train_segment.csv +201 -0
  125. teradataml/data/idwt2d_dataTable.csv +5 -0
  126. teradataml/data/idwt_dataTable.csv +8 -0
  127. teradataml/data/idwt_filterTable.csv +3 -0
  128. teradataml/data/insect2Cols.csv +61 -0
  129. teradataml/data/interval_data.csv +5 -0
  130. teradataml/data/jsons/paired_functions.json +14 -0
  131. teradataml/data/jsons/sqle/17.20/TD_ANOVA.json +99 -27
  132. teradataml/data/jsons/sqle/17.20/TD_CFilter.json +118 -0
  133. teradataml/data/jsons/sqle/17.20/TD_FTest.json +166 -83
  134. teradataml/data/jsons/sqle/17.20/TD_GLM.json +90 -14
  135. teradataml/data/jsons/sqle/17.20/TD_GLMPREDICT.json +48 -5
  136. teradataml/data/jsons/sqle/17.20/TD_GetFutileColumns.json +5 -3
  137. teradataml/data/jsons/sqle/17.20/TD_KMeans.json +31 -11
  138. teradataml/data/jsons/sqle/17.20/TD_NaiveBayes.json +193 -0
  139. teradataml/data/jsons/sqle/17.20/TD_NaiveBayesPredict.json +212 -0
  140. teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineFit.json +3 -2
  141. teradataml/data/jsons/sqle/17.20/TD_OneClassSVM.json +9 -9
  142. teradataml/data/jsons/sqle/17.20/TD_Pivoting.json +280 -0
  143. teradataml/data/jsons/sqle/17.20/TD_ROC.json +2 -1
  144. teradataml/data/jsons/sqle/17.20/TD_SVM.json +16 -16
  145. teradataml/data/jsons/sqle/17.20/TD_SVMPredict.json +19 -1
  146. teradataml/data/jsons/sqle/17.20/TD_ScaleFit.json +168 -15
  147. teradataml/data/jsons/sqle/17.20/TD_ScaleTransform.json +50 -1
  148. teradataml/data/jsons/sqle/17.20/TD_Shap.json +222 -0
  149. teradataml/data/jsons/sqle/17.20/TD_TFIDF.json +162 -0
  150. teradataml/data/jsons/sqle/17.20/TD_Unpivoting.json +235 -0
  151. teradataml/data/jsons/sqle/17.20/TD_XGBoost.json +25 -7
  152. teradataml/data/jsons/sqle/17.20/TD_XGBoostPredict.json +17 -4
  153. teradataml/data/jsons/sqle/17.20/TD_ZTest.json +157 -80
  154. teradataml/data/jsons/storedprocedure/17.20/TD_FILTERFACTORY1D.json +150 -0
  155. teradataml/data/jsons/uaf/17.20/TD_ACF.json +1 -18
  156. teradataml/data/jsons/uaf/17.20/TD_ARIMAESTIMATE.json +3 -16
  157. teradataml/data/jsons/uaf/17.20/TD_ARIMAFORECAST.json +0 -3
  158. teradataml/data/jsons/uaf/17.20/TD_ARIMAVALIDATE.json +5 -3
  159. teradataml/data/jsons/uaf/17.20/TD_ARIMAXESTIMATE.json +362 -0
  160. teradataml/data/jsons/uaf/17.20/TD_AUTOARIMA.json +469 -0
  161. teradataml/data/jsons/uaf/17.20/TD_BINARYMATRIXOP.json +0 -3
  162. teradataml/data/jsons/uaf/17.20/TD_BINARYSERIESOP.json +0 -2
  163. teradataml/data/jsons/uaf/17.20/TD_BREUSCH_GODFREY.json +2 -1
  164. teradataml/data/jsons/uaf/17.20/TD_BREUSCH_PAGAN_GODFREY.json +2 -5
  165. teradataml/data/jsons/uaf/17.20/TD_CONVOLVE.json +3 -6
  166. teradataml/data/jsons/uaf/17.20/TD_CONVOLVE2.json +1 -3
  167. teradataml/data/jsons/uaf/17.20/TD_CUMUL_PERIODOGRAM.json +0 -5
  168. teradataml/data/jsons/uaf/17.20/TD_DFFT.json +1 -4
  169. teradataml/data/jsons/uaf/17.20/TD_DFFT2.json +2 -7
  170. teradataml/data/jsons/uaf/17.20/TD_DFFT2CONV.json +1 -2
  171. teradataml/data/jsons/uaf/17.20/TD_DFFTCONV.json +0 -2
  172. teradataml/data/jsons/uaf/17.20/TD_DTW.json +3 -6
  173. teradataml/data/jsons/uaf/17.20/TD_DWT.json +173 -0
  174. teradataml/data/jsons/uaf/17.20/TD_DWT2D.json +160 -0
  175. teradataml/data/jsons/uaf/17.20/TD_FITMETRICS.json +1 -1
  176. teradataml/data/jsons/uaf/17.20/TD_GOLDFELD_QUANDT.json +16 -30
  177. teradataml/data/jsons/uaf/17.20/{TD_HOLT_WINTERS_FORECAST.json → TD_HOLT_WINTERS_FORECASTER.json} +1 -2
  178. teradataml/data/jsons/uaf/17.20/TD_IDFFT2.json +1 -15
  179. teradataml/data/jsons/uaf/17.20/TD_IDWT.json +162 -0
  180. teradataml/data/jsons/uaf/17.20/TD_IDWT2D.json +149 -0
  181. teradataml/data/jsons/uaf/17.20/TD_IQR.json +117 -0
  182. teradataml/data/jsons/uaf/17.20/TD_LINEAR_REGR.json +1 -1
  183. teradataml/data/jsons/uaf/17.20/TD_LINESPEC.json +1 -1
  184. teradataml/data/jsons/uaf/17.20/TD_MAMEAN.json +1 -3
  185. teradataml/data/jsons/uaf/17.20/TD_MATRIX2IMAGE.json +209 -0
  186. teradataml/data/jsons/uaf/17.20/TD_PACF.json +2 -2
  187. teradataml/data/jsons/uaf/17.20/TD_POWERSPEC.json +5 -5
  188. teradataml/data/jsons/uaf/17.20/TD_RESAMPLE.json +48 -28
  189. teradataml/data/jsons/uaf/17.20/TD_SAX.json +208 -0
  190. teradataml/data/jsons/uaf/17.20/TD_SEASONALNORMALIZE.json +12 -6
  191. teradataml/data/jsons/uaf/17.20/TD_SIMPLEEXP.json +0 -1
  192. teradataml/data/jsons/uaf/17.20/TD_TRACKINGOP.json +8 -8
  193. teradataml/data/jsons/uaf/17.20/TD_UNDIFF.json +1 -1
  194. teradataml/data/jsons/uaf/17.20/TD_UNNORMALIZE.json +1 -1
  195. teradataml/data/jsons/uaf/17.20/TD_WINDOWDFFT.json +400 -0
  196. teradataml/data/kmeans_example.json +5 -0
  197. teradataml/data/kmeans_table.csv +10 -0
  198. teradataml/data/load_example_data.py +8 -2
  199. teradataml/data/naivebayestextclassifier_example.json +1 -1
  200. teradataml/data/naivebayestextclassifierpredict_example.json +11 -0
  201. teradataml/data/onehot_encoder_train.csv +4 -0
  202. teradataml/data/openml_example.json +29 -0
  203. teradataml/data/peppers.png +0 -0
  204. teradataml/data/real_values.csv +14 -0
  205. teradataml/data/sax_example.json +8 -0
  206. teradataml/data/scale_attributes.csv +3 -0
  207. teradataml/data/scale_example.json +52 -1
  208. teradataml/data/scale_input_part_sparse.csv +31 -0
  209. teradataml/data/scale_input_partitioned.csv +16 -0
  210. teradataml/data/scale_input_sparse.csv +11 -0
  211. teradataml/data/scale_parameters.csv +3 -0
  212. teradataml/data/scripts/deploy_script.py +21 -2
  213. teradataml/data/scripts/sklearn/sklearn_fit.py +40 -37
  214. teradataml/data/scripts/sklearn/sklearn_fit_predict.py +22 -30
  215. teradataml/data/scripts/sklearn/sklearn_function.template +42 -24
  216. teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +23 -33
  217. teradataml/data/scripts/sklearn/sklearn_neighbors.py +19 -28
  218. teradataml/data/scripts/sklearn/sklearn_score.py +32 -32
  219. teradataml/data/scripts/sklearn/sklearn_transform.py +85 -42
  220. teradataml/data/star_pivot.csv +8 -0
  221. teradataml/data/templates/open_source_ml.json +2 -1
  222. teradataml/data/teradataml_example.json +97 -1
  223. teradataml/data/timestamp_data.csv +4 -0
  224. teradataml/data/titanic_dataset_unpivoted.csv +19 -0
  225. teradataml/data/uaf_example.json +55 -1
  226. teradataml/data/unpivot_example.json +15 -0
  227. teradataml/data/url_data.csv +9 -0
  228. teradataml/data/windowdfft.csv +16 -0
  229. teradataml/data/ztest_example.json +16 -0
  230. teradataml/dataframe/copy_to.py +9 -4
  231. teradataml/dataframe/data_transfer.py +125 -64
  232. teradataml/dataframe/dataframe.py +575 -57
  233. teradataml/dataframe/dataframe_utils.py +47 -9
  234. teradataml/dataframe/fastload.py +273 -90
  235. teradataml/dataframe/functions.py +339 -0
  236. teradataml/dataframe/row.py +160 -0
  237. teradataml/dataframe/setop.py +2 -2
  238. teradataml/dataframe/sql.py +740 -18
  239. teradataml/dataframe/window.py +1 -1
  240. teradataml/dbutils/dbutils.py +324 -18
  241. teradataml/geospatial/geodataframe.py +1 -1
  242. teradataml/geospatial/geodataframecolumn.py +1 -1
  243. teradataml/hyperparameter_tuner/optimizer.py +13 -13
  244. teradataml/lib/aed_0_1.dll +0 -0
  245. teradataml/opensource/sklearn/_sklearn_wrapper.py +254 -122
  246. teradataml/options/__init__.py +16 -5
  247. teradataml/options/configure.py +39 -6
  248. teradataml/options/display.py +2 -2
  249. teradataml/plot/axis.py +4 -4
  250. teradataml/scriptmgmt/UserEnv.py +26 -19
  251. teradataml/scriptmgmt/lls_utils.py +120 -16
  252. teradataml/table_operators/Script.py +4 -5
  253. teradataml/table_operators/TableOperator.py +160 -26
  254. teradataml/table_operators/table_operator_util.py +88 -41
  255. teradataml/table_operators/templates/dataframe_udf.template +63 -0
  256. teradataml/telemetry_utils/__init__.py +0 -0
  257. teradataml/telemetry_utils/queryband.py +52 -0
  258. teradataml/utils/validators.py +41 -3
  259. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/METADATA +191 -6
  260. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/RECORD +263 -185
  261. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/WHEEL +0 -0
  262. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/top_level.txt +0 -0
  263. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.2.dist-info}/zip-safe +0 -0
@@ -0,0 +1,339 @@
1
+ from teradatasqlalchemy.types import VARCHAR
2
+ from teradataml.utils.validators import _Validators
3
+ from teradataml.dataframe.sql import _SQLColumnExpression
4
+ from teradatasqlalchemy import (BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT,
5
+ NUMBER)
6
+ from teradatasqlalchemy import (TIMESTAMP, DATE, TIME)
7
+ from teradatasqlalchemy import (CHAR, VARCHAR, CLOB)
8
+ from teradatasqlalchemy import (BYTE, VARBYTE, BLOB)
9
+ from teradatasqlalchemy import (PERIOD_DATE, PERIOD_TIME, PERIOD_TIMESTAMP)
10
+ from teradatasqlalchemy import (INTERVAL_YEAR, INTERVAL_YEAR_TO_MONTH, INTERVAL_MONTH,
11
+ INTERVAL_DAY,INTERVAL_DAY_TO_HOUR, INTERVAL_DAY_TO_MINUTE,
12
+ INTERVAL_DAY_TO_SECOND, INTERVAL_HOUR,
13
+ INTERVAL_HOUR_TO_MINUTE, INTERVAL_HOUR_TO_SECOND,
14
+ INTERVAL_MINUTE, INTERVAL_MINUTE_TO_SECOND,
15
+ INTERVAL_SECOND)
16
+
17
+ def udf(user_function=None, returns=VARCHAR(1024), env_name = None, delimiter=',', quotechar=None):
18
+ """
19
+ DESCRIPTION:
20
+ Creates a user defined function (UDF).
21
+
22
+ PARAMETERS:
23
+ user_function:
24
+ Required Argument.
25
+ Specifies the user defined function to create a column for
26
+ teradataml DataFrame.
27
+ Types: function
28
+ Note:
29
+ 1. Lambda Function are not supported.
30
+
31
+ returns:
32
+ Optional Argument.
33
+ Specifies the output column type.
34
+ Types: teradata type
35
+ Default: VARCHAR(1024)
36
+
37
+ env_name:
38
+ Optional Argument.
39
+ Specifies the name of the remote user environment or an object of
40
+ class UserEnv for VantageCloud Lake.
41
+ Types: str or oject of class UserEnv.
42
+ Note:
43
+ * One can set up a user environment with required packages using teradataml
44
+ Open Analytics APIs. If no ``env_name`` is provided, udf use the default
45
+ ``openml_env`` user environment. This default environment has latest Python
46
+ and scikit-learn versions that are supported by Open Analytics Framework
47
+ at the time of creating environment.
48
+
49
+ delimiter:
50
+ Optional Argument.
51
+ Specifies a delimiter to use when reading columns from a row and
52
+ writing result columns.
53
+ Default value: ','
54
+ Types: str with one character
55
+ Notes:
56
+ * This argument cannot be same as "quotechar" argument.
57
+ * This argument cannot be a newline character.
58
+ * Use a different delimiter if categorial columns in the data contains
59
+ a character same as the delimiter.
60
+
61
+ quotechar:
62
+ Optional Argument.
63
+ Specifies a character that forces input of the user function
64
+ to be quoted using this specified character.
65
+ Using this argument enables the Advanced SQL Engine to
66
+ distinguish between NULL fields and empty strings.
67
+ A string with length zero is quoted, while NULL fields are not.
68
+ Default value: None
69
+ Types: str with one character
70
+ Notes:
71
+ * This argument cannot be same as "delimiter" argument.
72
+ * This argument cannot be a newline character.
73
+
74
+ RETURNS:
75
+ ColumnExpression
76
+
77
+ RAISES:
78
+ TeradataMLException
79
+
80
+ NOTES:
81
+ 1. While working on date and time data types one must format these to supported formats.
82
+ (See Requisite Input and Output Structures in Open Analytics Framework for more details.)
83
+ 2. Required packages to run the user defined function must be installed in remote user
84
+ environment using install_lib function Of UserEnv class. Import statements of these
85
+ packages should be inside the user defined function itself.
86
+ 3. One can't call a regular function defined outside the udf from the user defined function.
87
+ The function definition and call must be inside the udf. Look at Example 9 to understand more.
88
+
89
+ EXAMPLES:
90
+ # Load the data to run the example.
91
+ >>> load_example_data("dataframe", "sales")
92
+
93
+ # Create a DataFrame on 'sales' table.
94
+ >>> df = DataFrame("sales")
95
+ >>> df
96
+ Feb Jan Mar Apr datetime
97
+ accounts
98
+ Yellow Inc 90.0 NaN NaN NaN 04/01/2017
99
+ Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
100
+ Red Inc 200.0 150.0 140.0 NaN 04/01/2017
101
+ Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
102
+ Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
103
+ Orange Inc 210.0 NaN NaN 250.0 04/01/2017
104
+
105
+ # Example 1: Create the user defined function to get the values in 'accounts'
106
+ # to upper case without passing returns argument.
107
+ >>> from teradataml.dataframe.functions import udf
108
+ >>> @udf
109
+ ... def to_upper(s):
110
+ ... if s is not None:
111
+ ... return s.upper()
112
+ >>>
113
+ # Assign the Column Expression returned by user defined function
114
+ # to the DataFrame.
115
+ >>> res = df.assign(upper_stats = to_upper('accounts'))
116
+ >>> res
117
+ Feb Jan Mar Apr datetime upper_stats
118
+ accounts
119
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 ALPHA CO
120
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 BLUE INC
121
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 YELLOW INC
122
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 JONES LLC
123
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 ORANGE INC
124
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 RED INC
125
+ >>>
126
+
127
+ # Example 2: Create a user defined function to add length of string values in column
128
+ # 'accounts' with column 'Feb' and store the result in Integer type column.
129
+ >>> from teradatasqlalchemy.types import INTEGER
130
+ >>> @udf(returns=INTEGER())
131
+ ... def sum(x, y):
132
+ ... return len(x)+y
133
+ >>>
134
+ # Assign the Column Expression returned by user defined function
135
+ # to the DataFrame.
136
+ >>> res = df.assign(len_sum = sum('accounts', 'Feb'))
137
+ >>> res
138
+ Feb Jan Mar Apr datetime len_sum
139
+ accounts
140
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 218
141
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 98
142
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 100
143
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 209
144
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 220
145
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 207
146
+ >>>
147
+
148
+ # Example 3: Create a function to get the values in 'accounts' to upper case
149
+ # and pass it to udf as parameter to create a user defined function.
150
+ >>> from teradataml.dataframe.functions import udf
151
+ >>> def to_upper(s):
152
+ ... if s is not None:
153
+ ... return s.upper()
154
+ >>> upper_case = udf(to_upper)
155
+ >>>
156
+ # Assign the Column Expression returned by user defined function
157
+ # to the DataFrame.
158
+ >>> res = df.assign(upper_stats = upper_case('accounts'))
159
+ >>> res
160
+ Feb Jan Mar Apr datetime upper_stats
161
+ accounts
162
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 ALPHA CO
163
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 BLUE INC
164
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 YELLOW INC
165
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 JONES LLC
166
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 ORANGE INC
167
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 RED INC
168
+ >>>
169
+
170
+ # Example 4: Create a user defined function to add 4 to the 'datetime' column
171
+ # and store the result in DATE type column.
172
+ >>> from teradatasqlalchemy.types import DATE
173
+ >>> import datetime
174
+ >>> @udf(returns=DATE())
175
+ ... def add_date(x, y):
176
+ ... return (datetime.datetime.strptime(x, "%y/%m/%d")+datetime.timedelta(y)).strftime("%y/%m/%d")
177
+ >>>
178
+ # Assign the Column Expression returned by user defined function
179
+ # to the DataFrame.
180
+ >>> res = df.assign(new_date = add_date('datetime', 4))
181
+ >>> res
182
+ Feb Jan Mar Apr datetime new_date
183
+ accounts
184
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 17/01/08
185
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 17/01/08
186
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 17/01/08
187
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 17/01/08
188
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 17/01/08
189
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 17/01/08
190
+
191
+ # Example 5: Create a user defined function to add 4 to the 'datetime' column
192
+ # without passing returns argument.
193
+ >>> from teradatasqlalchemy.types import DATE
194
+ >>> import datetime
195
+ >>> @udf
196
+ ... def add_date(x, y):
197
+ ... return (datetime.datetime.strptime(x, "%y/%m/%d")+datetime.timedelta(y))
198
+ >>>
199
+ # Assign the Column Expression returned by user defined function
200
+ # to the DataFrame.
201
+ >>> res = df.assign(new_date = add_date('datetime', 4))
202
+ >>> res
203
+ Feb Jan Mar Apr datetime new_date
204
+ accounts
205
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 2017-01-08 00:00:00
206
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 2017-01-08 00:00:00
207
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 2017-01-08 00:00:00
208
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 2017-01-08 00:00:00
209
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 2017-01-08 00:00:00
210
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 2017-01-08 00:00:00
211
+
212
+ # Example 6: Create a two user defined function to 'to_upper' and 'sum',
213
+ # 'to_upper' to get the values in 'accounts' to upper case and
214
+ # 'sum' to add length of string values in column 'accounts'
215
+ # with column 'Feb' and store the result in Integer type column.
216
+ >>> @udf
217
+ ... def to_upper(s):
218
+ ... if s is not None:
219
+ ... return s.upper()
220
+ >>>
221
+ >>> from teradatasqlalchemy.types import INTEGER
222
+ >>> @udf(returns=INTEGER())
223
+ ... def sum(x, y):
224
+ ... return len(x)+y
225
+ >>>
226
+ # Assign the both Column Expression returned by user defined functions
227
+ # to the DataFrame.
228
+ >>> res = df.assign(upper_stats = to_upper('accounts'), len_sum = sum('accounts', 'Feb'))
229
+ >>> res
230
+ Feb Jan Mar Apr datetime upper_stats len_sum
231
+ accounts
232
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 BLUE INC 98
233
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 RED INC 207
234
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 YELLOW INC 100
235
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 JONES LLC 209
236
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 ORANGE INC 220
237
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 ALPHA CO 218
238
+ >>>
239
+
240
+ # Example 7: Convert the values is 'accounts' column to upper case using a user
241
+ # defined function on Vantage Cloud Lake.
242
+ # Create a Python 3.10.5 environment with given name and description in Vantage.
243
+ >>> env = create_env('test_udf', 'python_3.10.5', 'Test environment for UDF')
244
+ User environment 'test_udf' created.
245
+ >>>
246
+ # Create a user defined functions to 'to_upper' to get the values in upper case
247
+ # and pass the user env to run it on.
248
+ >>> from teradataml.dataframe.functions import udf
249
+ >>> @udf(env_name = env)
250
+ ... def to_upper(s):
251
+ ... if s is not None:
252
+ ... return s.upper()
253
+ >>>
254
+ # Assign the Column Expression returned by user defined function
255
+ # to the DataFrame.
256
+ >>> df.assign(upper_stats = to_upper('accounts'))
257
+ Feb Jan Mar Apr datetime upper_stats
258
+ accounts
259
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 ALPHA CO
260
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 BLUE INC
261
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 YELLOW INC
262
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 JONES LLC
263
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 ORANGE INC
264
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 RED INC
265
+
266
+ # Example 8: Create a user defined function to add 4 to the 'datetime' column
267
+ # and store the result in DATE type column on Vantage Cloud Lake.
268
+ >>> from teradatasqlalchemy.types import DATE
269
+ >>> import datetime
270
+ >>> @udf(returns=DATE())
271
+ ... def add_date(x, y):
272
+ ... return (datetime.datetime.strptime(x, "%Y-%m-%d")+datetime.timedelta(y)).strftime("%Y-%m-%d")
273
+ >>>
274
+ # Assign the Column Expression returned by user defined function
275
+ # to the DataFrame.
276
+ >>> res = df.assign(new_date = add_date('datetime', 4))
277
+ >>> res
278
+ Feb Jan Mar Apr datetime new_date
279
+ accounts
280
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 17/01/08
281
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 17/01/08
282
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 17/01/08
283
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 17/01/08
284
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 17/01/08
285
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 17/01/08
286
+ >>>
287
+
288
+ # Example 9: Define a function 'inner_add_date' inside the udf to create a
289
+ # date object by passing year, month, and day and add 1 to that date.
290
+ # Call this function inside the user defined function.
291
+ >>> @udf
292
+ ... def add_date(y,m,d):
293
+ ... import datetime
294
+ ... def inner_add_date(y,m,d):
295
+ ... return datetime.date(y,m,d) + datetime.timedelta(1)
296
+ ... return inner_add_date(y,m,d)
297
+
298
+ # Assign the Column Expression returned by user defined function
299
+ # to the DataFrame.
300
+ >>> res = df.assign(new_date = add_date(2021, 10, 5))
301
+ >>> res
302
+ Feb Jan Mar Apr datetime new_date
303
+ accounts
304
+ Jones LLC 200.0 150.0 140.0 180.0 17/01/04 2021-10-06
305
+ Blue Inc 90.0 50.0 95.0 101.0 17/01/04 2021-10-06
306
+ Yellow Inc 90.0 NaN NaN NaN 17/01/04 2021-10-06
307
+ Orange Inc 210.0 NaN NaN 250.0 17/01/04 2021-10-06
308
+ Alpha Co 210.0 200.0 215.0 250.0 17/01/04 2021-10-06
309
+ Red Inc 200.0 150.0 140.0 NaN 17/01/04 2021-10-06
310
+ >>>
311
+ """
312
+
313
+ allowed_datatypes = (BYTEINT, SMALLINT, INTEGER, BIGINT, DECIMAL, FLOAT, NUMBER,
314
+ TIMESTAMP, DATE, TIME, CHAR, VARCHAR, CLOB, BYTE, VARBYTE,
315
+ BLOB, PERIOD_DATE, PERIOD_TIME, PERIOD_TIMESTAMP,
316
+ INTERVAL_YEAR, INTERVAL_YEAR_TO_MONTH, INTERVAL_MONTH,
317
+ INTERVAL_DAY, INTERVAL_DAY_TO_HOUR, INTERVAL_DAY_TO_MINUTE,
318
+ INTERVAL_DAY_TO_SECOND, INTERVAL_HOUR,
319
+ INTERVAL_HOUR_TO_MINUTE, INTERVAL_HOUR_TO_SECOND,
320
+ INTERVAL_MINUTE, INTERVAL_MINUTE_TO_SECOND, INTERVAL_SECOND
321
+ )
322
+
323
+ # Validate datatypes in returns.
324
+ _Validators._validate_function_arguments([["returns", returns, False, allowed_datatypes]])
325
+
326
+ # Notation: @udf(returnType=INTEGER())
327
+ if user_function is None:
328
+ def wrapper(f):
329
+ def func_(*args):
330
+ return _SQLColumnExpression(expression=None, udf=f, udf_type=returns, udf_args=args,\
331
+ env_name=env_name, delimiter=delimiter, quotechar=quotechar)
332
+ return func_
333
+ return wrapper
334
+ # Notation: @udf
335
+ else:
336
+ def func_(*args):
337
+ return _SQLColumnExpression(expression=None, udf=user_function, udf_type=returns, udf_args=args,\
338
+ env_name=env_name, delimiter=delimiter, quotechar=quotechar)
339
+ return func_
@@ -0,0 +1,160 @@
1
+ """
2
+ Unpublished work.
3
+ Copyright (c) 2021 by Teradata Corporation. All rights reserved.
4
+ TERADATA CORPORATION CONFIDENTIAL AND TRADE SECRET
5
+
6
+ Primary Owner: pradeep.garre@teradata.com
7
+ Secondary Owner: PankajVinod.Purandare@teradata.com
8
+
9
+ This file implements the Row for teradataml DataFrame.
10
+ """
11
+
12
+
13
+ class _Row:
14
+ """ Class for representing a row in teradataml DataFrame. """
15
+ def __init__(self, columns, values):
16
+ """
17
+ DESCRIPTION:
18
+ Constructor for creating Row object.
19
+
20
+ PARAMETERS:
21
+ columns:
22
+ Required Argument.
23
+ Specifies the name(s) of the columns for the corresponding
24
+ teradataml DataFrame.
25
+ Types: list
26
+
27
+ values:
28
+ Required Argument.
29
+ Specifies the corresponding values for the columns.
30
+ Types: list
31
+
32
+ RAISES:
33
+ None
34
+
35
+ EXAMPLES:
36
+
37
+ # Example 1: Create a Row for columns 'a', 'b', 'c' and corresponding values 'p', 'q', 'r'.
38
+ >>> from teradataml.utils.utils import Row
39
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
40
+ """
41
+ self.__data = dict(zip(columns, values))
42
+ self.__values = values
43
+
44
+ # Create a function _asdict similar to namedtuple._asdict
45
+ self._asdict = lambda: self.__data
46
+
47
+ def __getattr__(self, item):
48
+ """
49
+ DESCRIPTION:
50
+ Retrieve the corresponding value for column
51
+ using dot(.) notation.
52
+
53
+ PARAMETERS:
54
+ item:
55
+ Required Argument.
56
+ Specifies name of the column.
57
+ Types: str
58
+
59
+ RETURNS:
60
+ str OR int OR float OR datetime
61
+
62
+ EXAMPLES:
63
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
64
+ >>> row.a
65
+ """
66
+ # Check if item is a valid column or not. If yes, proceed. Otherwise raise error.
67
+ if item in self.__data:
68
+ return self.__data[item]
69
+
70
+ raise AttributeError("'Row' object has no attribute '{}'".format(item))
71
+
72
+ def __getitem__(self, item):
73
+ """
74
+ DESCRIPTION:
75
+ Retrieve the corresponding value for column
76
+ using square bracket([]) notation.
77
+
78
+ PARAMETERS:
79
+ item:
80
+ Required Argument.
81
+ Specifies the name or the index of the column.
82
+ Types: str
83
+
84
+ RETURNS:
85
+ str OR int OR float OR datetime
86
+
87
+ EXAMPLES:
88
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
89
+ >>> row['a']
90
+ 'p'
91
+ >>> row[1]
92
+ 'q'
93
+ """
94
+ # User's can retrieve the value of a column either by using name of the
95
+ # column or by index of column position.
96
+ if isinstance(item, int):
97
+
98
+ # Check if sourced index is valid or not.
99
+ if item >= len(self.__values):
100
+ raise IndexError("tuple index out of range")
101
+
102
+ return self.__values[item]
103
+
104
+ # If it is a string, retrieve it from here. Otherwise, raise error.
105
+ if item in self.__data:
106
+ return self.__data[item]
107
+
108
+ raise AttributeError("'Row' object has no attribute '{}'".format(item))
109
+
110
+ def __dir__(self):
111
+ """
112
+ DESCRIPTION:
113
+ Provide the suggestions for column names.
114
+
115
+ PARAMETERS:
116
+ None
117
+
118
+ RETURNS:
119
+ tuple
120
+
121
+ EXAMPLES:
122
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
123
+ >>> dir(row)
124
+ """
125
+ return tuple(col for col in self.__data)
126
+
127
+ def __str__(self):
128
+ """
129
+ DESCRIPTION:
130
+ Returns the string representation of _Row object.
131
+
132
+ PARAMETERS:
133
+ None
134
+
135
+ RETURNS:
136
+ tuple
137
+
138
+ EXAMPLES:
139
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
140
+ >>> print(row)
141
+ """
142
+ return self.__repr__()
143
+
144
+ def __repr__(self):
145
+ """
146
+ DESCRIPTION:
147
+ Returns the string representation of _Row object.
148
+
149
+ PARAMETERS:
150
+ None
151
+
152
+ RETURNS:
153
+ tuple
154
+
155
+ EXAMPLES:
156
+ >>> row = Row(columns=['a', 'b', 'c'], values=['p', 'q', 'r'])
157
+ >>> print(row)
158
+ """
159
+ columns_values = ", ".join(("{}={}".format(col, repr(val)) for col, val in self.__data.items()))
160
+ return "Row({})".format(columns_values)
@@ -24,7 +24,7 @@ from teradatasqlalchemy.dialect import dialect as td_dialect, TeradataTypeCompil
24
24
  from teradatasqlalchemy import (GEOMETRY, MBR, MBB)
25
25
  from teradatasql import OperationalError
26
26
 
27
- from teradatasqlalchemy.telemetry.queryband import collect_queryband
27
+ from teradataml.telemetry_utils.queryband import collect_queryband
28
28
 
29
29
  module = importlib.import_module("teradataml")
30
30
 
@@ -963,7 +963,7 @@ def td_minus(df_list, allow_duplicates=True):
963
963
  awu_matrix = []
964
964
  awu_matrix.append(["df_list", df_list, False, (list)])
965
965
  awu_matrix.append(["allow_duplicates", allow_duplicates, False, (bool)])
966
- setop_type = 'td_except' if (inspect.stack()[2][3] and inspect.stack()[2][3] == 'td_except') else 'td_minus'
966
+ setop_type = 'td_except' if (inspect.stack()[3][3] and inspect.stack()[3][3] == 'td_except') else 'td_minus'
967
967
  operation = 'minus'
968
968
 
969
969
  # Validate Set operator arguments