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

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

Potentially problematic release.


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

Files changed (432) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/LICENSE.pdf +0 -0
  3. teradataml/README.md +238 -1
  4. teradataml/__init__.py +13 -3
  5. teradataml/_version.py +1 -1
  6. teradataml/analytics/Transformations.py +4 -4
  7. teradataml/analytics/__init__.py +0 -2
  8. teradataml/analytics/analytic_function_executor.py +3 -0
  9. teradataml/analytics/json_parser/utils.py +13 -12
  10. teradataml/analytics/sqle/DecisionTreePredict.py +15 -30
  11. teradataml/analytics/sqle/NaiveBayesPredict.py +11 -20
  12. teradataml/analytics/sqle/__init__.py +0 -13
  13. teradataml/analytics/utils.py +1 -0
  14. teradataml/analytics/valib.py +3 -0
  15. teradataml/automl/__init__.py +1628 -0
  16. teradataml/automl/custom_json_utils.py +1270 -0
  17. teradataml/automl/data_preparation.py +993 -0
  18. teradataml/automl/data_transformation.py +727 -0
  19. teradataml/automl/feature_engineering.py +1648 -0
  20. teradataml/automl/feature_exploration.py +547 -0
  21. teradataml/automl/model_evaluation.py +163 -0
  22. teradataml/automl/model_training.py +887 -0
  23. teradataml/catalog/__init__.py +0 -2
  24. teradataml/catalog/byom.py +49 -6
  25. teradataml/catalog/function_argument_mapper.py +0 -2
  26. teradataml/catalog/model_cataloging_utils.py +2 -1021
  27. teradataml/common/aed_utils.py +6 -2
  28. teradataml/common/constants.py +50 -58
  29. teradataml/common/deprecations.py +160 -0
  30. teradataml/common/garbagecollector.py +61 -104
  31. teradataml/common/messagecodes.py +27 -36
  32. teradataml/common/messages.py +11 -15
  33. teradataml/common/utils.py +205 -287
  34. teradataml/common/wrapper_utils.py +1 -110
  35. teradataml/context/context.py +150 -78
  36. teradataml/data/bank_churn.csv +10001 -0
  37. teradataml/data/bmi.csv +501 -0
  38. teradataml/data/docs/sqle/docs_17_10/BincodeFit.py +3 -3
  39. teradataml/data/docs/sqle/docs_17_10/BincodeTransform.py +6 -5
  40. teradataml/data/docs/sqle/docs_17_10/Fit.py +1 -1
  41. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +1 -1
  42. teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +1 -1
  43. teradataml/data/docs/sqle/docs_17_10/PolynomialFeaturesTransform.py +2 -2
  44. teradataml/data/docs/sqle/docs_17_10/RowNormalizeTransform.py +2 -1
  45. teradataml/data/docs/sqle/docs_17_10/ScaleTransform.py +1 -0
  46. teradataml/data/docs/sqle/docs_17_10/SimpleImputeTransform.py +1 -1
  47. teradataml/data/docs/sqle/docs_17_10/Transform.py +2 -1
  48. teradataml/data/docs/sqle/docs_17_20/BincodeFit.py +3 -3
  49. teradataml/data/docs/sqle/docs_17_20/BincodeTransform.py +6 -5
  50. teradataml/data/docs/sqle/docs_17_20/Fit.py +1 -1
  51. teradataml/data/docs/sqle/docs_17_20/GLM.py +1 -1
  52. teradataml/data/docs/sqle/docs_17_20/GLMPredictPerSegment.py +9 -10
  53. teradataml/data/docs/sqle/docs_17_20/KMeansPredict.py +3 -2
  54. teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierPredict.py +16 -15
  55. teradataml/data/docs/sqle/docs_17_20/NaiveBayesTextClassifierTrainer.py +2 -2
  56. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +2 -2
  57. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineTransform.py +8 -8
  58. teradataml/data/docs/sqle/docs_17_20/OneClassSVMPredict.py +21 -20
  59. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +1 -1
  60. teradataml/data/docs/sqle/docs_17_20/OutlierFilterTransform.py +8 -3
  61. teradataml/data/docs/sqle/docs_17_20/PolynomialFeaturesTransform.py +6 -5
  62. teradataml/data/docs/sqle/docs_17_20/RandomProjectionTransform.py +6 -6
  63. teradataml/data/docs/sqle/docs_17_20/RowNormalizeTransform.py +2 -1
  64. teradataml/data/docs/sqle/docs_17_20/SVM.py +1 -1
  65. teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +16 -16
  66. teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +1 -0
  67. teradataml/data/docs/sqle/docs_17_20/SimpleImputeTransform.py +3 -2
  68. teradataml/data/docs/sqle/docs_17_20/TDDecisionForestPredict.py +4 -4
  69. teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +19 -19
  70. teradataml/data/docs/sqle/docs_17_20/TargetEncodingTransform.py +5 -4
  71. teradataml/data/docs/sqle/docs_17_20/Transform.py +2 -2
  72. teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +9 -9
  73. teradataml/data/fish.csv +160 -0
  74. teradataml/data/glass_types.csv +215 -0
  75. teradataml/data/insurance.csv +1 -1
  76. teradataml/data/iris_data.csv +151 -0
  77. teradataml/data/jsons/sqle/17.10/TD_FunctionTransform.json +1 -0
  78. teradataml/data/jsons/sqle/17.10/TD_OneHotEncodingTransform.json +1 -0
  79. teradataml/data/jsons/sqle/17.10/TD_OutlierFilterTransform.json +1 -0
  80. teradataml/data/jsons/sqle/17.10/TD_PolynomialFeaturesTransform.json +1 -0
  81. teradataml/data/jsons/sqle/17.10/TD_RowNormalizeTransform.json +1 -0
  82. teradataml/data/jsons/sqle/17.10/TD_ScaleTransform.json +1 -0
  83. teradataml/data/jsons/sqle/17.10/TD_SimpleImputeTransform.json +1 -0
  84. teradataml/data/load_example_data.py +3 -0
  85. teradataml/data/multi_model_classification.csv +401 -0
  86. teradataml/data/multi_model_regression.csv +401 -0
  87. teradataml/data/openml_example.json +63 -0
  88. teradataml/data/scripts/deploy_script.py +65 -0
  89. teradataml/data/scripts/mapper.R +20 -0
  90. teradataml/data/scripts/sklearn/__init__.py +0 -0
  91. teradataml/data/scripts/sklearn/sklearn_fit.py +175 -0
  92. teradataml/data/scripts/sklearn/sklearn_fit_predict.py +135 -0
  93. teradataml/data/scripts/sklearn/sklearn_function.template +113 -0
  94. teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +158 -0
  95. teradataml/data/scripts/sklearn/sklearn_neighbors.py +152 -0
  96. teradataml/data/scripts/sklearn/sklearn_score.py +128 -0
  97. teradataml/data/scripts/sklearn/sklearn_transform.py +179 -0
  98. teradataml/data/templates/open_source_ml.json +9 -0
  99. teradataml/data/teradataml_example.json +73 -1
  100. teradataml/data/test_classification.csv +101 -0
  101. teradataml/data/test_prediction.csv +101 -0
  102. teradataml/data/test_regression.csv +101 -0
  103. teradataml/data/train_multiclass.csv +101 -0
  104. teradataml/data/train_regression.csv +101 -0
  105. teradataml/data/train_regression_multiple_labels.csv +101 -0
  106. teradataml/data/wine_data.csv +1600 -0
  107. teradataml/dataframe/copy_to.py +79 -13
  108. teradataml/dataframe/data_transfer.py +8 -0
  109. teradataml/dataframe/dataframe.py +910 -311
  110. teradataml/dataframe/dataframe_utils.py +102 -5
  111. teradataml/dataframe/fastload.py +11 -3
  112. teradataml/dataframe/setop.py +15 -2
  113. teradataml/dataframe/sql.py +3735 -77
  114. teradataml/dataframe/sql_function_parameters.py +56 -5
  115. teradataml/dataframe/vantage_function_types.py +45 -1
  116. teradataml/dataframe/window.py +30 -29
  117. teradataml/dbutils/dbutils.py +18 -1
  118. teradataml/geospatial/geodataframe.py +18 -7
  119. teradataml/geospatial/geodataframecolumn.py +5 -0
  120. teradataml/hyperparameter_tuner/optimizer.py +910 -120
  121. teradataml/hyperparameter_tuner/utils.py +131 -37
  122. teradataml/lib/aed_0_1.dll +0 -0
  123. teradataml/lib/libaed_0_1.dylib +0 -0
  124. teradataml/lib/libaed_0_1.so +0 -0
  125. teradataml/libaed_0_1.dylib +0 -0
  126. teradataml/libaed_0_1.so +0 -0
  127. teradataml/opensource/__init__.py +1 -0
  128. teradataml/opensource/sklearn/__init__.py +1 -0
  129. teradataml/opensource/sklearn/_class.py +255 -0
  130. teradataml/opensource/sklearn/_sklearn_wrapper.py +1668 -0
  131. teradataml/opensource/sklearn/_wrapper_utils.py +268 -0
  132. teradataml/opensource/sklearn/constants.py +54 -0
  133. teradataml/options/__init__.py +3 -6
  134. teradataml/options/configure.py +21 -20
  135. teradataml/scriptmgmt/UserEnv.py +61 -5
  136. teradataml/scriptmgmt/lls_utils.py +135 -53
  137. teradataml/table_operators/Apply.py +38 -6
  138. teradataml/table_operators/Script.py +45 -308
  139. teradataml/table_operators/TableOperator.py +182 -591
  140. teradataml/table_operators/__init__.py +0 -1
  141. teradataml/table_operators/table_operator_util.py +32 -40
  142. teradataml/utils/validators.py +127 -3
  143. {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/METADATA +243 -3
  144. {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/RECORD +147 -391
  145. teradataml/analytics/mle/AdaBoost.py +0 -651
  146. teradataml/analytics/mle/AdaBoostPredict.py +0 -564
  147. teradataml/analytics/mle/Antiselect.py +0 -342
  148. teradataml/analytics/mle/Arima.py +0 -641
  149. teradataml/analytics/mle/ArimaPredict.py +0 -477
  150. teradataml/analytics/mle/Attribution.py +0 -1070
  151. teradataml/analytics/mle/Betweenness.py +0 -658
  152. teradataml/analytics/mle/Burst.py +0 -711
  153. teradataml/analytics/mle/CCM.py +0 -600
  154. teradataml/analytics/mle/CCMPrepare.py +0 -324
  155. teradataml/analytics/mle/CFilter.py +0 -460
  156. teradataml/analytics/mle/ChangePointDetection.py +0 -572
  157. teradataml/analytics/mle/ChangePointDetectionRT.py +0 -477
  158. teradataml/analytics/mle/Closeness.py +0 -737
  159. teradataml/analytics/mle/ConfusionMatrix.py +0 -420
  160. teradataml/analytics/mle/Correlation.py +0 -477
  161. teradataml/analytics/mle/Correlation2.py +0 -573
  162. teradataml/analytics/mle/CoxHazardRatio.py +0 -679
  163. teradataml/analytics/mle/CoxPH.py +0 -556
  164. teradataml/analytics/mle/CoxSurvival.py +0 -478
  165. teradataml/analytics/mle/CumulativeMovAvg.py +0 -363
  166. teradataml/analytics/mle/DTW.py +0 -623
  167. teradataml/analytics/mle/DWT.py +0 -564
  168. teradataml/analytics/mle/DWT2D.py +0 -599
  169. teradataml/analytics/mle/DecisionForest.py +0 -716
  170. teradataml/analytics/mle/DecisionForestEvaluator.py +0 -363
  171. teradataml/analytics/mle/DecisionForestPredict.py +0 -561
  172. teradataml/analytics/mle/DecisionTree.py +0 -830
  173. teradataml/analytics/mle/DecisionTreePredict.py +0 -528
  174. teradataml/analytics/mle/ExponentialMovAvg.py +0 -418
  175. teradataml/analytics/mle/FMeasure.py +0 -402
  176. teradataml/analytics/mle/FPGrowth.py +0 -734
  177. teradataml/analytics/mle/FrequentPaths.py +0 -695
  178. teradataml/analytics/mle/GLM.py +0 -558
  179. teradataml/analytics/mle/GLML1L2.py +0 -547
  180. teradataml/analytics/mle/GLML1L2Predict.py +0 -519
  181. teradataml/analytics/mle/GLMPredict.py +0 -529
  182. teradataml/analytics/mle/HMMDecoder.py +0 -945
  183. teradataml/analytics/mle/HMMEvaluator.py +0 -901
  184. teradataml/analytics/mle/HMMSupervised.py +0 -521
  185. teradataml/analytics/mle/HMMUnsupervised.py +0 -572
  186. teradataml/analytics/mle/Histogram.py +0 -561
  187. teradataml/analytics/mle/IDWT.py +0 -476
  188. teradataml/analytics/mle/IDWT2D.py +0 -493
  189. teradataml/analytics/mle/IdentityMatch.py +0 -763
  190. teradataml/analytics/mle/Interpolator.py +0 -918
  191. teradataml/analytics/mle/KMeans.py +0 -485
  192. teradataml/analytics/mle/KNN.py +0 -627
  193. teradataml/analytics/mle/KNNRecommender.py +0 -488
  194. teradataml/analytics/mle/KNNRecommenderPredict.py +0 -581
  195. teradataml/analytics/mle/LAR.py +0 -439
  196. teradataml/analytics/mle/LARPredict.py +0 -478
  197. teradataml/analytics/mle/LDA.py +0 -548
  198. teradataml/analytics/mle/LDAInference.py +0 -492
  199. teradataml/analytics/mle/LDATopicSummary.py +0 -464
  200. teradataml/analytics/mle/LevenshteinDistance.py +0 -450
  201. teradataml/analytics/mle/LinReg.py +0 -433
  202. teradataml/analytics/mle/LinRegPredict.py +0 -438
  203. teradataml/analytics/mle/MinHash.py +0 -544
  204. teradataml/analytics/mle/Modularity.py +0 -587
  205. teradataml/analytics/mle/NEREvaluator.py +0 -410
  206. teradataml/analytics/mle/NERExtractor.py +0 -595
  207. teradataml/analytics/mle/NERTrainer.py +0 -458
  208. teradataml/analytics/mle/NGrams.py +0 -570
  209. teradataml/analytics/mle/NPath.py +0 -634
  210. teradataml/analytics/mle/NTree.py +0 -549
  211. teradataml/analytics/mle/NaiveBayes.py +0 -462
  212. teradataml/analytics/mle/NaiveBayesPredict.py +0 -513
  213. teradataml/analytics/mle/NaiveBayesTextClassifier.py +0 -607
  214. teradataml/analytics/mle/NaiveBayesTextClassifier2.py +0 -531
  215. teradataml/analytics/mle/NaiveBayesTextClassifierPredict.py +0 -799
  216. teradataml/analytics/mle/NamedEntityFinder.py +0 -529
  217. teradataml/analytics/mle/NamedEntityFinderEvaluator.py +0 -414
  218. teradataml/analytics/mle/NamedEntityFinderTrainer.py +0 -396
  219. teradataml/analytics/mle/POSTagger.py +0 -417
  220. teradataml/analytics/mle/Pack.py +0 -411
  221. teradataml/analytics/mle/PageRank.py +0 -535
  222. teradataml/analytics/mle/PathAnalyzer.py +0 -426
  223. teradataml/analytics/mle/PathGenerator.py +0 -367
  224. teradataml/analytics/mle/PathStart.py +0 -464
  225. teradataml/analytics/mle/PathSummarizer.py +0 -470
  226. teradataml/analytics/mle/Pivot.py +0 -471
  227. teradataml/analytics/mle/ROC.py +0 -425
  228. teradataml/analytics/mle/RandomSample.py +0 -637
  229. teradataml/analytics/mle/RandomWalkSample.py +0 -490
  230. teradataml/analytics/mle/SAX.py +0 -779
  231. teradataml/analytics/mle/SVMDense.py +0 -677
  232. teradataml/analytics/mle/SVMDensePredict.py +0 -536
  233. teradataml/analytics/mle/SVMDenseSummary.py +0 -437
  234. teradataml/analytics/mle/SVMSparse.py +0 -557
  235. teradataml/analytics/mle/SVMSparsePredict.py +0 -553
  236. teradataml/analytics/mle/SVMSparseSummary.py +0 -435
  237. teradataml/analytics/mle/Sampling.py +0 -549
  238. teradataml/analytics/mle/Scale.py +0 -565
  239. teradataml/analytics/mle/ScaleByPartition.py +0 -496
  240. teradataml/analytics/mle/ScaleMap.py +0 -378
  241. teradataml/analytics/mle/ScaleSummary.py +0 -320
  242. teradataml/analytics/mle/SentenceExtractor.py +0 -363
  243. teradataml/analytics/mle/SentimentEvaluator.py +0 -432
  244. teradataml/analytics/mle/SentimentExtractor.py +0 -578
  245. teradataml/analytics/mle/SentimentTrainer.py +0 -405
  246. teradataml/analytics/mle/SeriesSplitter.py +0 -641
  247. teradataml/analytics/mle/Sessionize.py +0 -475
  248. teradataml/analytics/mle/SimpleMovAvg.py +0 -397
  249. teradataml/analytics/mle/StringSimilarity.py +0 -425
  250. teradataml/analytics/mle/TF.py +0 -389
  251. teradataml/analytics/mle/TFIDF.py +0 -504
  252. teradataml/analytics/mle/TextChunker.py +0 -414
  253. teradataml/analytics/mle/TextClassifier.py +0 -399
  254. teradataml/analytics/mle/TextClassifierEvaluator.py +0 -413
  255. teradataml/analytics/mle/TextClassifierTrainer.py +0 -565
  256. teradataml/analytics/mle/TextMorph.py +0 -494
  257. teradataml/analytics/mle/TextParser.py +0 -623
  258. teradataml/analytics/mle/TextTagger.py +0 -530
  259. teradataml/analytics/mle/TextTokenizer.py +0 -502
  260. teradataml/analytics/mle/UnivariateStatistics.py +0 -488
  261. teradataml/analytics/mle/Unpack.py +0 -526
  262. teradataml/analytics/mle/Unpivot.py +0 -438
  263. teradataml/analytics/mle/VarMax.py +0 -776
  264. teradataml/analytics/mle/VectorDistance.py +0 -762
  265. teradataml/analytics/mle/WeightedMovAvg.py +0 -400
  266. teradataml/analytics/mle/XGBoost.py +0 -842
  267. teradataml/analytics/mle/XGBoostPredict.py +0 -627
  268. teradataml/analytics/mle/__init__.py +0 -123
  269. teradataml/analytics/mle/json/adaboost_mle.json +0 -135
  270. teradataml/analytics/mle/json/adaboostpredict_mle.json +0 -85
  271. teradataml/analytics/mle/json/antiselect_mle.json +0 -34
  272. teradataml/analytics/mle/json/antiselect_mle_mle.json +0 -34
  273. teradataml/analytics/mle/json/arima_mle.json +0 -172
  274. teradataml/analytics/mle/json/arimapredict_mle.json +0 -52
  275. teradataml/analytics/mle/json/attribution_mle_mle.json +0 -143
  276. teradataml/analytics/mle/json/betweenness_mle.json +0 -97
  277. teradataml/analytics/mle/json/burst_mle.json +0 -140
  278. teradataml/analytics/mle/json/ccm_mle.json +0 -124
  279. teradataml/analytics/mle/json/ccmprepare_mle.json +0 -14
  280. teradataml/analytics/mle/json/cfilter_mle.json +0 -93
  281. teradataml/analytics/mle/json/changepointdetection_mle.json +0 -92
  282. teradataml/analytics/mle/json/changepointdetectionrt_mle.json +0 -78
  283. teradataml/analytics/mle/json/closeness_mle.json +0 -104
  284. teradataml/analytics/mle/json/confusionmatrix_mle.json +0 -79
  285. teradataml/analytics/mle/json/correlation_mle.json +0 -86
  286. teradataml/analytics/mle/json/correlationreduce_mle.json +0 -49
  287. teradataml/analytics/mle/json/coxhazardratio_mle.json +0 -89
  288. teradataml/analytics/mle/json/coxph_mle.json +0 -98
  289. teradataml/analytics/mle/json/coxsurvival_mle.json +0 -79
  290. teradataml/analytics/mle/json/cumulativemovavg_mle.json +0 -34
  291. teradataml/analytics/mle/json/decisionforest_mle.json +0 -167
  292. teradataml/analytics/mle/json/decisionforestevaluator_mle.json +0 -33
  293. teradataml/analytics/mle/json/decisionforestpredict_mle_mle.json +0 -74
  294. teradataml/analytics/mle/json/decisiontree_mle.json +0 -194
  295. teradataml/analytics/mle/json/decisiontreepredict_mle_mle.json +0 -86
  296. teradataml/analytics/mle/json/dtw_mle.json +0 -97
  297. teradataml/analytics/mle/json/dwt2d_mle.json +0 -116
  298. teradataml/analytics/mle/json/dwt_mle.json +0 -101
  299. teradataml/analytics/mle/json/exponentialmovavg_mle.json +0 -55
  300. teradataml/analytics/mle/json/fmeasure_mle.json +0 -58
  301. teradataml/analytics/mle/json/fpgrowth_mle.json +0 -159
  302. teradataml/analytics/mle/json/frequentpaths_mle.json +0 -129
  303. teradataml/analytics/mle/json/glm_mle.json +0 -111
  304. teradataml/analytics/mle/json/glml1l2_mle.json +0 -106
  305. teradataml/analytics/mle/json/glml1l2predict_mle.json +0 -57
  306. teradataml/analytics/mle/json/glmpredict_mle_mle.json +0 -74
  307. teradataml/analytics/mle/json/histogram_mle.json +0 -100
  308. teradataml/analytics/mle/json/hmmdecoder_mle.json +0 -192
  309. teradataml/analytics/mle/json/hmmevaluator_mle.json +0 -206
  310. teradataml/analytics/mle/json/hmmsupervised_mle.json +0 -91
  311. teradataml/analytics/mle/json/hmmunsupervised_mle.json +0 -114
  312. teradataml/analytics/mle/json/identitymatch_mle.json +0 -88
  313. teradataml/analytics/mle/json/idwt2d_mle.json +0 -73
  314. teradataml/analytics/mle/json/idwt_mle.json +0 -66
  315. teradataml/analytics/mle/json/interpolator_mle.json +0 -151
  316. teradataml/analytics/mle/json/kmeans_mle.json +0 -97
  317. teradataml/analytics/mle/json/knn_mle.json +0 -141
  318. teradataml/analytics/mle/json/knnrecommender_mle.json +0 -111
  319. teradataml/analytics/mle/json/knnrecommenderpredict_mle.json +0 -75
  320. teradataml/analytics/mle/json/lar_mle.json +0 -78
  321. teradataml/analytics/mle/json/larpredict_mle.json +0 -69
  322. teradataml/analytics/mle/json/lda_mle.json +0 -130
  323. teradataml/analytics/mle/json/ldainference_mle.json +0 -78
  324. teradataml/analytics/mle/json/ldatopicsummary_mle.json +0 -64
  325. teradataml/analytics/mle/json/levenshteindistance_mle.json +0 -92
  326. teradataml/analytics/mle/json/linreg_mle.json +0 -42
  327. teradataml/analytics/mle/json/linregpredict_mle.json +0 -56
  328. teradataml/analytics/mle/json/minhash_mle.json +0 -113
  329. teradataml/analytics/mle/json/modularity_mle.json +0 -91
  330. teradataml/analytics/mle/json/naivebayespredict_mle_mle.json +0 -85
  331. teradataml/analytics/mle/json/naivebayesreduce_mle.json +0 -52
  332. teradataml/analytics/mle/json/naivebayestextclassifierpredict_mle_mle.json +0 -147
  333. teradataml/analytics/mle/json/naivebayestextclassifiertrainer2_mle.json +0 -108
  334. teradataml/analytics/mle/json/naivebayestextclassifiertrainer_mle.json +0 -102
  335. teradataml/analytics/mle/json/namedentityfinder_mle.json +0 -84
  336. teradataml/analytics/mle/json/namedentityfinderevaluatorreduce_mle.json +0 -43
  337. teradataml/analytics/mle/json/namedentityfindertrainer_mle.json +0 -64
  338. teradataml/analytics/mle/json/nerevaluator_mle.json +0 -54
  339. teradataml/analytics/mle/json/nerextractor_mle.json +0 -87
  340. teradataml/analytics/mle/json/nertrainer_mle.json +0 -89
  341. teradataml/analytics/mle/json/ngrams_mle.json +0 -137
  342. teradataml/analytics/mle/json/ngramsplitter_mle_mle.json +0 -137
  343. teradataml/analytics/mle/json/npath@coprocessor_mle.json +0 -73
  344. teradataml/analytics/mle/json/ntree@coprocessor_mle.json +0 -123
  345. teradataml/analytics/mle/json/pack_mle.json +0 -58
  346. teradataml/analytics/mle/json/pack_mle_mle.json +0 -58
  347. teradataml/analytics/mle/json/pagerank_mle.json +0 -81
  348. teradataml/analytics/mle/json/pathanalyzer_mle.json +0 -63
  349. teradataml/analytics/mle/json/pathgenerator_mle.json +0 -40
  350. teradataml/analytics/mle/json/pathstart_mle.json +0 -62
  351. teradataml/analytics/mle/json/pathsummarizer_mle.json +0 -72
  352. teradataml/analytics/mle/json/pivoting_mle.json +0 -71
  353. teradataml/analytics/mle/json/postagger_mle.json +0 -51
  354. teradataml/analytics/mle/json/randomsample_mle.json +0 -131
  355. teradataml/analytics/mle/json/randomwalksample_mle.json +0 -85
  356. teradataml/analytics/mle/json/roc_mle.json +0 -73
  357. teradataml/analytics/mle/json/sampling_mle.json +0 -75
  358. teradataml/analytics/mle/json/sax_mle.json +0 -154
  359. teradataml/analytics/mle/json/scale_mle.json +0 -93
  360. teradataml/analytics/mle/json/scalebypartition_mle.json +0 -89
  361. teradataml/analytics/mle/json/scalemap_mle.json +0 -44
  362. teradataml/analytics/mle/json/scalesummary_mle.json +0 -14
  363. teradataml/analytics/mle/json/sentenceextractor_mle.json +0 -41
  364. teradataml/analytics/mle/json/sentimentevaluator_mle.json +0 -43
  365. teradataml/analytics/mle/json/sentimentextractor_mle.json +0 -100
  366. teradataml/analytics/mle/json/sentimenttrainer_mle.json +0 -68
  367. teradataml/analytics/mle/json/seriessplitter_mle.json +0 -133
  368. teradataml/analytics/mle/json/sessionize_mle_mle.json +0 -62
  369. teradataml/analytics/mle/json/simplemovavg_mle.json +0 -48
  370. teradataml/analytics/mle/json/stringsimilarity_mle.json +0 -50
  371. teradataml/analytics/mle/json/stringsimilarity_mle_mle.json +0 -50
  372. teradataml/analytics/mle/json/svmdense_mle.json +0 -165
  373. teradataml/analytics/mle/json/svmdensepredict_mle.json +0 -95
  374. teradataml/analytics/mle/json/svmdensesummary_mle.json +0 -58
  375. teradataml/analytics/mle/json/svmsparse_mle.json +0 -148
  376. teradataml/analytics/mle/json/svmsparsepredict_mle_mle.json +0 -103
  377. teradataml/analytics/mle/json/svmsparsesummary_mle.json +0 -57
  378. teradataml/analytics/mle/json/textchunker_mle.json +0 -40
  379. teradataml/analytics/mle/json/textclassifier_mle.json +0 -51
  380. teradataml/analytics/mle/json/textclassifierevaluator_mle.json +0 -43
  381. teradataml/analytics/mle/json/textclassifiertrainer_mle.json +0 -103
  382. teradataml/analytics/mle/json/textmorph_mle.json +0 -63
  383. teradataml/analytics/mle/json/textparser_mle.json +0 -166
  384. teradataml/analytics/mle/json/texttagger_mle.json +0 -81
  385. teradataml/analytics/mle/json/texttokenizer_mle.json +0 -91
  386. teradataml/analytics/mle/json/tf_mle.json +0 -33
  387. teradataml/analytics/mle/json/tfidf_mle.json +0 -34
  388. teradataml/analytics/mle/json/univariatestatistics_mle.json +0 -81
  389. teradataml/analytics/mle/json/unpack_mle.json +0 -91
  390. teradataml/analytics/mle/json/unpack_mle_mle.json +0 -91
  391. teradataml/analytics/mle/json/unpivoting_mle.json +0 -63
  392. teradataml/analytics/mle/json/varmax_mle.json +0 -176
  393. teradataml/analytics/mle/json/vectordistance_mle.json +0 -179
  394. teradataml/analytics/mle/json/weightedmovavg_mle.json +0 -48
  395. teradataml/analytics/mle/json/xgboost_mle.json +0 -178
  396. teradataml/analytics/mle/json/xgboostpredict_mle.json +0 -104
  397. teradataml/analytics/sqle/Antiselect.py +0 -321
  398. teradataml/analytics/sqle/Attribution.py +0 -603
  399. teradataml/analytics/sqle/DecisionForestPredict.py +0 -408
  400. teradataml/analytics/sqle/GLMPredict.py +0 -430
  401. teradataml/analytics/sqle/MovingAverage.py +0 -543
  402. teradataml/analytics/sqle/NGramSplitter.py +0 -548
  403. teradataml/analytics/sqle/NPath.py +0 -632
  404. teradataml/analytics/sqle/NaiveBayesTextClassifierPredict.py +0 -515
  405. teradataml/analytics/sqle/Pack.py +0 -388
  406. teradataml/analytics/sqle/SVMSparsePredict.py +0 -464
  407. teradataml/analytics/sqle/Sessionize.py +0 -390
  408. teradataml/analytics/sqle/StringSimilarity.py +0 -400
  409. teradataml/analytics/sqle/Unpack.py +0 -503
  410. teradataml/analytics/sqle/json/antiselect_sqle.json +0 -21
  411. teradataml/analytics/sqle/json/attribution_sqle.json +0 -92
  412. teradataml/analytics/sqle/json/decisionforestpredict_sqle.json +0 -48
  413. teradataml/analytics/sqle/json/glmpredict_sqle.json +0 -48
  414. teradataml/analytics/sqle/json/h2opredict_sqle.json +0 -63
  415. teradataml/analytics/sqle/json/movingaverage_sqle.json +0 -58
  416. teradataml/analytics/sqle/json/naivebayestextclassifierpredict_sqle.json +0 -76
  417. teradataml/analytics/sqle/json/ngramsplitter_sqle.json +0 -126
  418. teradataml/analytics/sqle/json/npath_sqle.json +0 -67
  419. teradataml/analytics/sqle/json/pack_sqle.json +0 -47
  420. teradataml/analytics/sqle/json/pmmlpredict_sqle.json +0 -55
  421. teradataml/analytics/sqle/json/sessionize_sqle.json +0 -43
  422. teradataml/analytics/sqle/json/stringsimilarity_sqle.json +0 -39
  423. teradataml/analytics/sqle/json/svmsparsepredict_sqle.json +0 -74
  424. teradataml/analytics/sqle/json/unpack_sqle.json +0 -80
  425. teradataml/catalog/model_cataloging.py +0 -980
  426. teradataml/config/mlengine_alias_definitions_v1.0 +0 -118
  427. teradataml/config/mlengine_alias_definitions_v1.1 +0 -127
  428. teradataml/config/mlengine_alias_definitions_v1.3 +0 -129
  429. teradataml/table_operators/sandbox_container_util.py +0 -643
  430. {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/WHEEL +0 -0
  431. {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/top_level.txt +0 -0
  432. {teradataml-17.20.0.6.dist-info → teradataml-20.0.0.0.dist-info}/zip-safe +0 -0
@@ -52,6 +52,7 @@ from teradatasqlalchemy import (INTERVAL_DAY, INTERVAL_DAY_TO_HOUR, INTERVAL_DAY
52
52
  INTERVAL_YEAR_TO_MONTH)
53
53
  from teradatasqlalchemy import (PERIOD_DATE, PERIOD_TIME, PERIOD_TIMESTAMP)
54
54
  from teradatasqlalchemy import XML, GEOMETRY
55
+ from teradatasqlalchemy.telemetry.queryband import collect_queryband
55
56
  import decimal
56
57
  import datetime as dt
57
58
  from teradataml.dataframe.window import Window
@@ -1586,7 +1587,7 @@ class _ArithmeticColumnExpression(ColumnExpression):
1586
1587
  2 67/06/30 07/07/10 421.0 465.0 179.0
1587
1588
  3 67/06/30 07/07/10 434.0 485.0 185.0
1588
1589
  5 67/06/30 07/07/10 459.0 509.0 211.0
1589
-
1590
+
1590
1591
  # Example 1: Add 100 to the expenditure amount and assign the final amount
1591
1592
  # to new column 'total_expenditure'.
1592
1593
  >>> df.assign(total_expenditure=df.expenditure + 100)
@@ -2028,7 +2029,7 @@ class _ArithmeticColumnExpression(ColumnExpression):
2028
2029
  # Example 1: Divide the income by 2 and assign the divided income
2029
2030
  # to new column 'divided_income'.
2030
2031
  >>> df.assign(divided_income=c1 // 2)
2031
-
2032
+
2032
2033
  # Example 2: Calculate the percent of investment of income and assign the
2033
2034
  # final output to new column 'percent_inverstment_'.
2034
2035
  >>> df.assign(percent_inverstment_=df.investment * 100 // df.income)
@@ -2215,6 +2216,7 @@ class _StringMethods(object):
2215
2216
  """
2216
2217
  self.c = c
2217
2218
 
2219
+ @collect_queryband(queryband="DFC_lower")
2218
2220
  def lower(self):
2219
2221
  """
2220
2222
  Convert character column values to lowercase.
@@ -2261,18 +2263,20 @@ class _StringMethods(object):
2261
2263
  )
2262
2264
  return res
2263
2265
 
2266
+ @collect_queryband(queryband="DFC_contains")
2264
2267
  def contains(self, pattern, case = True, na = None, **kw):
2265
2268
  """
2266
- Search the pattern or substring in a given string.
2267
- REFERENCE:
2268
- SQL Functions, Operators, Expressions, and Predicates
2269
- Chapter 24: Regular Expression Functions
2269
+ Search the pattern or substring in the column.
2270
2270
 
2271
2271
  PARAMETERS:
2272
2272
  pattern:
2273
2273
  Required Argument.
2274
- Specifies a regex pattern
2275
- Types: str
2274
+ Specifies a literal value or ColumnExpression. Use ColumnExpression
2275
+ when comparison is done based on values inside ColumnExpression or
2276
+ based on a ColumnExpression function. Else, use literal value.
2277
+ Note:
2278
+ Argument supports regular expressions too.
2279
+ Types: str OR ColumnExpression
2276
2280
 
2277
2281
  case:
2278
2282
  Optional Argument.
@@ -2354,7 +2358,7 @@ class _StringMethods(object):
2354
2358
  7 'rejoicing' 0
2355
2359
  8 'comforting' 0
2356
2360
  9 'obstinate' 0
2357
-
2361
+
2358
2362
  >>> load_example_data("dataframe", "sales")
2359
2363
  >>> df = DataFrame("sales")
2360
2364
  >>> df
@@ -2402,8 +2406,25 @@ class _StringMethods(object):
2402
2406
  Jones LLC 200.0 150 140 180 04/01/2017
2403
2407
  Alpha Co 210.0 200 215 250 04/01/2017
2404
2408
 
2409
+ >>> load_example_data("ntree", "employee_table")
2410
+ >>> df = DataFrame("employee_table")
2411
+ >>> df
2412
+ emp_name mgr_id mgr_name
2413
+ emp_id
2414
+ 200 Pat 100.0 Don
2415
+ 300 Donna 100.0 Don
2416
+ 400 Kim 200.0 Pat
2417
+ 500 Fred 400.0 Kim
2418
+ 100 Don NaN NA
2419
+
2420
+ # Example 7: Get all the employees whose name has managers name.
2421
+ >>> df[df.emp_name.str.contains(df.mgr_name) == True]
2422
+ >>> df
2423
+ emp_name mgr_id mgr_name
2424
+ emp_id
2425
+ 300 Donna 100 Don
2405
2426
  """
2406
- if not isinstance(pattern, str):
2427
+ if not isinstance(pattern, (str, ColumnExpression)):
2407
2428
  raise TypeError('str.contains requires the pattern parameter to be a string.')
2408
2429
 
2409
2430
  if not isinstance(case, bool):
@@ -2412,9 +2433,9 @@ class _StringMethods(object):
2412
2433
  match_arg = kw.get('match_arg', 'c' if case else 'i')
2413
2434
  regexp_substr = func.regexp_substr(
2414
2435
  self.c.expression,
2415
- pattern, 1, 1,
2436
+ pattern.expression if isinstance(pattern, ColumnExpression) else pattern, 1, 1,
2416
2437
  match_arg)
2417
-
2438
+
2418
2439
  expr = case_when((regexp_substr == None, 0), else_ = 1)
2419
2440
  expr = case_when((self.c.expression == None, na), else_ = expr)
2420
2441
 
@@ -2430,6 +2451,7 @@ class _StringMethods(object):
2430
2451
 
2431
2452
  return _SQLColumnExpression(expr)
2432
2453
 
2454
+ @collect_queryband(queryband="DFC_strip")
2433
2455
  def strip(self):
2434
2456
  """
2435
2457
  Remove leading and trailing whitespace.
@@ -2540,6 +2562,7 @@ class _SeriesColumnExpression(ColumnExpression):
2540
2562
 
2541
2563
  # otherwise, just ignore
2542
2564
 
2565
+ @collect_queryband(queryband="DFC_gt")
2543
2566
  def gt(self, other):
2544
2567
  """
2545
2568
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2610,6 +2633,7 @@ class _SeriesColumnExpression(ColumnExpression):
2610
2633
  """
2611
2634
  return self > other
2612
2635
 
2636
+ @collect_queryband(queryband="DFC_ge")
2613
2637
  def ge(self, other):
2614
2638
  """
2615
2639
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2677,6 +2701,7 @@ class _SeriesColumnExpression(ColumnExpression):
2677
2701
  """
2678
2702
  return self >= other
2679
2703
 
2704
+ @collect_queryband(queryband="DFC_lt")
2680
2705
  def lt(self, other):
2681
2706
  """
2682
2707
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2743,6 +2768,7 @@ class _SeriesColumnExpression(ColumnExpression):
2743
2768
  """
2744
2769
  return self < other
2745
2770
 
2771
+ @collect_queryband(queryband="DFC_le")
2746
2772
  def le(self, other):
2747
2773
  """
2748
2774
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2806,6 +2832,7 @@ class _SeriesColumnExpression(ColumnExpression):
2806
2832
  """
2807
2833
  return self <= other
2808
2834
 
2835
+ @collect_queryband(queryband="DFC_eq")
2809
2836
  def eq(self, other):
2810
2837
  """
2811
2838
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2870,6 +2897,7 @@ class _SeriesColumnExpression(ColumnExpression):
2870
2897
  """
2871
2898
  return self == other
2872
2899
 
2900
+ @collect_queryband(queryband="DFC_ne")
2873
2901
  def ne(self, other):
2874
2902
  """
2875
2903
  Compare the ColumnExpressions to check if one ColumnExpression
@@ -2940,6 +2968,7 @@ class _SeriesColumnExpression(ColumnExpression):
2940
2968
  """
2941
2969
  return self != other
2942
2970
 
2971
+ @collect_queryband(queryband="DFC_add")
2943
2972
  def add(self, other):
2944
2973
  """
2945
2974
  Compute the addition between two ColumnExpressions.
@@ -2983,6 +3012,7 @@ class _SeriesColumnExpression(ColumnExpression):
2983
3012
  4 67/06/30 07/07/10 448.0 493.0 192.0 """
2984
3013
  return self + other
2985
3014
 
3015
+ @collect_queryband(queryband="DFC_sub")
2986
3016
  def sub(self, other):
2987
3017
  """
2988
3018
  Compute the subtraction between two ColumnExpressions.
@@ -3027,6 +3057,7 @@ class _SeriesColumnExpression(ColumnExpression):
3027
3057
  """
3028
3058
  return self - other
3029
3059
 
3060
+ @collect_queryband(queryband="DFC_mul")
3030
3061
  def mul(self, other):
3031
3062
  """
3032
3063
  Compute the multiplication between two ColumnExpressions.
@@ -3107,6 +3138,7 @@ class _SeriesColumnExpression(ColumnExpression):
3107
3138
  """
3108
3139
  return self * other
3109
3140
 
3141
+ @collect_queryband(queryband="DFC_div")
3110
3142
  def div(self, other):
3111
3143
  """
3112
3144
  Compute the division between two ColumnExpressions.
@@ -3152,6 +3184,7 @@ class _SeriesColumnExpression(ColumnExpression):
3152
3184
  """
3153
3185
  return self.truediv(other)
3154
3186
 
3187
+ @collect_queryband(queryband="DFC_truediv")
3155
3188
  def truediv(self, other):
3156
3189
  """
3157
3190
  Compute the true-division between two ColumnExpressions.
@@ -3197,6 +3230,7 @@ class _SeriesColumnExpression(ColumnExpression):
3197
3230
  """
3198
3231
  return self / other
3199
3232
 
3233
+ @collect_queryband(queryband="DFC_floordiv")
3200
3234
  def floordiv(self, other):
3201
3235
  """
3202
3236
  Compute the floor-division between two ColumnExpressions.
@@ -3242,6 +3276,7 @@ class _SeriesColumnExpression(ColumnExpression):
3242
3276
  """
3243
3277
  return self // other
3244
3278
 
3279
+ @collect_queryband(queryband="DFC_mod")
3245
3280
  def mod(self, other):
3246
3281
  """
3247
3282
  Compute the mod between two ColumnExpressions.
@@ -3290,6 +3325,7 @@ class _SeriesColumnExpression(ColumnExpression):
3290
3325
  """
3291
3326
  return self % other
3292
3327
 
3328
+ @collect_queryband(queryband="DFC_isna")
3293
3329
  def isna(self):
3294
3330
  """
3295
3331
  Test for NA values
@@ -3360,6 +3396,7 @@ class _SeriesColumnExpression(ColumnExpression):
3360
3396
  )
3361
3397
  return res
3362
3398
 
3399
+ @collect_queryband(queryband="DFC_isnull")
3363
3400
  def isnull(self):
3364
3401
  """
3365
3402
  Test for NA values. Alias for isna()
@@ -3423,6 +3460,7 @@ class _SeriesColumnExpression(ColumnExpression):
3423
3460
  """
3424
3461
  return self.isna()
3425
3462
 
3463
+ @collect_queryband(queryband="DFC_notna")
3426
3464
  def notna(self):
3427
3465
  """
3428
3466
  Test for non NA values
@@ -3506,6 +3544,7 @@ class _SeriesColumnExpression(ColumnExpression):
3506
3544
 
3507
3545
  return res
3508
3546
 
3547
+ @collect_queryband(queryband="DFC_notnull")
3509
3548
  def notnull(self):
3510
3549
  """
3511
3550
  Alias for notna().Test for non NA values
@@ -3618,6 +3657,7 @@ class _SeriesColumnExpression(ColumnExpression):
3618
3657
 
3619
3658
  return res
3620
3659
 
3660
+ @collect_queryband(queryband="DFC_isin")
3621
3661
  def isin(self, values=None):
3622
3662
  """
3623
3663
  Function to check for the presence of values in a column.
@@ -3909,6 +3949,7 @@ class _AggregateColumnExpresion(ColumnExpression):
3909
3949
  columnExpression = columnExpression.cast(NUMBER())
3910
3950
  return columnExpression
3911
3951
 
3952
+ @collect_queryband(arg_name="python_func_name", prefix="DFC")
3912
3953
  def __process_column_expression(self, func_name, *args, **kwargs):
3913
3954
  """
3914
3955
  Description:
@@ -4038,6 +4079,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4038
4079
  return lambda *args, **kwargs:\
4039
4080
  self.__process_column_expression(sql_func_name, *args, python_func_name=func_name, **kwargs)
4040
4081
 
4082
+ @collect_queryband(queryband="DFC_count")
4041
4083
  def count(self, distinct=False, skipna=False, **kwargs):
4042
4084
  """
4043
4085
  DESCRIPTION:
@@ -4123,6 +4165,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4123
4165
  """
4124
4166
  return self.__generate_function_call_object(func.count, distinct=distinct, skipna=skipna, **kwargs)
4125
4167
 
4168
+ @collect_queryband(queryband="DFC_kurtosis")
4126
4169
  def kurtosis(self, distinct=False, **kwargs):
4127
4170
  """
4128
4171
  DESCRIPTION:
@@ -4211,6 +4254,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4211
4254
  """
4212
4255
  return self.__generate_function_call_object(func.kurtosis, distinct=distinct, **kwargs)
4213
4256
 
4257
+ @collect_queryband(queryband="DFC_first")
4214
4258
  def first(self, **kwargs):
4215
4259
  """
4216
4260
  DESCRIPTION:
@@ -4244,6 +4288,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4244
4288
  """
4245
4289
  return self.__generate_function_call_object(func.first)
4246
4290
 
4291
+ @collect_queryband(queryband="DFC_last")
4247
4292
  def last(self, **kwargs):
4248
4293
  """
4249
4294
  DESCRIPTION:
@@ -4277,6 +4322,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4277
4322
  """
4278
4323
  return self.__generate_function_call_object(func.last)
4279
4324
 
4325
+ @collect_queryband(queryband="DFC_mad")
4280
4326
  def mad(self, constant_multiplier=None, **kwargs):
4281
4327
  """
4282
4328
  DESCRIPTION:
@@ -4352,6 +4398,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4352
4398
  func_obj = func.mad(self.expression)
4353
4399
  return self.__process_function_call_object(func_obj)
4354
4400
 
4401
+ @collect_queryband(queryband="DFC_max")
4355
4402
  def max(self, distinct=False, **kwargs):
4356
4403
  """
4357
4404
  DESCRIPTION:
@@ -4431,6 +4478,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4431
4478
  """
4432
4479
  return self.__generate_function_call_object(func.max, distinct=distinct, **kwargs)
4433
4480
 
4481
+ @collect_queryband(queryband="DFC_mean")
4434
4482
  def mean(self, distinct=False, **kwargs):
4435
4483
  """
4436
4484
  DESCRIPTION:
@@ -4514,6 +4562,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4514
4562
 
4515
4563
  return self.__generate_function_call_object(func.avg, distinct=distinct, **kwargs)
4516
4564
 
4565
+ @collect_queryband(queryband="DFC_median")
4517
4566
  def median(self, distinct=False, **kwargs):
4518
4567
  """
4519
4568
  DESCRIPTION:
@@ -4600,6 +4649,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4600
4649
  """
4601
4650
  return self.__generate_function_call_object(func.median, distinct=distinct, **kwargs)
4602
4651
 
4652
+ @collect_queryband(queryband="DFC_min")
4603
4653
  def min(self, distinct=False, **kwargs):
4604
4654
  """
4605
4655
  DESCRIPTION:
@@ -4678,6 +4728,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4678
4728
  """
4679
4729
  return self.__generate_function_call_object(func.min, distinct=distinct, **kwargs)
4680
4730
 
4731
+ @collect_queryband(queryband="DFC_mode")
4681
4732
  def mode(self, **kwargs):
4682
4733
  """
4683
4734
  DESCRIPTION:
@@ -4711,6 +4762,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4711
4762
  """
4712
4763
  return self.__generate_function_call_object(func.mode)
4713
4764
 
4765
+ @collect_queryband(queryband="DFC_percentile")
4714
4766
  def percentile(self, percentile, distinct=False, interpolation="LINEAR",
4715
4767
  as_time_series_aggregate=False, **kwargs):
4716
4768
  """
@@ -4891,6 +4943,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4891
4943
  return self.__generate_function_call_object(
4892
4944
  func.percentile, percentile*100, text(interpolation), distinct=distinct)
4893
4945
 
4946
+ @collect_queryband(queryband="DFC_skew")
4894
4947
  def skew(self, distinct=False, **kwargs):
4895
4948
  """
4896
4949
  DESCRIPTION:
@@ -4970,6 +5023,7 @@ class _AggregateColumnExpresion(ColumnExpression):
4970
5023
  """
4971
5024
  return self.__generate_function_call_object(func.skew, distinct=distinct, **kwargs)
4972
5025
 
5026
+ @collect_queryband(queryband="DFC_sum")
4973
5027
  def sum(self, distinct=False, **kwargs):
4974
5028
  """
4975
5029
  DESCRIPTION:
@@ -5049,6 +5103,7 @@ class _AggregateColumnExpresion(ColumnExpression):
5049
5103
  """
5050
5104
  return self.__generate_function_call_object(func.sum, distinct=distinct, **kwargs)
5051
5105
 
5106
+ @collect_queryband(queryband="DFC_std")
5052
5107
  def std(self, distinct=False, population=False, **kwargs):
5053
5108
  """
5054
5109
  DESCRIPTION:
@@ -5169,6 +5224,7 @@ class _AggregateColumnExpresion(ColumnExpression):
5169
5224
  else:
5170
5225
  return self.__generate_function_call_object(func.stddev_samp, distinct=distinct, **kwargs)
5171
5226
 
5227
+ @collect_queryband(queryband="DFC_unique")
5172
5228
  def unique(self, **kwargs):
5173
5229
  """
5174
5230
  DESCRIPTION:
@@ -5223,6 +5279,7 @@ class _AggregateColumnExpresion(ColumnExpression):
5223
5279
  self.__validate_operation(name="unique", describe_op=describe_op)
5224
5280
  return self.count(True)
5225
5281
 
5282
+ @collect_queryband(queryband="DFC_var")
5226
5283
  def var(self, distinct=False, population=False, **kwargs):
5227
5284
  """
5228
5285
  DESCRIPTION:
@@ -5597,6 +5654,153 @@ class _SQLColumnExpression(_LogicalColumnExpression,
5597
5654
  literal_binds=True)
5598
5655
  return aliased_expression
5599
5656
 
5657
+ @collect_queryband(queryband="DFC_fillna")
5658
+ def fillna(self, value):
5659
+ """
5660
+ DESCRIPTION:
5661
+ Function replaces every occurrence of NA value in column
5662
+ with the "value". Use this function either to replace or remove
5663
+ NA from Column.
5664
+
5665
+ PARAMETES:
5666
+ value:
5667
+ Required Argument.
5668
+ Specifies the replacement value for null values in the column.
5669
+ Types: str or int or float or ColumnExpression
5670
+
5671
+ RAISES:
5672
+ TeradataMlException
5673
+
5674
+ RETURNS:
5675
+ ColumnExpression
5676
+
5677
+ EXAMPLES:
5678
+ >>> load_example_data("dataframe", "sales")
5679
+ >>> df = DataFrame("sales")
5680
+ >>> df
5681
+ Feb Jan Mar Apr datetime
5682
+ accounts
5683
+ Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
5684
+ Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
5685
+ Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
5686
+ Yellow Inc 90.0 NaN NaN NaN 04/01/2017
5687
+ Orange Inc 210.0 NaN NaN 250.0 04/01/2017
5688
+ Red Inc 200.0 150.0 140.0 NaN 04/01/2017
5689
+
5690
+ # Example 1: Fill the null value in column 'Mar'
5691
+ # with the the specified value.
5692
+ >>> df.assign(Mar = df.Mar.fillna(1))
5693
+ Feb Jan Mar Apr datetime
5694
+ accounts
5695
+ Red Inc 200.0 150.0 140 NaN 04/01/2017
5696
+ Alpha Co 210.0 200.0 215 250.0 04/01/2017
5697
+ Yellow Inc 90.0 NaN 1 NaN 04/01/2017
5698
+ Jones LLC 200.0 150.0 140 180.0 04/01/2017
5699
+ Blue Inc 90.0 50.0 95 101.0 04/01/2017
5700
+ Orange Inc 210.0 NaN 1 250.0 04/01/2017
5701
+ """
5702
+ if isinstance(value, type(self)):
5703
+ value = value.expression
5704
+ return case_when((self.expression == None, value), else_=self.expression)
5705
+
5706
+ @collect_queryband(queryband="DFC_concat")
5707
+ def concat(self, separator, *columns):
5708
+ """
5709
+ DESCRIPTION:
5710
+ Function to concatenate the columns with a separator.
5711
+
5712
+ PARAMETERS:
5713
+ separator:
5714
+ Required Argument.
5715
+ Specifies the string to be used as a separator between two concatenated columns.
5716
+ Note:
5717
+ This argument is ignored when no column is specified.
5718
+ Types: str
5719
+
5720
+ columns:
5721
+ Optional Argument.
5722
+ Specifies the name(s) of the columns or ColumnExpression(s) to concat on.
5723
+ Types: str OR ColumnExpression OR ColumnExpressions
5724
+
5725
+ RETURNS:
5726
+ ColumnExpression
5727
+
5728
+ EXAMPLES:
5729
+ # Load the data to run the example.
5730
+ >>> load_example_data("dataframe", "admissions_train")
5731
+ >>>
5732
+
5733
+ # Create a DataFrame on 'admissions_train' table.
5734
+ >>> admissions_train = DataFrame("admissions_train")
5735
+ >>> admissions_train
5736
+ masters gpa stats programming admitted
5737
+ id
5738
+ 22 yes 3.46 Novice Beginner 0
5739
+ 36 no 3.00 Advanced Novice 0
5740
+ 15 yes 4.00 Advanced Advanced 1
5741
+ 38 yes 2.65 Advanced Beginner 1
5742
+ 5 no 3.44 Novice Novice 0
5743
+ 17 no 3.83 Advanced Advanced 1
5744
+ 34 yes 3.85 Advanced Beginner 0
5745
+ 13 no 4.00 Advanced Novice 1
5746
+ 26 yes 3.57 Advanced Advanced 1
5747
+ 19 yes 1.98 Advanced Advanced 0
5748
+ >>>
5749
+
5750
+ # Example 1: Concatenate the columns "stats" and "programming" with out any seperator.
5751
+ >>> df = admissions_train.assign(concat_gpa_=admissions_train.stats.concat("", admissions_train.programming))
5752
+ >>> print(df)
5753
+ masters gpa stats programming admitted new_column
5754
+ id
5755
+ 34 yes 3.85 Advanced Beginner 0 AdvancedBeginner
5756
+ 32 yes 3.46 Advanced Beginner 0 AdvancedBeginner
5757
+ 11 no 3.13 Advanced Advanced 1 AdvancedAdvanced
5758
+ 40 yes 3.95 Novice Beginner 0 NoviceBeginner
5759
+ 38 yes 2.65 Advanced Beginner 1 AdvancedBeginner
5760
+ 36 no 3.00 Advanced Novice 0 AdvancedNovice
5761
+ 7 yes 2.33 Novice Novice 1 NoviceNovice
5762
+ 26 yes 3.57 Advanced Advanced 1 AdvancedAdvanced
5763
+ 19 yes 1.98 Advanced Advanced 0 AdvancedAdvanced
5764
+ 13 no 4.00 Advanced Novice 1 AdvancedNovice
5765
+ >>>
5766
+
5767
+ # Example 2: Concatenate the columns "programming", "gpa" and "masters" with '_'.
5768
+ >>> df = admissions_train.assign(new_column=admissions_train.programming.concat("_", admissions_train.gpa, "masters"))
5769
+ >>> print(df)
5770
+ masters gpa stats programming admitted new_column
5771
+ id
5772
+ 34 yes 3.85 Advanced Beginner 0 Beginner_ 3.85000000000000E 000_yes
5773
+ 32 yes 3.46 Advanced Beginner 0 Beginner_ 3.46000000000000E 000_yes
5774
+ 11 no 3.13 Advanced Advanced 1 Advanced_ 3.13000000000000E 000_no
5775
+ 40 yes 3.95 Novice Beginner 0 Beginner_ 3.95000000000000E 000_yes
5776
+ 38 yes 2.65 Advanced Beginner 1 Beginner_ 2.65000000000000E 000_yes
5777
+ 36 no 3.00 Advanced Novice 0 Novice_ 3.00000000000000E 000_no
5778
+ 7 yes 2.33 Novice Novice 1 Novice_ 2.33000000000000E 000_yes
5779
+ 26 yes 3.57 Advanced Advanced 1 Advanced_ 3.57000000000000E 000_yes
5780
+ 19 yes 1.98 Advanced Advanced 0 Advanced_ 1.98000000000000E 000_yes
5781
+ 13 no 4.00 Advanced Novice 1 Novice_ 4.00000000000000E 000_no
5782
+ """
5783
+ awu_matrix = []
5784
+ awu_matrix.append(["separator", separator, False, (str), False])
5785
+ for column in columns:
5786
+ awu_matrix.append(["columns", column, True, (str, ColumnExpression), True])
5787
+
5788
+ # Validate argument types
5789
+ _Validators._validate_function_arguments(awu_matrix)
5790
+
5791
+ get_expr = lambda col: col.expression if not isinstance(col, str) else getattr(self._parent_df, col).expression
5792
+ columns_ = [get_expr(self)]
5793
+ if columns:
5794
+ for column in columns:
5795
+ columns_ = columns_ + [separator, get_expr(column)]
5796
+ # Below condition is edge case condition for func.concat method,
5797
+ # It seems when last argument is ColumnExpression, i.e., df.column1+df.column2
5798
+ # it raises error so to handle that below condition is added.
5799
+ columns_.append("")
5800
+
5801
+ return _SQLColumnExpression(func.concat(*columns_))
5802
+
5803
+ @collect_queryband(queryband="DFC_cast")
5600
5804
  def cast(self, type_ = None):
5601
5805
  """
5602
5806
  DESCRIPTION:
@@ -5702,7 +5906,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
5702
5906
  1 yes 3.95 Beginner Beginner 0
5703
5907
 
5704
5908
  RETURNS:
5705
- _SQLColumnExpression
5909
+ ColumnExpression
5706
5910
 
5707
5911
  RAISES:
5708
5912
  TeradataMlException
@@ -5858,6 +6062,9 @@ class _SQLColumnExpression(_LogicalColumnExpression,
5858
6062
  identifier = func_name
5859
6063
  package = "vantage"
5860
6064
 
6065
+ # Empty queryband buffer before SQL call.
6066
+ UtilFuncs._set_queryband()
6067
+
5861
6068
  # Invoke the function and return the results.
5862
6069
  if property:
5863
6070
  return self._wrap_as_column_expression(getattr(func.vantage,
@@ -5932,6 +6139,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
5932
6139
  if isinstance(key, str):
5933
6140
  return getattr(self, key)
5934
6141
 
6142
+ @collect_queryband(queryband="DFC_window")
5935
6143
  def window(self,
5936
6144
  partition_columns=None,
5937
6145
  order_columns=None,
@@ -5987,16 +6195,24 @@ class _SQLColumnExpression(_LogicalColumnExpression,
5987
6195
  of a teradataml DataFrame.
5988
6196
  2. "order_columns" supports only columns specified in
5989
6197
  groupby function, if Column is from DataFrameGroupBy.
5990
- Types: str OR list of Strings (str)
6198
+ 3. When ColumnExpression(s) is(are) passed to "order_columns", then the
6199
+ corresponding expression takes precedence over arguments
6200
+ "sort_ascending" and "nulls_first". Say, ColumnExpression is col1, then
6201
+ 1. col1.asc() or col.desc() is effective irrespective of "sort_ascending".
6202
+ 2. col1.nulls_first() or col.nulls_last() is effective irrespective of "nulls_first".
6203
+ 3. Any combination of above two take precedence over "sort_ascending" and "nulls_first".
6204
+ Types: str OR list of Strings (str) OR ColumnExpression OR list of ColumnExpressions
5991
6205
 
5992
6206
  sort_ascending:
5993
6207
  Optional Argument.
5994
6208
  Specifies whether column ordering should be in ascending or
5995
6209
  descending order.
5996
6210
  Default Value: True (ascending)
5997
- Note:
5998
- When "order_columns" argument is not specified, argument
5999
- is ignored.
6211
+ Notes:
6212
+ * When "order_columns" argument is not specified, argument
6213
+ is ignored.
6214
+ * When ColumnExpression(s) is(are) passed to "order_columns", then the
6215
+ argument is ignored.
6000
6216
  Types: bool
6001
6217
 
6002
6218
  nulls_first:
@@ -6004,9 +6220,11 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6004
6220
  Specifies whether null results are to be listed first or last
6005
6221
  or scattered.
6006
6222
  Default Value: None
6007
- Note:
6008
- When "order_columns" argument is not specified, argument
6009
- is ignored.
6223
+ Notes:
6224
+ * When "order_columns" argument is not specified, argument
6225
+ is ignored.
6226
+ * When "order_columns" is a ColumnExpression(s), this argument
6227
+ is ignored.
6010
6228
  Types: bool
6011
6229
 
6012
6230
  window_start_point:
@@ -6094,8 +6312,8 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6094
6312
  # between unbounded preceding and 3 preceding with
6095
6313
  # "partition_columns" and "order_columns" argument with
6096
6314
  # default sorting.
6097
- >>> window = df.Feb.window(partition_columns="Feb",
6098
- ... order_columns=["Feb", "datetime"],
6315
+ >>> window = df.Feb.window(partition_columns=df.Feb,
6316
+ ... order_columns=[df.Feb, df.datetime],
6099
6317
  ... window_start_point=None,
6100
6318
  ... window_end_point=-3)
6101
6319
  >>>
@@ -6104,9 +6322,8 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6104
6322
  # current row and 3 following with sorting done on 'Feb',
6105
6323
  # 'datetime' columns in descending order and
6106
6324
  # "partition_columns" argument.
6107
- >>> window = df.Feb.window(partition_columns="Feb",
6108
- ... order_columns=["Feb", "datetime"],
6109
- ... sort_ascending=False,
6325
+ >>> window = df.Feb.window(partition_columns=df.Feb,
6326
+ ... order_columns=[df.Feb.desc(), df.datetime.desc()],
6110
6327
  ... window_start_point=0,
6111
6328
  ... window_end_point=3)
6112
6329
  >>>
@@ -6117,8 +6334,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6117
6334
  # order and NULL values in 'Feb', 'datetime'
6118
6335
  # columns appears at last.
6119
6336
  >>> window = df.Feb.window(partition_columns="Feb",
6120
- ... order_columns=["Feb", "datetime"],
6121
- ... nulls_first=False,
6337
+ ... order_columns=[df.Feb.nulls_first(), df.datetime.nulls_first()],
6122
6338
  ... window_start_point=0,
6123
6339
  ... window_end_point=None
6124
6340
  ... )
@@ -6127,10 +6343,8 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6127
6343
  # Example 5: Create a grouping window, with sorting done on 'Feb',
6128
6344
  # 'datetime' columns in ascending order and NULL values
6129
6345
  # in 'Feb', 'datetime' columns appears at last.
6130
- >>> window = df.Feb.window(partition_columns="Feb",
6131
- ... order_columns=["Feb", "datetime"],
6132
- ... sort_ascending=False,
6133
- ... nulls_first=False,
6346
+ >>> window = df.Feb.window(partition_columns=df.Feb,
6347
+ ... order_columns=[df.Feb.desc().nulls_last(), df.datetime.desc().nulls_last()],
6134
6348
  ... window_start_point=None,
6135
6349
  ... window_end_point=None
6136
6350
  ... )
@@ -6138,10 +6352,8 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6138
6352
 
6139
6353
  # Example 6: Create a window on a teradataml DataFrame column, which
6140
6354
  # ignores all the parameters while creating window.
6141
- >>> window = df.Feb.window(partition_columns="Feb",
6142
- ... order_columns=["Feb", "datetime"],
6143
- ... sort_ascending=False,
6144
- ... nulls_first=False,
6355
+ >>> window = df.Feb.window(partition_columns=df.Feb,
6356
+ ... order_columns=[df.Feb.desc().nulls_last(), df.datetime.desc().nulls_last()],
6145
6357
  ... ignore_window=True
6146
6358
  ... )
6147
6359
  >>>
@@ -6198,6 +6410,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6198
6410
  window_end_point=window_end_point,
6199
6411
  ignore_window=ignore_window)
6200
6412
 
6413
+ @collect_queryband(queryband="DFC_desc")
6201
6414
  def desc(self):
6202
6415
  """
6203
6416
  DESCRIPTION:
@@ -6212,7 +6425,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6212
6425
  None
6213
6426
 
6214
6427
  RETURNS:
6215
- An object of type _SQLColumnExpression.
6428
+ ColumnExpression
6216
6429
 
6217
6430
  EXAMPLES:
6218
6431
  >>> load_example_data("dataframe","sales")
@@ -6235,6 +6448,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6235
6448
  """
6236
6449
  return _SQLColumnExpression(self.expression.desc().label(self.name))
6237
6450
 
6451
+ @collect_queryband(queryband="DFC_asc")
6238
6452
  def asc(self):
6239
6453
  """
6240
6454
  DESCRIPTION:
@@ -6249,7 +6463,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6249
6463
  None
6250
6464
 
6251
6465
  RETURNS:
6252
- An object of type _SQLColumnExpression.
6466
+ ColumnExpression
6253
6467
 
6254
6468
  EXAMPLES:
6255
6469
  >>> load_example_data("dataframe","sales")
@@ -6269,6 +6483,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6269
6483
  """
6270
6484
  return _SQLColumnExpression(self.expression.asc().label(self.name))
6271
6485
 
6486
+ @collect_queryband(queryband="DFC_nullsFirst")
6272
6487
  def nulls_first(self):
6273
6488
  """
6274
6489
  DESCRIPTION:
@@ -6280,7 +6495,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6280
6495
  None
6281
6496
 
6282
6497
  RETURNS:
6283
- An object of type _SQLColumnExpression.
6498
+ ColumnExpression
6284
6499
 
6285
6500
  EXAMPLES:
6286
6501
  >>> load_example_data("dataframe","sales")
@@ -6300,6 +6515,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6300
6515
  """
6301
6516
  return _SQLColumnExpression(self.expression.nulls_first().label(self.name))
6302
6517
 
6518
+ @collect_queryband(queryband="DFC_nullsLast")
6303
6519
  def nulls_last(self):
6304
6520
  """
6305
6521
  DESCRIPTION:
@@ -6311,7 +6527,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6311
6527
  None
6312
6528
 
6313
6529
  RETURNS:
6314
- An object of type _SQLColumnExpression.
6530
+ ColumnExpression
6315
6531
 
6316
6532
  EXAMPLES:
6317
6533
  >>> load_example_data("dataframe","sales")
@@ -6331,6 +6547,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6331
6547
  """
6332
6548
  return _SQLColumnExpression(self.expression.nulls_last().label(self.name))
6333
6549
 
6550
+ @collect_queryband(queryband="DFC_distinct")
6334
6551
  def distinct(self):
6335
6552
  """
6336
6553
  DESCRIPTION:
@@ -6345,7 +6562,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6345
6562
  None
6346
6563
 
6347
6564
  RETURNS:
6348
- An object of type _SQLColumnExpression.
6565
+ ColumnExpression
6349
6566
 
6350
6567
  EXAMPLES:
6351
6568
  >>> from teradataml import *
@@ -6370,63 +6587,3504 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6370
6587
  """
6371
6588
  return _SQLColumnExpression(self.expression.distinct().label(self.name))
6372
6589
 
6373
- def __get_columns(self, col_expr):
6590
+ @collect_queryband(queryband="DFC_ilike")
6591
+ def ilike(self, other):
6374
6592
  """
6375
6593
  DESCRIPTION:
6376
- Function to get the columns involved in a sqlalchemy expression.
6594
+ Function which is used to match the pattern.
6377
6595
 
6378
6596
  PARAMETERS:
6379
- col_expr:
6597
+ other:
6380
6598
  Required Argument.
6381
- Specifies the sqlalchemy expression.
6382
- Types: BinaryExpression OR Grouping OR GenericFunction OR ClauseList OR Column
6599
+ Specifies a string to match. String match is case insensitive.
6600
+ Types: str
6383
6601
 
6384
- RAISES:
6385
- None
6602
+ RETURNS:
6603
+ ColumnExpression.
6604
+
6605
+ EXAMPLES:
6606
+ >>> load_example_data("dataframe","admissions_train")
6607
+ >>> df = DataFrame.from_table('admissions_train')
6608
+ masters gpa stats programming admitted
6609
+ id
6610
+ 13 no 4.00 Advanced Novice 1
6611
+ 26 yes 3.57 Advanced Advanced 1
6612
+ 5 no 3.44 Novice Novice 0
6613
+ 19 yes 1.98 Advanced Advanced 0
6614
+ 15 yes 4.00 Advanced Advanced 1
6615
+ 40 yes 3.95 Novice Beginner 0
6616
+ 7 yes 2.33 Novice Novice 1
6617
+ 22 yes 3.46 Novice Beginner 0
6618
+ 36 no 3.00 Advanced Novice 0
6619
+ 38 yes 2.65 Advanced Beginner 1
6620
+
6621
+ # Example 1: Find out the records whose stats starts with 'A'.
6622
+ >>> df = df[df.stats.ilike('a%')]
6623
+ >>> df
6624
+ masters gpa stats programming admitted
6625
+ id
6626
+ 19 yes 1.98 Advanced Advanced 0
6627
+ 15 yes 4.00 Advanced Advanced 1
6628
+ 38 yes 2.65 Advanced Beginner 1
6629
+ 26 yes 3.57 Advanced Advanced 1
6630
+ 17 no 3.83 Advanced Advanced 1
6631
+ 34 yes 3.85 Advanced Beginner 0
6632
+ 13 no 4.00 Advanced Novice 1
6633
+ 24 no 1.87 Advanced Novice 1
6634
+ 36 no 3.00 Advanced Novice 0
6635
+ 27 yes 3.96 Advanced Advanced 0
6636
+ >>>
6637
+
6638
+ # Example 2: Create a new Column with values as -
6639
+ # 1 if value of column 'stats' starts with 'a' and third letter is 'v',
6640
+ # 0 otherwise. Ignore case.
6641
+ >>> df.assign(new_col = case_when((df.stats.ilike('a_v%').expression, 1), else_=0))
6642
+ masters gpa stats programming admitted n
6643
+ id
6644
+ 13 no 4.00 Advanced Novice 1 1
6645
+ 26 yes 3.57 Advanced Advanced 1 1
6646
+ 5 no 3.44 Novice Novice 0 0
6647
+ 19 yes 1.98 Advanced Advanced 0 1
6648
+ 15 yes 4.00 Advanced Advanced 1 1
6649
+ 40 yes 3.95 Novice Beginner 0 0
6650
+ 7 yes 2.33 Novice Novice 1 0
6651
+ 22 yes 3.46 Novice Beginner 0 0
6652
+ 36 no 3.00 Advanced Novice 0 1
6653
+ 38 yes 2.65 Advanced Beginner 1 1
6654
+ >>>
6655
+ """
6656
+ return _SQLColumnExpression(
6657
+ literal_column("{} (NOT CASESPECIFIC) LIKE '{}'".format(self.compile(), other)))
6658
+
6659
+ @collect_queryband(queryband="DFC_like")
6660
+ def like(self, other):
6661
+ """
6662
+ DESCRIPTION:
6663
+ Function which is used to match the pattern.
6664
+
6665
+ PARAMETERS:
6666
+ other:
6667
+ Required Argument.
6668
+ Specifies a string to match. String match is case insensitive.
6669
+ Types: str
6386
6670
 
6387
6671
  RETURNS:
6388
- list
6672
+ ColumnExpression.
6389
6673
 
6390
6674
  EXAMPLES:
6391
- >>> self.__get_columns(self.expression)
6675
+ >>> load_example_data("dataframe","admissions_train")
6676
+ >>> df = DataFrame.from_table('admissions_train')
6677
+ masters gpa stats programming admitted
6678
+ id
6679
+ 13 no 4.00 Advanced Novice 1
6680
+ 26 yes 3.57 Advanced Advanced 1
6681
+ 5 no 3.44 Novice Novice 0
6682
+ 19 yes 1.98 Advanced Advanced 0
6683
+ 15 yes 4.00 Advanced Advanced 1
6684
+ 40 yes 3.95 Novice Beginner 0
6685
+ 7 yes 2.33 Novice Novice 1
6686
+ 22 yes 3.46 Novice Beginner 0
6687
+ 36 no 3.00 Advanced Novice 0
6688
+ 38 yes 2.65 Advanced Beginner 1
6689
+
6690
+ # Example 1: Find out the records whose stats starts with 'A'.
6691
+ >>> df = df[df.stats.like('A%')]
6692
+ >>> df
6693
+ masters gpa stats programming admitted
6694
+ id
6695
+ 19 yes 1.98 Advanced Advanced 0
6696
+ 15 yes 4.00 Advanced Advanced 1
6697
+ 38 yes 2.65 Advanced Beginner 1
6698
+ 26 yes 3.57 Advanced Advanced 1
6699
+ 17 no 3.83 Advanced Advanced 1
6700
+ 34 yes 3.85 Advanced Beginner 0
6701
+ 13 no 4.00 Advanced Novice 1
6702
+ 24 no 1.87 Advanced Novice 1
6703
+ 36 no 3.00 Advanced Novice 0
6704
+ 27 yes 3.96 Advanced Advanced 0
6705
+ >>>
6706
+
6707
+ # Example 2: Create a new Column with values as -
6708
+ # 1 if value of column 'stats' starts with 'A' and third letter is 'v',
6709
+ # 0 otherwise. Do not ignore case.
6710
+ >>> df.assign(new_col = case_when((df.stats.like('A_v%').expression, 1), else_=0))
6711
+ >>> df
6712
+ masters gpa stats programming admitted n
6713
+ id
6714
+ 13 no 4.00 Advanced Novice 1 1
6715
+ 26 yes 3.57 Advanced Advanced 1 1
6716
+ 5 no 3.44 Novice Novice 0 0
6717
+ 19 yes 1.98 Advanced Advanced 0 1
6718
+ 15 yes 4.00 Advanced Advanced 1 1
6719
+ 40 yes 3.95 Novice Beginner 0 0
6720
+ 7 yes 2.33 Novice Novice 1 0
6721
+ 22 yes 3.46 Novice Beginner 0 0
6722
+ 36 no 3.00 Advanced Novice 0 1
6723
+ 38 yes 2.65 Advanced Beginner 1 1
6724
+ >>>
6392
6725
  """
6393
- # If it is a column, return the name of the column.
6394
- if isinstance(col_expr, Column):
6395
- return [col_expr.name]
6726
+ return _SQLColumnExpression(
6727
+ literal_column("{} (CASESPECIFIC) LIKE '{}'".format(self.compile(), other)))
6396
6728
 
6397
- # Every other type exposes a method to retrieve the children. Recursively, walk through all
6398
- # the childs till a Column or a Bind Parameter is reached.
6399
- elif isinstance(col_expr, (BinaryExpression, Grouping, GenericFunction, ClauseList, Function)):
6400
- res = []
6401
- for c in col_expr.get_children():
6402
- res = res + self.__get_columns(c)
6403
- return res
6404
- else:
6405
- try:
6406
- if isinstance(col_expr, ExpressionClauseList):
6407
- res = []
6408
- for c in col_expr.get_children():
6409
- res = res + self.__get_columns(c)
6410
- return res
6411
- except NameError:
6412
- pass
6413
- # If the child is a Bind Parameter, return empty string.
6414
- return []
6729
+ @collect_queryband(queryband="DFC_startswith")
6730
+ def startswith(self, other):
6731
+ """
6732
+ DESCRIPTION:
6733
+ Function to check whether the column value starts with the specified value or not.
6415
6734
 
6416
- @property
6417
- def _all_columns(self):
6735
+ PARAMETERS:
6736
+ other:
6737
+ Required Argument.
6738
+ Specifies a string literal or ColumnExpression to match.
6739
+ Types: str OR ColumnExpression
6740
+
6741
+ RETURNS:
6742
+ ColumnExpression.
6743
+
6744
+ EXAMPLES:
6745
+ >>> load_example_data("ntree", "employee_table")
6746
+ >>> df = DataFrame("employee_table")
6747
+ >>> df
6748
+ emp_name mgr_id mgr_name
6749
+ emp_id
6750
+ 200 Pat 100.0 Don
6751
+ 300 Donna 100.0 Don
6752
+ 400 Kim 200.0 Pat
6753
+ 500 Fred 400.0 Kim
6754
+ 100 Don NaN NA
6755
+
6756
+ # Example 1: Find out the employees whose name starts with their managers name.
6757
+ >>> df[df.emp_name.startswith(df.mgr_name)]
6758
+ emp_name mgr_id mgr_name
6759
+ emp_id
6760
+ 300 Donna 100 Don
6761
+
6762
+ # Example 2: Find out the employees whose manager name starts with Don.
6763
+ >>> df[df.mgr_name.startswith('Don')]
6764
+ emp_name mgr_id mgr_name
6765
+ emp_id
6766
+ 300 Donna 100 Don
6767
+ 200 Pat 100 Don
6768
+
6769
+ # Example 3: Create a new column with values as
6770
+ # 1, if employees manager name starts with 'Don'.
6771
+ # 0, else.
6772
+ >>> df.assign(new_col=case_when((df.mgr_name.startswith('Don').expression, 1), else_=0))
6773
+ emp_name mgr_id mgr_name new_col
6774
+ emp_id
6775
+ 300 Donna 100.0 Don 1
6776
+ 500 Fred 400.0 Kim 0
6777
+ 100 Don NaN NA 0
6778
+ 400 Kim 200.0 Pat 0
6779
+ 200 Pat 100.0 Don 1
6780
+ """
6781
+ return _SQLColumnExpression(
6782
+ self.regexp_instr(other, 1, 1, 0).expression == 1,
6783
+ type=INTEGER)
6784
+
6785
+ @collect_queryband(queryband="DFC_endswith")
6786
+ def endswith(self, other):
6418
6787
  """
6419
6788
  DESCRIPTION:
6420
- A property to get the columns involved in ColumnExpression.
6789
+ Function to check whether the column value ends with the specified value or not.
6790
+
6791
+ PARAMETERS:
6792
+ other:
6793
+ Required Argument.
6794
+ Specifies a string literal or ColumnExpression to match.
6795
+ Types: str OR ColumnExpression
6796
+
6797
+ RETURNS:
6798
+ ColumnExpression.
6799
+
6800
+ EXAMPLES:
6801
+ >>> load_example_data("ntree", "employee_table")
6802
+ >>> df = DataFrame("employee_table")
6803
+ >>> df = df.assign(new_col = 'on')
6804
+ emp_name mgr_id mgr_name new_col
6805
+ emp_id
6806
+ 300 Donna 100.0 Don on
6807
+ 500 Fred 400.0 Kim on
6808
+ 100 Don NaN NA on
6809
+ 400 Kim 200.0 Pat on
6810
+ 200 Pat 100.0 Don on
6811
+
6812
+ # Example 1: Find out the employees whose manager name ends
6813
+ # with values in column 'new_col'.
6814
+ >>> df[df.mgr_name.endswith(df.new_col)]
6815
+ emp_name mgr_id mgr_name new_col
6816
+ emp_id
6817
+ 300 Donna 100 Don on
6818
+ 200 Pat 100 Don on
6819
+
6820
+ # Example 2: Find out the employees whose name starts with
6821
+ # 'D' and ends with 'n'.
6822
+ >>> df[df.emp_name.startswith('D') & df.emp_name.endswith('n')]
6823
+ emp_name mgr_id mgr_name new_col
6824
+ emp_id
6825
+ 100 Don None NA on
6826
+
6827
+ # Example 3: Create a new column with values as
6828
+ # 1, if employees manager name ends with 'im'.
6829
+ # 0, else.
6830
+ >>> df.assign(new_col=case_when((df.mgr_name.endswith('im').expression, 1), else_=0))
6831
+ emp_name mgr_id mgr_name new_col
6832
+ emp_id
6833
+ 300 Donna 100.0 Don 0
6834
+ 500 Fred 400.0 Kim 1
6835
+ 100 Don NaN NA 0
6836
+ 400 Kim 200.0 Pat 0
6837
+ 200 Pat 100.0 Don 0
6838
+ """
6839
+ return _SQLColumnExpression(
6840
+ self.regexp_instr(other, 1, 1, 1).expression == self.length().expression+1,
6841
+ type=INTEGER)
6842
+
6843
+ @collect_queryband(queryband="DFC_substr")
6844
+ def substr(self, start_pos, length):
6845
+ """
6846
+ DESCRIPTION:
6847
+ Function to get substring from column.
6848
+
6849
+ PARAMETERS:
6850
+ start_pos:
6851
+ Required Argument.
6852
+ Specifies starting position to extract string from column.
6853
+ Note:
6854
+ Index position starts with 1 instead of 0.
6855
+ Types: int
6856
+
6857
+ length:
6858
+ Required Argument.
6859
+ Specifies the length of the string to extract from column.
6860
+ Types: int
6861
+
6862
+ RETURNS:
6863
+ ColumnExpression.
6864
+
6865
+ EXAMPLES:
6866
+ >>> load_example_data("ntree", "employee_table")
6867
+ >>> df = DataFrame("employee_table")
6868
+ emp_name mgr_id mgr_name
6869
+ emp_id
6870
+ 200 Pat 100.0 Don
6871
+ 300 Donna 100.0 Don
6872
+ 400 Kim 200.0 Pat
6873
+ 500 Fred 400.0 Kim
6874
+ 100 Don NaN NA
6875
+
6876
+ # Example 1: Create a new column by extracting the first 3 letters
6877
+ # from column emp_name.
6878
+ >>> df.assign(new_column = df.emp_name.substr(1,3))
6879
+ emp_name mgr_id mgr_name new_column
6880
+ emp_id
6881
+ 200 Pat 100.0 Don Pat
6882
+ 300 Donna 100.0 Don Don
6883
+ 400 Kim 200.0 Pat Kim
6884
+ 500 Fred 400.0 Kim Fre
6885
+ 100 Don NaN NA Don
6886
+
6887
+ # Example 2: Find out the employees whose first three letters
6888
+ # in their name is 'Fre'.
6889
+ >>> df[df.emp_name.substr(1,3) == 'Fre']
6890
+ emp_name mgr_id mgr_name new_col
6891
+ emp_id
6892
+ 500 Fred 400 Kim on
6893
+ """
6894
+ return _SQLColumnExpression(func.substr(self.expression, start_pos, length),
6895
+ type=self.type)
6896
+
6897
+ @collect_queryband(queryband="DFC_replace")
6898
+ def replace(self, to_replace, value=None):
6899
+ """
6900
+ DESCRIPTION:
6901
+ Function replaces every occurrence of "to_replace" in the column
6902
+ with the "value". Use this function to replace a value from string.
6903
+ Note:
6904
+ The function replaces value in a string column only when it
6905
+ matches completely. If you want to replace a value in a string
6906
+ column with only a portion of the string, then use function
6907
+ oreplace.
6908
+
6909
+ PARAMETERS:
6910
+ to_replace:
6911
+ Required Argument.
6912
+ Specifies a ColumnExpression or a literal that the function
6913
+ searches for values in the Column. Use ColumnExpression when
6914
+ you want to match the condition based on a DataFrameColumn
6915
+ function, else use literal.
6916
+ Note:
6917
+ Only ColumnExpressions generated from DataFrameColumn
6918
+ functions are supported. BinaryExpressions are not supported.
6919
+ Example: Consider teradataml DataFrame has two columns COL1, COL2.
6920
+ df.COL1.abs() is supported but df.COL1 == df.COL2 is not
6921
+ supported.
6922
+ Supported column types: CHAR, VARCHAR, FLOAT, INTEGER, DECIMAL
6923
+ Types: ColumnExpression OR int OR float OR str OR dict
6924
+
6925
+ value:
6926
+ Required argument when "to_replace" is not a dictionary. Optional otherwise.
6927
+ Specifies a ColumnExpression or a literal that replaces
6928
+ the "to_replace" in the column. Use ColumnExpression when
6929
+ you want to replace based on a DataFrameColumn function, else
6930
+ use literal.
6931
+ Notes:
6932
+ * Argument is ignored if "to_replace" is a dictionary.
6933
+ * Only ColumnExpressions generated from DataFrameColumn
6934
+ functions are supported. BinaryExpressions are not supported.
6935
+ Example: Consider teradataml DataFrame has two columns COL1, COL2.
6936
+ df.COL1.abs() is supported but df.COL1 == df.COL2 is not
6937
+ supported.
6938
+ Supported column types: CHAR, VARCHAR, FLOAT, INTEGER, DECIMAL
6939
+ Types: ColumnExpression OR int OR float OR str
6421
6940
 
6422
6941
  RAISES:
6423
- None
6942
+ TeradataMlException
6424
6943
 
6425
6944
  RETURNS:
6426
- list
6945
+ ColumnExpression
6427
6946
 
6428
6947
  EXAMPLES:
6429
- >>> self._all_columns
6948
+ # Load the data to run the example.
6949
+ >>> load_example_data("teradataml", "chi_sq")
6950
+
6951
+ # Create a DataFrame on 'chi_sq' table.
6952
+ >>> df = DataFrame("chi_sq")
6953
+ >>> print(df)
6954
+ dem rep
6955
+ gender
6956
+ female 6 9
6957
+ male 8 5
6958
+
6959
+ # Example 1: Create a new column 'new_column' by replacing all the
6960
+ # occurances of 'male' with 'man' in Column 'gender'.
6961
+ >>> res = df.assign(new_column = df.gender.replace("male", "man"))
6962
+ >>> print(res)
6963
+ dem rep new_column
6964
+ gender
6965
+ male 8 5 man
6966
+ female 6 9 female
6967
+
6968
+ # Example 2: Create a new Column 'new_column' by replacing all the
6969
+ # occurances of 5 with square root of 5 in Column 'rep'.
6970
+ >>> print(df.assign(new_column = df.rep.replace(5, df.rep.sqrt())))
6971
+ dem rep new_column
6972
+ gender
6973
+ male 8 5 2.236068
6974
+ female 6 9 9.000000
6975
+
6976
+ # Example 3: Create a new Column 'new_column' by replacing all the
6977
+ # occurances of 5 with square root of 5 and 9 with
6978
+ # the values of Column 'dem' in Column 'rep'.
6979
+ >>> print(df.assign(new_column = df.rep.replace({5: df.rep.sqrt(), 9:df.dem})))
6980
+ dem rep new_column
6981
+ gender
6982
+ male 8 5 2.236068
6983
+ female 6 9 6.000000
6984
+
6985
+ # Example 4: Create a new Column 'new_column' by replacing all the
6986
+ # the values of Column 'rep' with it's square root.
6987
+ >>> print(df.assign(new_column = df.rep.replace({df.rep: df.rep.sqrt()})))
6988
+ dem rep new_column
6989
+ gender
6990
+ female 6 9 3.000000
6991
+ male 8 5 2.236068
6992
+ """
6993
+ _validation_matrix = []
6994
+
6995
+ _validation_matrix.append(["to_replace", to_replace, True, (int, float, str, dict, _SQLColumnExpression), True])
6996
+ _validation_matrix.append(["value", value, True, (int, float, str, _SQLColumnExpression)])
6997
+ _Validators._validate_function_arguments(_validation_matrix)
6998
+
6999
+ # Convert to dictionary if it is not a dictionary.
7000
+ if not isinstance(to_replace, dict):
7001
+ to_replace = {to_replace: value}
7002
+
7003
+ exp = []
7004
+ for f_, t_ in to_replace.items():
7005
+ f_ = f_.expression if isinstance(f_, _SQLColumnExpression) else f_
7006
+ t_ = t_.expression if isinstance(t_, _SQLColumnExpression) else t_
7007
+ exp.append((self.expression == f_, t_))
7008
+
7009
+ expression = case_when(*exp, else_=self.expression)
7010
+ return _SQLColumnExpression(expression, type=self.type)
7011
+
7012
+ def _get_sql_columns(self, *columns):
6430
7013
  """
6431
- return list(set(self.__get_columns(self.expression)))
7014
+ DESCRIPTION:
7015
+ Get the list of columns names.
6432
7016
 
7017
+ PARAMETERS:
7018
+ *columns:
7019
+ Required Argument.
7020
+ Specifies the name(s) of the columns or ColumnExpression(s)
7021
+ as positional arguments.
7022
+ At least one positional argument is required.
7023
+ Types: str OR int OR float OR ColumnExpression OR ColumnExpressions
7024
+
7025
+ RETURNS:
7026
+ list
7027
+
7028
+ EXAMPLES:
7029
+ self._get_sql_columns(df.price, df.lotsize, df.bedrooms)
7030
+
7031
+ """
7032
+ arg_info_matrix = []
7033
+ expected_data_types = (str, int, float, ColumnExpression)
7034
+
7035
+ get_expr = lambda col: col.expression if isinstance(col, ColumnExpression)\
7036
+ else col
7037
+ columns_ = [get_expr(self)]
7038
+
7039
+ for column in columns:
7040
+ arg_info_matrix.append(["columns", column, False, expected_data_types, True])
7041
+ columns_ = columns_ + [get_expr(column)]
7042
+
7043
+ _Validators._validate_function_arguments(arg_info_matrix)
7044
+
7045
+ return columns_
7046
+
7047
+ @collect_queryband(queryband="DFC_greatest")
7048
+ def greatest(self, *columns):
7049
+ """
7050
+ DESCRIPTION:
7051
+ Get the greatest values from the given columns.
7052
+ Note:
7053
+ * All of the input columns type must be of same data
7054
+ type or else the types must be compatible.
7055
+
7056
+ PARAMETERS:
7057
+ *columns:
7058
+ Specifies the name(s) of the columns or ColumnExpression(s)
7059
+ as positional arguments.
7060
+ At least one positional argument is required.
7061
+ Types: str OR int OR float OR ColumnExpression OR ColumnExpressions
7062
+
7063
+ RETURNS:
7064
+ ColumnExpression
7065
+
7066
+ EXAMPLES:
7067
+ # Load the data to run the example.
7068
+ >>> load_example_data("glmpredict", "housing_test")
7069
+ >>>
7070
+
7071
+ # Create a DataFrame on 'housing_test' table.
7072
+ >>> df = DataFrame("housing_test")
7073
+ >>> df = df.select(["sn", "price", "lotsize", "bedrooms", "bathrms", "stories"])
7074
+ >>> df
7075
+ price lotsize bedrooms bathrms stories
7076
+ sn
7077
+ 364 72000.0 10700.0 3 1 2
7078
+ 13 27000.0 1700.0 3 1 2
7079
+ 459 44555.0 2398.0 3 1 1
7080
+ 463 49000.0 2610.0 3 1 2
7081
+ 260 41000.0 6000.0 2 1 1
7082
+ 177 70000.0 5400.0 4 1 2
7083
+ 53 68000.0 9166.0 2 1 1
7084
+ 440 69000.0 6862.0 3 1 2
7085
+ 255 61000.0 4360.0 4 1 2
7086
+ 301 55000.0 4080.0 2 1 1
7087
+ >>>
7088
+
7089
+ # Example 1: Find the greatest values in the columns "price" and "lotsize".
7090
+ >>> gt_df = df.assign(gt_col=df.price.greatest(df.lotsize))
7091
+ >>> gt_df
7092
+ price lotsize bedrooms bathrms stories gt_col
7093
+ sn
7094
+ 364 72000.0 10700.0 3 1 2 72000.0
7095
+ 13 27000.0 1700.0 3 1 2 27000.0
7096
+ 459 44555.0 2398.0 3 1 1 44555.0
7097
+ 463 49000.0 2610.0 3 1 2 49000.0
7098
+ 260 41000.0 6000.0 2 1 1 41000.0
7099
+ 177 70000.0 5400.0 4 1 2 70000.0
7100
+ 53 68000.0 9166.0 2 1 1 68000.0
7101
+ 440 69000.0 6862.0 3 1 2 69000.0
7102
+ 255 61000.0 4360.0 4 1 2 61000.0
7103
+ 301 55000.0 4080.0 2 1 1 55000.0
7104
+ >>>
7105
+
7106
+ # Example 2: Find the greatest values in the columns "price", "lotsize" and 70000.0.
7107
+ >>> gt_df = df.assign(gt_col=df.price.greatest(df.lotsize, 70000))
7108
+ >>> gt_df
7109
+ price lotsize bedrooms bathrms stories gt_col
7110
+ sn
7111
+ 364 72000.0 10700.0 3 1 2 72000.0
7112
+ 13 27000.0 1700.0 3 1 2 70000.0
7113
+ 459 44555.0 2398.0 3 1 1 70000.0
7114
+ 463 49000.0 2610.0 3 1 2 70000.0
7115
+ 260 41000.0 6000.0 2 1 1 70000.0
7116
+ 177 70000.0 5400.0 4 1 2 70000.0
7117
+ 53 68000.0 9166.0 2 1 1 70000.0
7118
+ 440 69000.0 6862.0 3 1 2 70000.0
7119
+ 255 61000.0 4360.0 4 1 2 70000.0
7120
+ 301 55000.0 4080.0 2 1 1 70000.0
7121
+ >>>
7122
+
7123
+ """
7124
+ cols = self._get_sql_columns(*columns)
7125
+
7126
+ return _SQLColumnExpression(func.greatest(*cols),
7127
+ type=cols[0].type)
7128
+
7129
+ @collect_queryband(queryband="DFC_least")
7130
+ def least(self, *columns):
7131
+ """
7132
+ DESCRIPTION:
7133
+ Get the least values from the given columns.
7134
+ Note:
7135
+ * All of the input columns type must be of same data
7136
+ type or else the types must be compatible.
7137
+
7138
+ PARAMETERS:
7139
+ *columns:
7140
+ Specifies the name(s) of the columns or ColumnExpression(s)
7141
+ as positional arguments.
7142
+ At least one positional argument is required.
7143
+ Types: str or int or float or ColumnExpression OR ColumnExpressions
7144
+
7145
+ RETURNS:
7146
+ ColumnExpression
7147
+
7148
+ EXAMPLES:
7149
+ # Load the data to run the example.
7150
+ >>> load_example_data("glmpredict", "housing_test")
7151
+ >>>
7152
+
7153
+ # Create a DataFrame on 'housing_test' table.
7154
+ >>> df = DataFrame("housing_test")
7155
+ >>> df = df.select(["sn", "price", "lotsize", "bedrooms", "bathrms", "stories"])
7156
+ >>> df
7157
+ price lotsize bedrooms bathrms stories
7158
+ sn
7159
+ 364 72000.0 10700.0 3 1 2
7160
+ 13 27000.0 1700.0 3 1 2
7161
+ 459 44555.0 2398.0 3 1 1
7162
+ 463 49000.0 2610.0 3 1 2
7163
+ 260 41000.0 6000.0 2 1 1
7164
+ 177 70000.0 5400.0 4 1 2
7165
+ 53 68000.0 9166.0 2 1 1
7166
+ 440 69000.0 6862.0 3 1 2
7167
+ 255 61000.0 4360.0 4 1 2
7168
+ 301 55000.0 4080.0 2 1 1
7169
+ >>>
7170
+
7171
+ # Example 1: Find the least values in the columns "price" and "lotsize".
7172
+ >>> lt_df = df.assign(lt_col=df.price.least(df.lotsize))
7173
+ >>> lt_df
7174
+ price lotsize bedrooms bathrms stories lt_col
7175
+ sn
7176
+ 364 72000.0 10700.0 3 1 2 10700.0
7177
+ 13 27000.0 1700.0 3 1 2 1700.0
7178
+ 459 44555.0 2398.0 3 1 1 2398.0
7179
+ 463 49000.0 2610.0 3 1 2 2610.0
7180
+ 260 41000.0 6000.0 2 1 1 6000.0
7181
+ 177 70000.0 5400.0 4 1 2 5400.0
7182
+ 53 68000.0 9166.0 2 1 1 9166.0
7183
+ 440 69000.0 6862.0 3 1 2 6862.0
7184
+ 255 61000.0 4360.0 4 1 2 4360.0
7185
+ 301 55000.0 4080.0 2 1 1 4080.0
7186
+ >>>
7187
+
7188
+ # Example 2: Find the least values in the columns "price", "lotsize" and 70000.0.
7189
+ >>> lt_df = df.assign(lt_col=df.price.least(df.lotsize, 70000))
7190
+ >>> lt_df
7191
+ price lotsize bedrooms bathrms stories lt_col
7192
+ sn
7193
+ 260 41000.0 6000.0 2 1 1 6000.0
7194
+ 38 67000.0 5170.0 3 1 4 5170.0
7195
+ 364 72000.0 10700.0 3 1 2 10700.0
7196
+ 301 55000.0 4080.0 2 1 1 4080.0
7197
+ 459 44555.0 2398.0 3 1 1 2398.0
7198
+ 177 70000.0 5400.0 4 1 2 5400.0
7199
+ 53 68000.0 9166.0 2 1 1 9166.0
7200
+ 440 69000.0 6862.0 3 1 2 6862.0
7201
+ 13 27000.0 1700.0 3 1 2 1700.0
7202
+ 469 55000.0 2176.0 2 1 2 2176.0
7203
+ >>>
7204
+
7205
+ """
7206
+ cols = self._get_sql_columns(*columns)
7207
+
7208
+ return _SQLColumnExpression(func.least(*cols),
7209
+ type=cols[0].type)
7210
+
7211
+ @collect_queryband(queryband="DFC_cbrt")
7212
+ def cbrt(self):
7213
+ """
7214
+ DESCRIPTION:
7215
+ Function to compute cube root of the column.
7216
+ Note:
7217
+ Function computes cuberoot for column only when it's values are positive.
7218
+ Else, the function fails.
7219
+
7220
+ RETURNS:
7221
+ ColumnExpression.
7222
+
7223
+ EXAMPLES:
7224
+ # Load the data to run the example.
7225
+ >>> load_example_data("teradataml","titanic")
7226
+
7227
+ # Create a DataFrame on 'titanic' table.
7228
+ >>> titanic = DataFrame.from_table('titanic')
7229
+ >>> df = titanic.select(["passenger", "age", "fare"])
7230
+ >>> print(df)
7231
+ age fare
7232
+ passenger
7233
+ 326 36.0 135.6333
7234
+ 183 9.0 31.3875
7235
+ 652 18.0 23.0000
7236
+ 265 NaN 7.7500
7237
+ 530 23.0 11.5000
7238
+ 122 NaN 8.0500
7239
+ 591 35.0 7.1250
7240
+ 387 1.0 46.9000
7241
+ 734 23.0 13.0000
7242
+ 795 25.0 7.8958
7243
+ >>>
7244
+
7245
+ # Example 1: Compute cuberoot values in "fare" and pass it as input to
7246
+ # DataFrame.assign().
7247
+ >>> cbrt_df = df.assign(fare_cbrt=df.fare.cbrt())
7248
+ >>> print(cbrt_df)
7249
+ age fare fare_cbrt
7250
+ passenger
7251
+ 326 36.0 135.6333 5.137937
7252
+ 183 9.0 31.3875 3.154416
7253
+ 652 18.0 23.0000 2.843867
7254
+ 40 14.0 11.2417 2.240151
7255
+ 774 NaN 7.2250 1.933211
7256
+ 366 30.0 7.2500 1.935438
7257
+ 509 28.0 22.5250 2.824153
7258
+ 795 25.0 7.8958 1.991279
7259
+ 61 22.0 7.2292 1.933586
7260
+ 469 NaN 7.7250 1.976816
7261
+ >>>
7262
+ """
7263
+ return (self.ln()/3).exp()
7264
+
7265
+ @collect_queryband(queryband="DFC_hex")
7266
+ def hex(self):
7267
+ """
7268
+ DESCRIPTION:
7269
+ Function to compute the Hexadecimal from decimal for the column.
7270
+
7271
+ RETURNS:
7272
+ ColumnExpression.
7273
+
7274
+ EXAMPLES:
7275
+ # Load the data to run the example.
7276
+ >>> load_example_data("teradataml","titanic")
7277
+
7278
+ # Create a DataFrame on 'titanic' table.
7279
+ >>> titanic = DataFrame.from_table('titanic')
7280
+ >>> df = titanic.select(["passenger", "age", "fare"])
7281
+ >>> print(df)
7282
+ age fare
7283
+ passenger
7284
+ 326 36.0 135.6333
7285
+ 183 9.0 31.3875
7286
+ 652 18.0 23.0000
7287
+ 265 NaN 7.7500
7288
+ 530 23.0 11.5000
7289
+ 122 NaN 8.0500
7290
+ 591 35.0 7.1250
7291
+ 387 1.0 46.9000
7292
+ 734 23.0 13.0000
7293
+ 795 25.0 7.8958
7294
+ >>>
7295
+
7296
+ # Example 1: Converts values in "age" decimal to hexadecimal and pass it as input to
7297
+ # DataFrame.assign().
7298
+ >>> hex_df = df.assign(age_in_hex=df.age.hex())
7299
+ >>> print(hex_df)
7300
+ age fare age_in_hex
7301
+ passenger
7302
+ 530 23.0 11.500 17
7303
+ 591 35.0 7.125 23
7304
+ 387 1.0 46.900 1
7305
+ 856 18.0 9.350 12
7306
+ 244 22.0 7.125 16
7307
+ 713 48.0 52.000 30
7308
+ 448 34.0 26.550 22
7309
+ 122 NaN 8.050 None
7310
+ 734 23.0 13.000 17
7311
+ 265 NaN 7.750 None
7312
+ >>>
7313
+ """
7314
+ return self.to_byte('base10').from_byte('base16')
7315
+
7316
+ @collect_queryband(queryband="DFC_unhex")
7317
+ def unhex(self):
7318
+ """
7319
+ DESCRIPTION:
7320
+ Function to compute the decimal from Hexadecimal for the column.
7321
+
7322
+ RETURNS:
7323
+ ColumnExpression.
7324
+
7325
+ EXAMPLES:
7326
+ # Load the data to run the example.
7327
+ >>> load_example_data("teradataml","titanic")
7328
+
7329
+ # Create a DataFrame on 'titanic' table.
7330
+ >>> titanic = DataFrame.from_table('titanic')
7331
+ >>> df = titanic.select(["passenger", "age", "fare"])
7332
+ >>> print(df)
7333
+ age fare
7334
+ passenger
7335
+ 326 36.0 135.6333
7336
+ 183 9.0 31.3875
7337
+ 652 18.0 23.0000
7338
+ 265 NaN 7.7500
7339
+ 530 23.0 11.5000
7340
+ 122 NaN 8.0500
7341
+ 591 35.0 7.1250
7342
+ 387 1.0 46.9000
7343
+ 734 23.0 13.0000
7344
+ 795 25.0 7.8958
7345
+ >>>
7346
+
7347
+ # create a "age_in_hex" column which contains hexadecimal values
7348
+ >>> hex_df = df.assign(age_in_hex=df.age.hex())
7349
+ >>> print(hex_df)
7350
+ age fare age_in_hex
7351
+ passenger
7352
+ 530 23.0 11.500 17
7353
+ 591 35.0 7.125 23
7354
+ 387 1.0 46.900 1
7355
+ 856 18.0 9.350 12
7356
+ 244 22.0 7.125 16
7357
+ 713 48.0 52.000 30
7358
+ 448 34.0 26.550 22
7359
+ 122 NaN 8.050 None
7360
+ 734 23.0 13.000 17
7361
+ 265 NaN 7.750 None
7362
+ >>>
7363
+
7364
+ # Example 1: Converts values in "age_in_hex" hexadecimal to decimal and pass it as input to
7365
+ # DataFrame.assign().
7366
+ >>> unhex_df = hex_df.assign(age_in_decimal=hex_df.age_in_hex.unhex())
7367
+ >>> print(unhex_df)
7368
+ age fare age_in_hex age_in_decimal
7369
+ passenger
7370
+ 326 36.0 135.6333 24 36
7371
+ 183 9.0 31.3875 9 9
7372
+ 652 18.0 23.0000 12 18
7373
+ 40 14.0 11.2417 E 14
7374
+ 774 NaN 7.2250 None None
7375
+ 366 30.0 7.2500 1E 30
7376
+ 509 28.0 22.5250 1C 28
7377
+ 795 25.0 7.8958 19 25
7378
+ 61 22.0 7.2292 16 22
7379
+ 469 NaN 7.7250 None None
7380
+ >>>
7381
+ """
7382
+ return self.to_byte('base16').from_byte('base10')
7383
+
7384
+ @collect_queryband(queryband="DFC_toByte")
7385
+ def to_byte(self, encoding='base10'):
7386
+ """
7387
+ DESCRIPTION:
7388
+ The function decodes a sequence of characters in a given
7389
+ encoding into a sequence of bits.
7390
+ Note:
7391
+ * By default, consider DataFrame column as 'base10' and encodes
7392
+ into a sequence of bits.
7393
+
7394
+ PARAMETERS:
7395
+ encoding:
7396
+ Optional Argument.
7397
+ Specifies encoding "to_byte" uses to return the sequence of characters
7398
+ specified by column.
7399
+ The following encodings are supported:
7400
+ * BaseX
7401
+ * BaseY
7402
+ * Base64M (MIME)
7403
+ * ASCII
7404
+ where X is a power of 2 (for example, 2, 8, 16) and
7405
+ Y is not a power of 2 (for example, 10 and 36).
7406
+ Default Value: 'base10'
7407
+ Types: str
7408
+
7409
+ Returns:
7410
+ ColumnExpression.
7411
+
7412
+ EXAMPLES:
7413
+ # Load the data to run the example.
7414
+ >>> load_example_data("dataframe", "bytes_table")
7415
+
7416
+ # Create a DataFrame on 'bytes_table' table.
7417
+ >>> df = DataFrame("bytes_table")
7418
+ >>> print(df)
7419
+ byte_col varbyte_col blob_col
7420
+ id_col
7421
+ 2 b'61' b'616263643132' b'6162636431323233'
7422
+ 1 b'62' b'62717765' b'3331363136323633'
7423
+ 0 b'63' b'627A7863' b'3330363136323633'
7424
+
7425
+ # Example 1: Converts values in "id_col" to bytes and pass it as input to
7426
+ # DataFrame.assign().
7427
+ >>> byte_df = df.assign(byte_col = df.id_col.to_byte())
7428
+ >>> print(byte_df)
7429
+ byte_col varbyte_col blob_col byte_col
7430
+ id_col
7431
+ 2 b'61' b'627A7863' b'6162636431323233...' b'2'
7432
+ 1 b'62' b'616263643132' b'3331363136323633...' b'1'
7433
+ 0 b'63' b'62717765' b'3330363136323633...' b''
7434
+ >>>
7435
+ """
7436
+ arg_validate = []
7437
+ arg_validate.append(["encoding", encoding, True, (str), True])
7438
+
7439
+ # Validate argument types
7440
+ _Validators._validate_function_arguments(arg_validate)
7441
+
7442
+ expression_=self.expression
7443
+ if not isinstance(self.type, VARCHAR):
7444
+ expression_ = self.cast(type_=VARCHAR).expression
7445
+
7446
+ expression_=func.to_bytes(expression_, encoding)
7447
+ return _SQLColumnExpression(expression_, type=VARBYTE())
7448
+
7449
+ @collect_queryband(queryband="DFC_fromByte")
7450
+ def from_byte(self, encoding='base10'):
7451
+ """
7452
+ DESCRIPTION:
7453
+ The function encodes a sequence of bits into a sequence of characters.
7454
+ Note:
7455
+ * By default it converts a sequence of bits to 'base10', which is decimal.
7456
+
7457
+ PARAMETERS:
7458
+ encoding:
7459
+ Optional Argument.
7460
+ Specifies encoding "from_byte" uses to encode the sequence of characters
7461
+ specified by column.
7462
+ The following encodings are supported:
7463
+ * BaseX
7464
+ * BaseY
7465
+ * Base64M (MIME)
7466
+ * ASCII
7467
+ where X is a power of 2 (for example, 2, 8, 16) and
7468
+ Y is not a power of 2 (for example, 10 and 36).
7469
+ Default Value: 'base10'
7470
+ Types: str
7471
+
7472
+ Returns:
7473
+ ColumnExpression.
7474
+
7475
+ EXAMPLES:
7476
+ # Load the data to run the example.
7477
+ >>> load_example_data("dataframe", "bytes_table")
7478
+
7479
+ # Create a DataFrame on 'bytes_table' table.
7480
+ >>> df = DataFrame("bytes_table")
7481
+ >>> print(df)
7482
+ byte_col varbyte_col blob_col
7483
+ id_col
7484
+ 2 b'61' b'616263643132' b'6162636431323233'
7485
+ 1 b'62' b'62717765' b'3331363136323633'
7486
+ 0 b'63' b'627A7863' b'3330363136323633'
7487
+
7488
+ # Example 1: Converts values in "byte_col" to decimal and pass it as input to
7489
+ # DataFrame.assign().
7490
+ >>> decimal_df = df.assign(decimal_col = df.byte_col.from_byte())
7491
+ >>> print(decimal_df)
7492
+ byte_col varbyte_col blob_col decimal_col
7493
+ id_col
7494
+ 2 b'61' b'627A7863' b'6162636431323233...' 97
7495
+ 1 b'62' b'616263643132' b'3331363136323633...' 98
7496
+ 0 b'63' b'62717765' b'3330363136323633...' 99
7497
+ >>>
7498
+ """
7499
+ arg_validate = []
7500
+ arg_validate.append(["encoding", encoding, True, (str), True])
7501
+
7502
+ # Validate argument types
7503
+ _Validators._validate_function_arguments(arg_validate)
7504
+ expression_=func.from_bytes(self.expression, encoding)
7505
+ return _SQLColumnExpression(expression_, type=VARCHAR())
7506
+
7507
+ @collect_queryband(queryband="DFC_hypot")
7508
+ def hypot(self, other):
7509
+ """
7510
+ DESCRIPTION:
7511
+ Function to compute the hypotenuse.
7512
+
7513
+ PARAMETERS:
7514
+ other:
7515
+ Required Argument.
7516
+ Specifies DataFrame column for calculation of hypotenuse.
7517
+ Types: int or float or str or ColumnExpression
7518
+
7519
+ Returns:
7520
+ ColumnExpression
7521
+
7522
+ Examples:
7523
+ # Load the data to run the example.
7524
+ >>> load_example_data("teradataml","titanic")
7525
+
7526
+ # Create a DataFrame on 'titanic' table.
7527
+ >>> titanic = DataFrame.from_table('titanic')
7528
+ >>> df = titanic.select(["passenger", "age", "fare"])
7529
+ >>> print(df)
7530
+ age fare
7531
+ passenger
7532
+ 326 36.0 135.6333
7533
+ 183 9.0 31.3875
7534
+ 652 18.0 23.0000
7535
+ 265 NaN 7.7500
7536
+ 530 23.0 11.5000
7537
+ 122 NaN 8.0500
7538
+ 591 35.0 7.1250
7539
+ 387 1.0 46.9000
7540
+ 734 23.0 13.0000
7541
+ 795 25.0 7.8958
7542
+ >>>
7543
+
7544
+ # Example 1: compute hypotenuse of two columns fare and age.
7545
+ >>> hypot_df = df.assign(hypot_column=df.fare.hypot(titanic.age))
7546
+ >>> print(hypot_df)
7547
+ age fare hypot_column
7548
+ passenger
7549
+ 326 36.0 135.6333 140.329584
7550
+ 183 9.0 31.3875 32.652338
7551
+ 652 18.0 23.0000 29.206164
7552
+ 40 14.0 11.2417 17.954827
7553
+ 774 NaN 7.2250 NaN
7554
+ 366 30.0 7.2500 30.863611
7555
+ 509 28.0 22.5250 35.935715
7556
+ 795 25.0 7.8958 26.217240
7557
+ 61 22.0 7.2292 23.157317
7558
+ 469 NaN 7.7250 NaN
7559
+ >>>
7560
+ """
7561
+ arg_validate = []
7562
+ arg_validate.append(["other", other, False, (int, float, str, ColumnExpression), True])
7563
+
7564
+ # Validate argument types
7565
+ _Validators._validate_function_arguments(arg_validate)
7566
+
7567
+ if isinstance(other, str):
7568
+ other = getattr(self._parent_df, other)
7569
+
7570
+ return ((self * self) + (other * other)).sqrt()
7571
+
7572
+ def format(self, formatter):
7573
+ """
7574
+ DESCRIPTION:
7575
+ Function to format the values in column based on formatter.
7576
+
7577
+ PARAMETERS:
7578
+ formatter:
7579
+ Required Argument.
7580
+ Specifies a variable length string containing formatting characters
7581
+ that define the display format for the data type.
7582
+ Formats can be specified for columns that have character, numeric, byte,
7583
+ DateTime, Period or UDT data types.
7584
+ Note:
7585
+ If the "formatter" does not include a sign character or a signed zoned decimal character,
7586
+ then the sign for a negative value is discarded and the output is displayed as a positive
7587
+ number.
7588
+
7589
+ Types: str
7590
+
7591
+ Following tables provide information about different formatters on numeric and
7592
+ date/time type columns:
7593
+ The formatting characters determine whether the output of numeric data is considered
7594
+ to be monetary or non-monetary. Numeric information is considered to be monetary if the
7595
+ "formatter" contains a currency symbol.
7596
+ Note:
7597
+ Formatting characters are case insensitive.
7598
+ The result of a formatted numeric string is right-justified.
7599
+ +--------------------------------------------------------------------------------------------------+
7600
+ | formatter description |
7601
+ +--------------------------------------------------------------------------------------------------+
7602
+ | G Invokes the currency grouping rule defined by CurrencyGroupingRule in the SDF. |
7603
+ | The value of CurrencyGroupSeparator in the current SDF is copied to the output |
7604
+ | string to separate groups of digits to the left of the currency radix separator|
7605
+ | ,according to the currency grouping rule defined by CurrencyGroupingRule. |
7606
+ | Grouping applies to only the integer portion of floating numbers. |
7607
+ | The G must appear as the first character in a "formatter". |
7608
+ | A currency character, such as L or C, must also appear in the "formatter". |
7609
+ | If the "formatter" does not contain the letter G, no grouping is |
7610
+ | done on the output string. |
7611
+ | The G cannot appear in a "formatter" that contains any of the following |
7612
+ | characters: |
7613
+ | * , |
7614
+ | * . |
7615
+ | * / |
7616
+ | * : |
7617
+ | * S |
7618
+ | Examples: |
7619
+ | +---------------------------------------------------------------+ |
7620
+ | | data formatter result | |
7621
+ | +---------------------------------------------------------------+ |
7622
+ | | -12345678.90 'G--(8)D9(2)' -12,345,678.90 | |
7623
+ | | 1234567890 'G-(10)9' 1.234.567.890 | |
7624
+ | | 9988.77 'GLLZ(I)D9(F)' $9,988.77 | |
7625
+ | +---------------------------------------------------------------+ |
7626
+ +--------------------------------------------------------------------------------------------------+
7627
+ | |
7628
+ | / Insertion characters. |
7629
+ | |
7630
+ | : Copied to output string where they appear in the "formatter". |
7631
+ | |
7632
+ | % The % insertion character cannot appear in a "formatter" that contains S, |
7633
+ | and cannot appear between digits in a "formatter" that contains G, D, or E. |
7634
+ | For example, GL9999D99% is valid, but L9(9)D99%E999 is not. |
7635
+ | |
7636
+ | The / and : insertion characters cannot appear in a "formatter" that |
7637
+ | contains any of the following characters: |
7638
+ | * G |
7639
+ | * D |
7640
+ | * S |
7641
+ | Examples: |
7642
+ | +---------------------------------------------------------------+ |
7643
+ | | data formatter result | |
7644
+ | +---------------------------------------------------------------+ |
7645
+ | | 1234567891 '9(8)/9(2)' 12345678/91 | |
7646
+ | | 1234567891 '9(8):9(2)' 12345678:91 | |
7647
+ | | 1234567891 '9(8)%9(2)' 12345678%91 | |
7648
+ | +---------------------------------------------------------------+ |
7649
+ +--------------------------------------------------------------------------------------------------+
7650
+ | |
7651
+ | B Insertion character. |
7652
+ | A blank space is copied to the output string wherever a B appears in the FORMAT |
7653
+ | phrase. |
7654
+ | B cannot appear between digits in a "formatter" that contains G, D, or E. |
7655
+ | For example, GNB99D99 is valid, but G9(9)BD99 is not. |
7656
+ | Examples: |
7657
+ | +---------------------------------------------------------------+ |
7658
+ | | data formatter result | |
7659
+ | +---------------------------------------------------------------+ |
7660
+ | | 998877.66 '-Z(I)BN' 998878 US Dollars | |
7661
+ | +---------------------------------------------------------------+ |
7662
+ +--------------------------------------------------------------------------------------------------+
7663
+ | |
7664
+ | + Sign characters. |
7665
+ | |
7666
+ | - These characters can appear at the beginning or end of a format string, |
7667
+ | but cannot appear between Z or 9 characters, or between repeated currency |
7668
+ | characters. One sign character places the edit character in a fixed position |
7669
+ | for the output string. |
7670
+ | If two or more of these characters are present, the sign floats (moves to the |
7671
+ | position just to the left of the number as determined by the stated structure). |
7672
+ | Repeated sign characters must appear to the left of formatting characters |
7673
+ | consisting of a combination of the radix and any 9 formatting characters. |
7674
+ | |
7675
+ | If a group of repeated sign characters appears in a "formatter" with a group |
7676
+ | of repeated Z characters or a group of repeated currency characters or both, the|
7677
+ | groups must be contiguous. For example, +++$$$ZZZ. |
7678
+ | One trailing sign character can occur to the right of any digits, and can |
7679
+ | combine with B and one currency character or currency sign. For example, |
7680
+ | G9(I)B+L. The trailing sign character for a mantissa cannot appear to the right |
7681
+ | of the exponent. |
7682
+ | For example, 999D999E+999+ is invalid. |
7683
+ | |
7684
+ | The + translates to + or - as appropriate; the - translates to - or blank. |
7685
+ | Examples: |
7686
+ | +---------------------------------------------------------------+ |
7687
+ | | data formatter result | |
7688
+ | +---------------------------------------------------------------+ |
7689
+ | | 0034567890 '--(8)D9(2)' 34567890.00 | |
7690
+ | | -0034567890 '++(8)D9(2)' -34567890.00 | |
7691
+ | +---------------------------------------------------------------+ |
7692
+ +--------------------------------------------------------------------------------------------------+
7693
+ | $ Currency signs: |
7694
+ | * $ means Dollar sign. |
7695
+ | £ * £ means Pound sterling. |
7696
+ | * ¥ means Yen sign. |
7697
+ | ¥ * ¤ means general currency sign. |
7698
+ | |
7699
+ | ¤ A currency sign cannot appear between Z or 9 formatting characters, or between |
7700
+ | repeated sign characters. |
7701
+ | One currency sign places the edit character in a fixed position for the output |
7702
+ | string. |
7703
+ | If a result is formatted using a single currency sign with Zs for |
7704
+ | zero-suppressed decimal digits (for example, £ZZ9.99), blanks can occur between |
7705
+ | the currency sign and the leftmost nonzero digit of the number. |
7706
+ | |
7707
+ | If the same currency sign appears more than once, the sign floats to the right, |
7708
+ | leaving no blanks between it and the leftmost digit. |
7709
+ | |
7710
+ | A currency sign cannot appear in the same phrase with a currency character, |
7711
+ | such as L. |
7712
+ | If + or - is present, the currency character cannot precede it. |
7713
+ | |
7714
+ | If a group of repeated currency signs appears in a "formatter" with a group of |
7715
+ | repeated sign characters or a group of repeated Z characters or both, the groups|
7716
+ | must be contiguous. For example, +++$$$ZZZ. |
7717
+ | |
7718
+ | One currency sign can occur to the right of any digits, and can combine with B |
7719
+ | and one trailing sign character. For example, G9(I)B+$. |
7720
+ | |
7721
+ | A currency sign cannot appear to the right of an exponent. For example, |
7722
+ | 999D999E+999B+$ is invalid. |
7723
+ | Examples: |
7724
+ | +---------------------------------------------------------------+ |
7725
+ | | data formatter result | |
7726
+ | +---------------------------------------------------------------+ |
7727
+ | | 1 '$(5).9(2)' $1.00 | |
7728
+ | | .069 '$$9.99' $0.07 | |
7729
+ | | 1095 '$$9.99' ****** | |
7730
+ | +---------------------------------------------------------------+ |
7731
+ +--------------------------------------------------------------------------------------------------+
7732
+ | |
7733
+ | L Currency characters. |
7734
+ | The value of the corresponding currency string in the current SDF is copied to |
7735
+ | C the output string whenever the character appears in the "formatter". |
7736
+ | * L in a "formatter" is interpreted as the currency symbol and the value |
7737
+ | N of the Currency string in the SDF is copied to the output string. |
7738
+ | * C in a "formatter" is interpreted as the ISO currency symbol and the |
7739
+ | O value of the ISOCurrency string in the SDF is copied to the output |
7740
+ | string. |
7741
+ | * N in a "formatter" is interpreted as the full currency name, such as Yen |
7742
+ | U or Kroner, and the value of the CurrencyName string in the SDF is copied |
7743
+ | to the output string. |
7744
+ | A * O in a "formatter" is interpreted as the dual currency symbol and the |
7745
+ | value of the DualCurrency string in the SDF is copied to the output |
7746
+ | string. |
7747
+ | * U in a "formatter" is interpreted as the dual ISO currency symbol and |
7748
+ | the value of the DualISOCurrency string in the SDF is copied to the |
7749
+ | output string. |
7750
+ | * A in a "formatter" is interpreted as the full dual currency name, |
7751
+ | such as Euro, and the value of the DualCurrencyName string in the SDF |
7752
+ | is copied to the output string. |
7753
+ | |
7754
+ | A currency character cannot appear between Z or 9 formatting characters, or |
7755
+ | between repeated sign characters. |
7756
+ | If the same currency character appears more than once, the value that is |
7757
+ | copied to the output string floats to the right, leaving no blanks between it |
7758
+ | and the leftmost digit. Repeated characters must be contiguous, and must appear |
7759
+ | to the left formatting characters consisting of a combination of the radix and |
7760
+ | any 9 formatting characters. |
7761
+ | |
7762
+ | If a group of repeated currency characters appears in a "formatter" with a |
7763
+ | group of repeated sign characters or a group of repeated Z characters or both, |
7764
+ | the groups must be contiguous. For example, +++LLLZZZ. |
7765
+ | A currency character cannot appear in the same phrase with any of the following |
7766
+ | characters: |
7767
+ | * other currency characters |
7768
+ | * a currency sign, such as $ or £ |
7769
+ | * , |
7770
+ | * . |
7771
+ | One currency character can occur to the right of any digits, and can combine |
7772
+ | with B and one trailing sign character. For example, G9(I)B+L. |
7773
+ | |
7774
+ | A currency character cannot appear to the right of an exponent. For example, |
7775
+ | 999D999E+999B+L is invalid. |
7776
+ | Examples: |
7777
+ | +----------------------------------------------------------------+ |
7778
+ | | data formatter result | |
7779
+ | +----------------------------------------------------------------+ |
7780
+ | | 9988.77 'GLLZ(I)D9(F)' $9,988.77 | |
7781
+ | | 9988.77 'GCBZ(4)D9(F)' USD 9,988.77 | |
7782
+ | | 9988.77 'GNBZ(4)D9(F)' US Dollars 9,988.77| |
7783
+ | +----------------------------------------------------------------+ |
7784
+ +--------------------------------------------------------------------------------------------------+
7785
+ | |
7786
+ | V Implied decimal point position. |
7787
+ | Internally, the V is recognized as a decimal point to align the numeric value |
7788
+ | properly for calculation. |
7789
+ | Because the decimal point is implied, it does not occupy any space in storage |
7790
+ | and is not included in the output. |
7791
+ | V cannot appear in a "formatter" that contains the 'D' radix symbol or |
7792
+ | the '.' radix character. |
7793
+ | Examples: |
7794
+ | +---------------------------------------------------------------+ |
7795
+ | | data formatter result | |
7796
+ | +---------------------------------------------------------------+ |
7797
+ | | 128.457 '999V99' 12846 | |
7798
+ | +---------------------------------------------------------------+ |
7799
+ +--------------------------------------------------------------------------------------------------+
7800
+ | |
7801
+ | Z Zero-suppressed decimal digit. |
7802
+ | Translates to blank if the digit is zero and preceding digits are also zero. |
7803
+ | |
7804
+ | A Z cannot follow a 9. |
7805
+ | |
7806
+ | Repeated Z characters must appear to the left of any combination of the radix |
7807
+ | and any 9 formatting characters. |
7808
+ | |
7809
+ | The characters to the right of the radix cannot be a combination of 9 and Z |
7810
+ | characters; they must be all 9s or all Zs. If they are all Zs, then the |
7811
+ | characters to the left of the radix must also be all Zs. |
7812
+ | |
7813
+ | If a group of repeated Z characters appears in a "formatter" with a group of |
7814
+ | repeated sign characters, the group of Z characters must immediately follow |
7815
+ | the group of sign characters. For example, --ZZZ. |
7816
+ | Examples: |
7817
+ | +---------------------------------------------------------------+ |
7818
+ | | data formatter result | |
7819
+ | +---------------------------------------------------------------+ |
7820
+ | | 1.3451 'zz.z' 1.3 | |
7821
+ | +---------------------------------------------------------------+ |
7822
+ +--------------------------------------------------------------------------------------------------+
7823
+ | |
7824
+ | 9 Decimal digit (no zero suppress). |
7825
+ | Examples: |
7826
+ | +---------------------------------------------------------------+ |
7827
+ | | data formatter result | |
7828
+ | +---------------------------------------------------------------+ |
7829
+ | | 0034567890 '9999999999' 0034567890 | |
7830
+ | +---------------------------------------------------------------+ |
7831
+ +--------------------------------------------------------------------------------------------------+
7832
+ | |
7833
+ | E For exponential notation. |
7834
+ | |
7835
+ | Defines the end of the mantissa and the start of the exponent. |
7836
+ | |
7837
+ | The exponent consists of one optional + or - sign character followed by one or |
7838
+ | more 9 formatting characters. |
7839
+ | Examples: |
7840
+ | +-------------------------------------------------------------------+ |
7841
+ | | data formatter result | |
7842
+ | +-------------------------------------------------------------------+ |
7843
+ | |1095 '9.99E99' 1.10E03 | |
7844
+ | |1.74524064372835e-2 '-9D99999999999999E-999' 1.74524064372835E-002| |
7845
+ | +-------------------------------------------------------------------+ |
7846
+ +--------------------------------------------------------------------------------------------------+
7847
+ | |
7848
+ | CHAR(n) For more than one occurrence of a character, where CHAR can be one of the |
7849
+ | following: |
7850
+ | * - (sign character) |
7851
+ | * + |
7852
+ | * Z |
7853
+ | * 9 |
7854
+ | * $ |
7855
+ | * ¤ |
7856
+ | * ¥ |
7857
+ | * £ |
7858
+ | and n can be: |
7859
+ | * an integer constant |
7860
+ | * I |
7861
+ | * F |
7862
+ | If n is F, CHAR can only be Z or 9. |
7863
+ | |
7864
+ | If n is an integer constant, the (n) notation means that the character repeats n|
7865
+ | number of times. For the meanings of I and F, see the definitions later in this |
7866
+ | table. |
7867
+ | Examples: |
7868
+ | +---------------------------------------------------------------+ |
7869
+ | | data formatter result | |
7870
+ | +---------------------------------------------------------------+ |
7871
+ | | 0034567890 'z(8)D9(2)' 34567890.00 | |
7872
+ | | -0034567890 '+z(8)D9(2)' -34567890.00 | |
7873
+ | +---------------------------------------------------------------+ |
7874
+ +--------------------------------------------------------------------------------------------------+
7875
+ | |
7876
+ | , Currency grouping character. |
7877
+ | The comma is inserted only if a digit has already appeared. |
7878
+ | |
7879
+ | The comma is interpreted as the currency grouping character regardless of the |
7880
+ | value of the CurrencyGroupSeparator in the SDF. |
7881
+ | |
7882
+ | The comma cannot appear in a "formatter" that contains any of the following |
7883
+ | characters: |
7884
+ | * G |
7885
+ | * D |
7886
+ | * L |
7887
+ | * C |
7888
+ | * O |
7889
+ | * U |
7890
+ | * N |
7891
+ | * A |
7892
+ | * S |
7893
+ | Examples: |
7894
+ | +---------------------------------------------------------------+ |
7895
+ | | data formatter result | |
7896
+ | +---------------------------------------------------------------+ |
7897
+ | | 0034567890 'z(7),z' 3456789,0 | |
7898
+ | +---------------------------------------------------------------+ |
7899
+ +--------------------------------------------------------------------------------------------------+
7900
+ | |
7901
+ | . Currency radix character. |
7902
+ | The period is interpreted as the currency radix character, regardless of the |
7903
+ | value of the CurrencyRadixSeparator in the SDF, and is copied to the output |
7904
+ | string. |
7905
+ | |
7906
+ | The period cannot appear in a "formatter" that contains any of the following |
7907
+ | characters: |
7908
+ | * G |
7909
+ | * D |
7910
+ | * L |
7911
+ | * V |
7912
+ | * C |
7913
+ | * O |
7914
+ | * U |
7915
+ | * N |
7916
+ | * A |
7917
+ | * S |
7918
+ | Examples: |
7919
+ | +---------------------------------------------------------------+ |
7920
+ | | data formatter result | |
7921
+ | +---------------------------------------------------------------+ |
7922
+ | | 0034567890 'z(8).z' 34567890.0 | |
7923
+ | +---------------------------------------------------------------+ |
7924
+ +--------------------------------------------------------------------------------------------------+
7925
+ | |
7926
+ | D Radix symbol. |
7927
+ | The value of CurrencyRadixSeparator in the current SDF is copied to the output |
7928
+ | string whenever a D appears in the "formatter". |
7929
+ | A currency symbol, such as a dollar sign or yen sign, must also appear in the |
7930
+ | "formatter". |
7931
+ | The D cannot appear in a "formatter" that contains any of the following |
7932
+ | characters: |
7933
+ | * , |
7934
+ | * . |
7935
+ | * / |
7936
+ | * : |
7937
+ | * S |
7938
+ | * V |
7939
+ | Examples: |
7940
+ | +---------------------------------------------------------------+ |
7941
+ | | data formatter result | |
7942
+ | +---------------------------------------------------------------+ |
7943
+ | | 0034567890 '--(8)D9(2)' 34567890.00 | |
7944
+ | +---------------------------------------------------------------+ |
7945
+ +--------------------------------------------------------------------------------------------------+
7946
+ | |
7947
+ | I The number of characters needed to display the integer portion of numeric and |
7948
+ | integer data. |
7949
+ | |
7950
+ | I can only appear as n in the CHAR(n) character sequence (see the definition of |
7951
+ | CHAR(n) earlier in this table), where CHAR can be: |
7952
+ | * - (sign character) |
7953
+ | * + |
7954
+ | * Z |
7955
+ | * 9 |
7956
+ | * $ |
7957
+ | * ¤ |
7958
+ | * ¥ |
7959
+ | * £ |
7960
+ | CHAR(I) can only appear once, and is valid for the following types: |
7961
+ | * DECIMAL/NUMERIC |
7962
+ | * BYTEINT |
7963
+ | * SMALLINT |
7964
+ | * INTEGER |
7965
+ | * BIGINT |
7966
+ | The value of I is resolved during the formatting of the monetary numeric data. |
7967
+ | The value is obtained from the declaration of the data type. For example, I is |
7968
+ | eight for the DECIMAL(10,2) type. |
7969
+ | |
7970
+ | If CHAR(F) also appears in the "formatter", CHAR(F) must appear to the right of |
7971
+ | CHAR(I), and one of the following characters must appear between CHAR(I) and |
7972
+ | CHAR(F): |
7973
+ | * D |
7974
+ | * . |
7975
+ | * V |
7976
+ | Examples: |
7977
+ | +---------------------------------------------------------------+ |
7978
+ | | data formatter result | |
7979
+ | +---------------------------------------------------------------+ |
7980
+ | | 000000.42 'Z(I)D9(F)' .42 | |
7981
+ | +---------------------------------------------------------------+ |
7982
+ +--------------------------------------------------------------------------------------------------+
7983
+ | F The number of characters needed to display the fractional portion of |
7984
+ | numeric data. |
7985
+ | F can only appear as n in the CHAR(n) character sequence |
7986
+ | (see the definition of CHAR(n) earlier in this table), |
7987
+ | where CHAR can be: |
7988
+ | * Z |
7989
+ | * 9 |
7990
+ | CHAR(F) is valid for the DECIMAL/NUMERIC data type. |
7991
+ | |
7992
+ | The value of F is resolved during the formatting of the monetary numeric data. |
7993
+ | The value is obtained from the declaration of the data type. For example, |
7994
+ | F is two for the DECIMAL(10,2) type. |
7995
+ | |
7996
+ | A value of zero for F displays no fractional precision for the data; however, |
7997
+ | the value of CurrencyRadixSeparator in the current SDF is copied to the output |
7998
+ | string if a D appears in the "formatter". |
7999
+ | |
8000
+ | CHAR(F) can appear only once. If CHAR(I) also appears in the "formatter", |
8001
+ | CHAR(F) must appear to the right of CHAR(I), and one of the following characters|
8002
+ | must appear between CHAR(I) and CHAR(F): |
8003
+ | * D |
8004
+ | * . |
8005
+ | * V |
8006
+ | Examples: |
8007
+ | +---------------------------------------------------------------+ |
8008
+ | | data formatter result | |
8009
+ | +---------------------------------------------------------------+ |
8010
+ | | 000000.42 'Z(I)D9(F)' .42 | |
8011
+ | +---------------------------------------------------------------+ |
8012
+ +--------------------------------------------------------------------------------------------------+
8013
+ | |
8014
+ | - Dash character. |
8015
+ | Used when storing numbers such as telephone numbers, social security numbers, |
8016
+ | and account numbers. |
8017
+ | |
8018
+ | A dash appears after the first digit and before the last digit, and is treated |
8019
+ | as an embedded dash rather than a sign character. A dash cannot follow any of |
8020
+ | these characters: |
8021
+ | * . |
8022
+ | * , |
8023
+ | * + |
8024
+ | * G |
8025
+ | * N |
8026
+ | * A |
8027
+ | * C |
8028
+ | * L |
8029
+ | * O |
8030
+ | * U |
8031
+ | * D |
8032
+ | * V |
8033
+ | * S |
8034
+ | * E |
8035
+ | * $ |
8036
+ | * ¤ |
8037
+ | * £ |
8038
+ | * ¥ |
8039
+ | Examples: |
8040
+ | +---------------------------------------------------------------+ |
8041
+ | | data formatter result | |
8042
+ | +---------------------------------------------------------------+ |
8043
+ | | 0034567890 '--(8)D9(2)' 34567890.00 | |
8044
+ | +---------------------------------------------------------------+ |
8045
+ +--------------------------------------------------------------------------------------------------+
8046
+ | |
8047
+ | S Signed Zoned Decimal character. |
8048
+ | Defines signed zoned decimal input as a numeric data type and displays numeric |
8049
+ | output as signed zone decimal character strings. |
8050
+ | |
8051
+ | When converting signed zone decimal input to a numeric data type, the final |
8052
+ | character is converted as follows: |
8053
+ | * Last character = { or 0, then the numeric conversion is n … 0 |
8054
+ | * Last character = A or 1, then the numeric conversion is n … 1 |
8055
+ | * Last character = B or 2, then the numeric conversion is n … 2 |
8056
+ | * Last character = C or 3, then the numeric conversion is n … 3 |
8057
+ | * Last character = D or 4, then the numeric conversion is n … 4 |
8058
+ | * Last character = E or 5, then the numeric conversion is n … 5 |
8059
+ | * Last character = F or 6, then the numeric conversion is n … 6 |
8060
+ | * Last character = G or 7, then the numeric conversion is n … 7 |
8061
+ | * Last character = H or 8, then the numeric conversion is n … 8 |
8062
+ | * Last character = I or 9, then the numeric conversion is n … 9 |
8063
+ | * Last character = }, then the numeric conversion is -n … 0 |
8064
+ | * Last character = J, then the numeric conversion is -n … 1 |
8065
+ | * Last character = K, then the numeric conversion is -n … 2 |
8066
+ | * Last character = L, then the numeric conversion is -n … 3 |
8067
+ | * Last character = M, then the numeric conversion is -n … 4 |
8068
+ | * Last character = N, then the numeric conversion is -n … 5 |
8069
+ | * Last character = O, then the numeric conversion is -n … 6 |
8070
+ | * Last character = P, then the numeric conversion is -n … 7 |
8071
+ | * Last character = Q, then the numeric conversion is -n … 8 |
8072
+ | * Last character = R, then the numeric conversion is -n … 9 |
8073
+ | |
8074
+ | When displaying numeric output as signed zone decimal character strings, |
8075
+ | the final character indicates the sign, as follows: |
8076
+ | |
8077
+ | If the final data digit is 0, then the final result digit is displayed as: |
8078
+ | * { if the result is a positive number |
8079
+ | * } if the result is a negative number |
8080
+ | If the final data digit is 1, then the final result digit is displayed as: |
8081
+ | * A if the result is a positive number |
8082
+ | * J if the result is a negative number |
8083
+ | If the final data digit is 2, then the final result digit is displayed as: |
8084
+ | * B if the result is a positive number |
8085
+ | * K if the result is a negative number |
8086
+ | If the final data digit is 3, then the final result digit is displayed as: |
8087
+ | * C if the result is a positive number |
8088
+ | * L if the result is a negative number |
8089
+ | If the final data digit is 4, then the final result digit is displayed as: |
8090
+ | * D if the result is a positive number |
8091
+ | * M if the result is a negative number |
8092
+ | If the final data digit is 5, then the final result digit is displayed as: |
8093
+ | * E if the result is a positive number |
8094
+ | * N if the result is a negative number |
8095
+ | If the final data digit is 6, then the final result digit is displayed as: |
8096
+ | * F if the result is a positive number |
8097
+ | * O if the result is a negative number |
8098
+ | If the final data digit is 7, then the final result digit is displayed as: |
8099
+ | * G if the result is a positive number |
8100
+ | * P if the result is a negative number |
8101
+ | If the final data digit is 8, then the final result digit is displayed as: |
8102
+ | * H if the result is a positive number |
8103
+ | * Q if the result is a negative number |
8104
+ | If the final data digit is 9, then the final result digit is displayed as: |
8105
+ | * I if the result is a positive number |
8106
+ | * R if the result is a negative number |
8107
+ | |
8108
+ | The S must follow the last decimal digit in the "formatter". It cannot appear |
8109
+ | in the same phrase with the following characters. |
8110
+ | * % |
8111
+ | * + |
8112
+ | * : |
8113
+ | * / |
8114
+ | * - |
8115
+ | * , |
8116
+ | * . |
8117
+ | * Z |
8118
+ | * E |
8119
+ | * D |
8120
+ | * G |
8121
+ | * F |
8122
+ | * N |
8123
+ | * A |
8124
+ | * C |
8125
+ | * L |
8126
+ | * U |
8127
+ | * O |
8128
+ | * $ |
8129
+ | * ¤ |
8130
+ | * £ |
8131
+ | * ¥ |
8132
+ | Examples: |
8133
+ | +---------------------------------------------------------------+ |
8134
+ | | data formatter result | |
8135
+ | +---------------------------------------------------------------+ |
8136
+ | | -1095 '99999S' 0109N | |
8137
+ | | 1095 '99999S' 0109E | |
8138
+ | +---------------------------------------------------------------+ |
8139
+ +--------------------------------------------------------------------------------------------------+
8140
+
8141
+ A "formatter" that defines fewer positions than are required by numeric values causes
8142
+ the data to be returned as follows:
8143
+ * Asterisks appear when the integer portion cannot be accommodated.
8144
+ * When only the integer portion can be accommodated, any digits to the right of the least
8145
+ significant digit are either truncated (for an integer value) or rounded (for a floating,
8146
+ number, or decimal value).
8147
+
8148
+ Rounding is based on “Round to the Nearest” mode, as illustrated by the following process.
8149
+ * Let B represent the actual result.
8150
+ * Let A and C represent the nearest bracketing values that can be represented, such that
8151
+ A < B < C.
8152
+ * The determination as to whether A or C is the represented result is made as follows:
8153
+ * When possible, the result is the value nearest to B.
8154
+ * If A and C are equidistant (for example, the fractional part is exactly .5),
8155
+ the result is the even number.
8156
+
8157
+
8158
+ * Date type FORMAT to SPECIFIC FORMAT
8159
+ The date and time formatting characters in a "formatter" determine the output of
8160
+ DATE, TIME, and TIMESTAMP teradatasqlalchemy types information.
8161
+
8162
+ Following tables provide information about different formatters on
8163
+ date type columns:
8164
+ +--------------------------------------------------------------------------------------------------+
8165
+ | formatter description |
8166
+ +--------------------------------------------------------------------------------------------------+
8167
+ | MMMM Represent the month as a full month name, such as |
8168
+ | November. |
8169
+ | M4 Valid names are specified by LongMonths in the |
8170
+ | current SDF. |
8171
+ | M4 is equivalent to MMMM, and is preferable to allow for a|
8172
+ | shorter, unambiguous format string. |
8173
+ | |
8174
+ | You cannot specify M4 in a format that also has M3 or MM. |
8175
+ | Examples: |
8176
+ | +-------------------------------------------------------+ |
8177
+ | | data formatter result | |
8178
+ | +-------------------------------------------------------+ |
8179
+ | | 19/01/16 'M4' JANUARY | |
8180
+ | +-------------------------------------------------------+ |
8181
+ +--------------------------------------------------------------------------------------------------+
8182
+ | |
8183
+ | MMM Represent the month as an abbreviated month name, such as |
8184
+ | 'Apr' for April. |
8185
+ | M3 Valid names are specified by ShortMonths in the current |
8186
+ | SDF. |
8187
+ | |
8188
+ | M3 is equivalent to MMM, and is preferable to allow for a |
8189
+ | shorter, unambiguous format string. |
8190
+ | |
8191
+ | You cannot specify MMM in a format that also has MM. |
8192
+ | Examples: |
8193
+ | +-------------------------------------------------------+ |
8194
+ | | data formatter result | |
8195
+ | +-------------------------------------------------------+ |
8196
+ | | 19/01/16 'M4' Jan | |
8197
+ | +-------------------------------------------------------+ |
8198
+ +--------------------------------------------------------------------------------------------------+
8199
+ | |
8200
+ | MM Represent the month as two numeric digits. |
8201
+ | Examples: |
8202
+ | +-------------------------------------------------------+ |
8203
+ | | data formatter result | |
8204
+ | +-------------------------------------------------------+ |
8205
+ | | 19/01/16 'MM' 01 | |
8206
+ | +-------------------------------------------------------+ |
8207
+ +--------------------------------------------------------------------------------------------------+
8208
+ | |
8209
+ | DDD Represent the date as the sequential day in the year, |
8210
+ | using three numeric digits, such as '032' as February 1. |
8211
+ | |
8212
+ | D3 D3 is equivalent to DDD, and allows for a shorter format |
8213
+ | string. |
8214
+ | You cannot specify DDD or D3 in a format that also has DD.|
8215
+ | Examples: |
8216
+ | +-------------------------------------------------------+ |
8217
+ | | data formatter result | |
8218
+ | +-------------------------------------------------------+ |
8219
+ | | 19/02/13 'D3' 044 | |
8220
+ | +-------------------------------------------------------+ |
8221
+ +--------------------------------------------------------------------------------------------------+
8222
+ | |
8223
+ | DD Represent the day of the month as two numeric digits. |
8224
+ | Examples: |
8225
+ | +-------------------------------------------------------+ |
8226
+ | | data formatter result | |
8227
+ | +-------------------------------------------------------+ |
8228
+ | | 19/01/16 'DD' 16 | |
8229
+ | +-------------------------------------------------------+ |
8230
+ +--------------------------------------------------------------------------------------------------+
8231
+ | |
8232
+ | YYYY Represent the year as four numeric digits. |
8233
+ | |
8234
+ | Y4 Y4 is equivalent to YYYY, and allows for a shorter format |
8235
+ | string. |
8236
+ | |
8237
+ | You cannot specify YYYY or Y4 in a format that also has |
8238
+ | YY. |
8239
+ | Examples: |
8240
+ | +-------------------------------------------------------+ |
8241
+ | | data formatter result | |
8242
+ | +-------------------------------------------------------+ |
8243
+ | | 19/01/16 'Y4' 2019 | |
8244
+ | +-------------------------------------------------------+ |
8245
+ +--------------------------------------------------------------------------------------------------+
8246
+ | |
8247
+ | YY Represent the year as two numeric digits. |
8248
+ | Examples: |
8249
+ | +-------------------------------------------------------+ |
8250
+ | | data formatter result | |
8251
+ | +-------------------------------------------------------+ |
8252
+ | | 19/01/16 'YY' 19 | |
8253
+ | +-------------------------------------------------------+ |
8254
+ +--------------------------------------------------------------------------------------------------+
8255
+ | |
8256
+ | EEEE Represent the day of the week using the full name, |
8257
+ | such as Thursday. |
8258
+ | |
8259
+ | E4 Valid names are specified by LongDays in the current SDF. |
8260
+ | |
8261
+ | E4 is equivalent to EEEE, and allows for a shorter format |
8262
+ | string. |
8263
+ | Examples: |
8264
+ | +-------------------------------------------------------+ |
8265
+ | | data formatter result | |
8266
+ | +-------------------------------------------------------+ |
8267
+ | | 19/01/16 'E4' Wednesday | |
8268
+ | +-------------------------------------------------------+ |
8269
+ +--------------------------------------------------------------------------------------------------+
8270
+ | |
8271
+ | EEE Represent the day of the week as an abbreviated name, such|
8272
+ | as 'Mon' for Monday. |
8273
+ | E3 Valid abbreviations are specified by ShortDays in the |
8274
+ | current SDF. |
8275
+ | E3 is equivalent to EEE, and allows for a shorter format |
8276
+ | string. |
8277
+ | Examples: |
8278
+ | +-------------------------------------------------------+ |
8279
+ | | data formatter result | |
8280
+ | +-------------------------------------------------------+ |
8281
+ | | 19/01/16 'E3' Wed | |
8282
+ | +-------------------------------------------------------+ |
8283
+ +--------------------------------------------------------------------------------------------------+
8284
+ | |
8285
+ | / Slash separator. |
8286
+ | Copied to output string where it appears in the FORMAT |
8287
+ | phrase. |
8288
+ | This is the default separator for Teradata dates. |
8289
+ | Examples: |
8290
+ | +-------------------------------------------------------+ |
8291
+ | | data formatter result | |
8292
+ | +-------------------------------------------------------+ |
8293
+ | | 19/01/16 'M4/E3' January/Wed | |
8294
+ | +-------------------------------------------------------+ |
8295
+ +--------------------------------------------------------------------------------------------------+
8296
+ | |
8297
+ | B Blank representation separator. |
8298
+ | |
8299
+ | b Use this instead of a space to represent a blank. |
8300
+ | Examples: |
8301
+ | +-------------------------------------------------------+ |
8302
+ | | data formatter result | |
8303
+ | +-------------------------------------------------------+ |
8304
+ | | 19/01/16 'M4BE3' JANUARY Wed | |
8305
+ | +-------------------------------------------------------+ |
8306
+ +--------------------------------------------------------------------------------------------------+
8307
+ | |
8308
+ | , Comma separator. |
8309
+ | Copied to output string where it appears in the FORMAT |
8310
+ | phrase. |
8311
+ | Examples: |
8312
+ | +-------------------------------------------------------+ |
8313
+ | | data formatter result | |
8314
+ | +-------------------------------------------------------+ |
8315
+ | | 19/01/16 'M4,E3' January,Wed | |
8316
+ | +-------------------------------------------------------+ |
8317
+ +--------------------------------------------------------------------------------------------------+
8318
+ | |
8319
+ | : Colon separator. |
8320
+ | Copied to output string where it appears in the FORMAT |
8321
+ | phrase. |
8322
+ | Examples: |
8323
+ | +-------------------------------------------------------+ |
8324
+ | | data formatter result | |
8325
+ | +-------------------------------------------------------+ |
8326
+ | | 19/01/16 'M4:E3' January:Wed | |
8327
+ | +-------------------------------------------------------+ |
8328
+ +--------------------------------------------------------------------------------------------------+
8329
+ | |
8330
+ | . Period separator. |
8331
+ | Copied to output string where it appears in the FORMAT |
8332
+ | phrase. |
8333
+ | Examples: |
8334
+ | +-------------------------------------------------------+ |
8335
+ | | data formatter result | |
8336
+ | +-------------------------------------------------------+ |
8337
+ | | 19/01/16 'M4.E3' January.Wed | |
8338
+ | +-------------------------------------------------------+ |
8339
+ +--------------------------------------------------------------------------------------------------+
8340
+ | |
8341
+ | - Dash separator. |
8342
+ | Copied to output string where it appears in the FORMAT |
8343
+ | phrase. |
8344
+ | This is the default separator for ANSI dates. |
8345
+ | Examples: |
8346
+ | +-------------------------------------------------------+ |
8347
+ | | data formatter result | |
8348
+ | +-------------------------------------------------------+ |
8349
+ | | 19/01/16 'M4-E3' January-Wed | |
8350
+ | +-------------------------------------------------------+ |
8351
+ +--------------------------------------------------------------------------------------------------+
8352
+ | |
8353
+ | 9 Decimal digit. |
8354
+ | This formatting character can only be used with separators|
8355
+ | less than 0x009F. |
8356
+ | |
8357
+ | The 9(n) notation can be used for more than one occurrence|
8358
+ | of this character, where n is an integer constant and |
8359
+ | means that the '9' repeats n number of times. |
8360
+ | |
8361
+ | This formatting character is for DATE and PERIOD(DATE) |
8362
+ | types only and cannot appear as a date formatting |
8363
+ | character for PERIOD(TIMESTAMP) and TIMESTAMP types. |
8364
+ | Examples: |
8365
+ | +-------------------------------------------------------+ |
8366
+ | | data formatter result | |
8367
+ | +-------------------------------------------------------+ |
8368
+ | | 19/01/16 '999999' 190116 | |
8369
+ | +-------------------------------------------------------+ |
8370
+ +--------------------------------------------------------------------------------------------------+
8371
+ | |
8372
+ | Z Zero-suppressed decimal digit. |
8373
+ | This formatting character can only be used with separators|
8374
+ | less than 0x009F. |
8375
+ | |
8376
+ | The Z(n) notation can be used for more than one occurrence|
8377
+ | of this character, where n is an integer constant and |
8378
+ | means that the 'Z' repeats n number of times. |
8379
+ | |
8380
+ | This formatting character is for DATE and PERIOD(DATE) |
8381
+ | types only and cannot appear as a date formatting |
8382
+ | character for PERIOD(TIMESTAMP) and TIMESTAMP types. |
8383
+ | Examples: |
8384
+ | +-------------------------------------------------------+ |
8385
+ | | data formatter result | |
8386
+ | +-------------------------------------------------------+ |
8387
+ | | 19/01/16 'ZZZZZZ' 190116 | |
8388
+ | +-------------------------------------------------------+ |
8389
+ +--------------------------------------------------------------------------------------------------+
8390
+
8391
+ Following tables provide information about different formatters on
8392
+ time type columns:
8393
+ +--------------------------------------------------------------------------------------------------+
8394
+ | formatter description |
8395
+ +--------------------------------------------------------------------------------------------------+
8396
+ | |
8397
+ | HH Represent the hour as two numeric digits. |
8398
+ | Examples: |
8399
+ | +-------------------------------------------------------+ |
8400
+ | | data formatter result | |
8401
+ | +-------------------------------------------------------+ |
8402
+ | | 2020-07-01 08:00:00.000000 'HH' 08 | |
8403
+ | +-------------------------------------------------------+ |
8404
+ +--------------------------------------------------------------------------------------------------+
8405
+ | |
8406
+ | MI Represent the minute as two numeric digits. |
8407
+ | Examples: |
8408
+ | +-------------------------------------------------------+ |
8409
+ | | data formatter result | |
8410
+ | +-------------------------------------------------------+ |
8411
+ | | 2020-07-01 13:20:53.64+03:00: 'HH:MI' 13:20 | |
8412
+ | +-------------------------------------------------------+ |
8413
+ +--------------------------------------------------------------------------------------------------+
8414
+ | |
8415
+ | SS Represent the second as two numeric digits. |
8416
+ | Examples: |
8417
+ | +-------------------------------------------------------+ |
8418
+ | | data formatter result | |
8419
+ | +-------------------------------------------------------+ |
8420
+ | | 2020-07-01 13:20:53.64+03:00: 'HH.MI.SS' 13.20.53 | |
8421
+ | +-------------------------------------------------------+ |
8422
+ +--------------------------------------------------------------------------------------------------+
8423
+ | |
8424
+ | S(n) Number of fractional seconds. |
8425
+ | |
8426
+ | S(F) Replace n with a number between 0 and 6, or use F for the |
8427
+ | number of characters needed to display the fractional |
8428
+ | seconds precision. |
8429
+ | |
8430
+ | The value of F is resolved during the formatting of the |
8431
+ | TIME or TIMESTAMP data. The value is obtained from the |
8432
+ | fractional seconds precision in the declaration of the |
8433
+ | data type. For example, F is two for the TIME(2) type. |
8434
+ | |
8435
+ | A value of zero for F displays no radix symbol and no |
8436
+ | fractional precision for the data. |
8437
+ | The S(F) formatting characters must follow a D formatting |
8438
+ | character or a . separator character. |
8439
+ | |
8440
+ | A value of n that is less than the PERIOD(TIME), |
8441
+ | PERIOD(TIMESTAMP), TIME or TIMESTAMP fractional second |
8442
+ | precision produces an error. |
8443
+ | Examples: |
8444
+ | +-------------------------------------------------------+ |
8445
+ | | data formatter result | |
8446
+ | +-------------------------------------------------------+ |
8447
+ | |2020-07-01 13:20:53.64+03:00:'HH:MI:SSDS(F)'13:20:53.64| |
8448
+ | +-------------------------------------------------------+ |
8449
+ +--------------------------------------------------------------------------------------------------+
8450
+ | |
8451
+ | D Radix symbol. |
8452
+ | The value of RadixSeparator in the current SDF is copied |
8453
+ | to the output string whenever a D appears in the FORMAT |
8454
+ | phrase. |
8455
+ | |
8456
+ | Separator characters, such as . or :, can also appear in |
8457
+ | the "formatter", but only if they do not match the value |
8458
+ | of RadixSeparator. |
8459
+ | Examples: |
8460
+ | +-------------------------------------------------------+ |
8461
+ | | data formatter result | |
8462
+ | +-------------------------------------------------------+ |
8463
+ | |2020-07-01 13:20:53.64+03:00:'HH:MI:SSDS(F)'13:20:53.64| |
8464
+ | +-------------------------------------------------------+ |
8465
+ +--------------------------------------------------------------------------------------------------+
8466
+ | |
8467
+ | T Represent time in 12-hour format instead of 24-hour |
8468
+ | format. The appropriate time of day, as specified by AMPM |
8469
+ | in the current SDF is copied to the output string |
8470
+ | where a T appears in the "formatter". |
8471
+ | |
8472
+ | Examples: |
8473
+ | +-------------------------------------------------------+ |
8474
+ | | data formatter result | |
8475
+ | +-------------------------------------------------------+ |
8476
+ | |2020-07-01 13:20:53.64+03:00:'HH:MI:SSBT'01:20:53 Nachm| |
8477
+ | | (Nachm is German for PM.)| |
8478
+ | +-------------------------------------------------------+ |
8479
+ +--------------------------------------------------------------------------------------------------+
8480
+ | |
8481
+ | Z Time zone. |
8482
+ | The Z controls the placement of the time zone in the |
8483
+ | output of PERIOD(TIME), PERIOD(TIMESTAMP), TIME and |
8484
+ | TIMESTAMP data, and can only appear at the beginning or |
8485
+ | end of the time formatting characters. |
8486
+ | |
8487
+ | For example, the following statement uses a "formatter" |
8488
+ | that includes a Z before the time formatting characters: |
8489
+ | |
8490
+ | SELECT CURRENT_TIMESTAMP |
8491
+ | (FORMAT 'YYYY-MM-DDBZBHH:MI:SS.S(6)'); |
8492
+ | If the PERIOD(TIME), PERIOD(TIMESTAMP), TIME or |
8493
+ | TIMESTAMP teradatasqlalchemy types contains time zone |
8494
+ | data, the time zone is copied to the output string. |
8495
+ | The time zone format is +HH:MI or -HH:MI, depending |
8496
+ | on the time zone hour displacement. |
8497
+ | Examples: |
8498
+ | +------------------------------------------------------------+|
8499
+ | | data formatter result ||
8500
+ | +------------------------------------------------------------+|
8501
+ | |2020-07-01 13:20:53.64+03:00: 'HH:MI:SSDS(F)Z' 13:20:53.64||
8502
+ | | +03:00||
8503
+ | +------------------------------------------------------------+|
8504
+ +--------------------------------------------------------------------------------------------------+
8505
+ | |
8506
+ | : Colon separator. |
8507
+ | Copied to output string where it appears in the FORMAT |
8508
+ | phrase. This is the default separator for ANSI time. |
8509
+ | |
8510
+ | This character cannot appear in the "formatter" if the |
8511
+ | value of RadixSeparator in the current SDF is a colon. |
8512
+ | Examples: |
8513
+ | +-------------------------------------------------------+ |
8514
+ | | data formatter result | |
8515
+ | +-------------------------------------------------------+ |
8516
+ | | 2020-07-01 13:20:53.64+03:00: 'HH:MI' 13:20 | |
8517
+ | +-------------------------------------------------------+ |
8518
+ +--------------------------------------------------------------------------------------------------+
8519
+ | |
8520
+ | . Period separator. |
8521
+ | This can also be used to indicate the fractional seconds. |
8522
+ | |
8523
+ | Copied to output string where it appears in the FORMAT |
8524
+ | phrase. |
8525
+ | |
8526
+ | This character cannot appear in the "formatter" if the |
8527
+ | value of RadixSeparator in the current SDF is a period. |
8528
+ | Examples: |
8529
+ | +-------------------------------------------------------+ |
8530
+ | | data formatter result | |
8531
+ | +-------------------------------------------------------+ |
8532
+ | | 2020-07-01 13:20:53.64+03:00: 'HH.MI.SS' 13.20.53 | |
8533
+ | +-------------------------------------------------------+ |
8534
+ +--------------------------------------------------------------------------------------------------+
8535
+ | |
8536
+ | - Dash separator. |
8537
+ | Copied to output string where it appears in the FORMAT |
8538
+ | phrase. |
8539
+ | Examples: |
8540
+ | +-------------------------------------------------------+ |
8541
+ | | data formatter result | |
8542
+ | +-------------------------------------------------------+ |
8543
+ | | 2020-07-01 13:20:53.64+03:00: 'HH-MI' 13-20 | |
8544
+ | +-------------------------------------------------------+ |
8545
+ +--------------------------------------------------------------------------------------------------+
8546
+ | |
8547
+ | h Hour separator. |
8548
+ | A lowercase h character is copied to the output string. |
8549
+ | |
8550
+ | The h formatting character must follow the HH formatting |
8551
+ | characters. |
8552
+ | |
8553
+ | This character cannot appear in the "formatter" if the |
8554
+ | value of RadixSeparator in the current SDF is a lowercase |
8555
+ | h character. |
8556
+ | Examples: |
8557
+ | +-------------------------------------------------------+ |
8558
+ | | data formatter result | |
8559
+ | +-------------------------------------------------------+ |
8560
+ | | 2020-07-01 13:20:53.64+03:00: 'HHhMImSSs' 13h20m53s| |
8561
+ | +-------------------------------------------------------+ |
8562
+ +--------------------------------------------------------------------------------------------------+
8563
+ | |
8564
+ | m Minute separator. |
8565
+ | A lowercase m character is copied to the output string. |
8566
+ | |
8567
+ | The m formatting character must follow the MI formatting |
8568
+ | characters. |
8569
+ | |
8570
+ | This character cannot appear in the "formatter" if the |
8571
+ | value of RadixSeparator in the current SDF is a lowercase |
8572
+ | m character. |
8573
+ | Examples: |
8574
+ | +-------------------------------------------------------+ |
8575
+ | | data formatter result | |
8576
+ | +-------------------------------------------------------+ |
8577
+ | | 2020-07-01 13:20:53.64+03:00: 'HHhMImSSs' 13h20m53s| |
8578
+ | +-------------------------------------------------------+ |
8579
+ +--------------------------------------------------------------------------------------------------+
8580
+ | |
8581
+ | s Second separator. |
8582
+ | A lowercase s character is copied to the output string. |
8583
+ | |
8584
+ | The s formatting character must follow SS or SSDS(F) |
8585
+ | formatting characters. |
8586
+ | |
8587
+ | This character cannot appear in the "formatter" if the |
8588
+ | value of RadixSeparator in the current SDF is a lowercase |
8589
+ | s character. |
8590
+ | Examples: |
8591
+ | +-------------------------------------------------------+ |
8592
+ | | data formatter result | |
8593
+ | +-------------------------------------------------------+ |
8594
+ | | 2020-07-01 13:20:53.64+03:00: 'HHhMImSSs' 13h20m53s| |
8595
+ | +-------------------------------------------------------+ |
8596
+ +--------------------------------------------------------------------------------------------------+
8597
+ | |
8598
+ | B Blank representation separator. |
8599
+ | |
8600
+ | b Use this instead of a space to represent a blank. |
8601
+ | |
8602
+ | This character cannot appear in the "formatter" if the |
8603
+ | value of RadixSeparator in the current SDF is a blank. |
8604
+ | Examples: |
8605
+ | +--------------------------------------------------------------+ |
8606
+ | | data formatter result | |
8607
+ | +--------------------------------------------------------------+ |
8608
+ | | 2020-07-01 13:20:53.64+03:00: 'MM/DD/YYBHH:MIBT' 07/01/20 | |
8609
+ | | 01:20 PM | |
8610
+ | +--------------------------------------------------------------+ |
8611
+ +--------------------------------------------------------------------------------------------------+
8612
+
8613
+ RETURNS:
8614
+ ColumnExpression.
8615
+
8616
+ EXAMPLES:
8617
+ # Load the data to run the example.
8618
+ >>> load_example_data("dataframe", "admissions_train")
8619
+ >>> load_example_data("uaf", "stock_data")
8620
+
8621
+ # Create a DataFrame on 'admissions_train' table.
8622
+ >>> admissions_train=DataFrame("admissions_train")
8623
+ >>> admissions_train
8624
+ masters gpa stats programming admitted
8625
+ id
8626
+ 34 yes 3.85 Advanced Beginner 0
8627
+ 32 yes 3.46 Advanced Beginner 0
8628
+ 11 no 3.13 Advanced Advanced 1
8629
+ 30 yes 3.79 Advanced Novice 0
8630
+ 28 no 3.93 Advanced Advanced 1
8631
+ 16 no 3.70 Advanced Advanced 1
8632
+ 9 no 3.82 Advanced Advanced 1
8633
+ 13 no 4.00 Advanced Novice 1
8634
+ 15 yes 4.00 Advanced Advanced 1
8635
+ 17 no 3.83 Advanced Advanced 1
8636
+ >>>
8637
+
8638
+ # Example 1: Round the 'age' column upto 1 decimal values.
8639
+ >>> format_df = admissions_train.assign(format_column=admissions_train.gpa.format("zz.z"))
8640
+ >>> format_df
8641
+ masters gpa stats programming admitted format_column
8642
+ id
8643
+ 38 yes 2.65 Advanced Beginner 1 2.6
8644
+ 7 yes 2.33 Novice Novice 1 2.3
8645
+ 26 yes 3.57 Advanced Advanced 1 3.6
8646
+ 5 no 3.44 Novice Novice 0 3.4
8647
+ 3 no 3.70 Novice Beginner 1 3.7
8648
+ 22 yes 3.46 Novice Beginner 0 3.5
8649
+ 24 no 1.87 Advanced Novice 1 1.9
8650
+ 36 no 3.00 Advanced Novice 0 3.0
8651
+ 19 yes 1.98 Advanced Advanced 0 2.0
8652
+ 40 yes 3.95 Novice Beginner 0 4.0
8653
+ >>>
8654
+
8655
+
8656
+
8657
+ # Create a DataFrame on 'stock_data' table.
8658
+ >>> stock_data=DataFrame("stock_data")
8659
+ >>> stock_data
8660
+ seq_no timevalue magnitude
8661
+ data_set_id
8662
+ 556 3 19/01/16 61.080
8663
+ 556 5 19/01/30 63.810
8664
+ 556 6 19/02/06 63.354
8665
+ 556 7 19/02/13 63.871
8666
+ 556 9 19/02/27 61.490
8667
+ 556 10 19/03/06 61.524
8668
+ 556 8 19/02/20 61.886
8669
+ 556 4 19/01/23 63.900
8670
+ 556 2 19/01/09 61.617
8671
+ 556 1 19/01/02 60.900
8672
+ >>>
8673
+
8674
+ # Example 2: change the format of 'timevalue' column.
8675
+ >>> format_df = stock_data.assign(format_column=stock_data.timevalue.format('MMMBDD,BYYYY'))
8676
+ >>> format_df
8677
+ seq_no timevalue magnitude format_column
8678
+ data_set_id
8679
+ 556 3 19/01/16 61.080 Jan 16, 2019
8680
+ 556 5 19/01/30 63.810 Jan 30, 2019
8681
+ 556 6 19/02/06 63.354 Feb 06, 2019
8682
+ 556 7 19/02/13 63.871 Feb 13, 2019
8683
+ 556 9 19/02/27 61.490 Feb 27, 2019
8684
+ 556 10 19/03/06 61.524 Mar 06, 2019
8685
+ 556 8 19/02/20 61.886 Feb 20, 2019
8686
+ 556 4 19/01/23 63.900 Jan 23, 2019
8687
+ 556 2 19/01/09 61.617 Jan 09, 2019
8688
+ 556 1 19/01/02 60.900 Jan 02, 2019
8689
+ >>>
8690
+ """
8691
+ arg_validate = []
8692
+ arg_validate.append(["formatter", formatter, False, (str), True])
8693
+
8694
+ # Validate argument types
8695
+ _Validators._validate_function_arguments(arg_validate)
8696
+
8697
+ return _SQLColumnExpression(func.cast(literal_column("({} (format '{}'))".format(self.compile(), formatter))
8698
+ , VARCHAR()))
8699
+
8700
+ def trim(self, expression=" "):
8701
+ """
8702
+ DESCRIPTION:
8703
+ Function trims the string values in the column.
8704
+
8705
+ PARAMETERS:
8706
+ expression:
8707
+ Optional Argument.
8708
+ Specifies a ColumnExpression of a string column or a string literal to
8709
+ be trimmed. If "expression" is specified, it must be the same data type
8710
+ as string values in column.
8711
+ Default Value: ' '
8712
+ Type: str or ColumnExpression
8713
+
8714
+ RAISES:
8715
+ TypeError, ValueError, TeradataMlException
8716
+
8717
+ RETURNS:
8718
+ ColumnExpression
8719
+
8720
+ EXAMPLES:
8721
+ # Load the data to run the example.
8722
+ >>> load_example_data("dataframe", "admissions_train")
8723
+
8724
+ # Create a DataFrame on 'admissions_train' table.
8725
+ >>> df = DataFrame("admissions_train")
8726
+ >>> df
8727
+ masters gpa stats programming admitted
8728
+ id
8729
+ 38 yes 2.65 Advanced Beginner 1
8730
+ 7 yes 2.33 Novice Novice 1
8731
+ 26 yes 3.57 Advanced Advanced 1
8732
+ 5 no 3.44 Novice Novice 0
8733
+ 3 no 3.70 Novice Beginner 1
8734
+ 22 yes 3.46 Novice Beginner 0
8735
+ 24 no 1.87 Advanced Novice 1
8736
+ 36 no 3.00 Advanced Novice 0
8737
+ 19 yes 1.98 Advanced Advanced 0
8738
+ 40 yes 3.95 Novice Beginner 0
8739
+
8740
+ # Example 1: Trim "Begi" from the strings in column "programing".
8741
+ >>> res = df.assign(trim_col = df.programming.trim("Begi"))
8742
+ >>> res
8743
+ masters gpa stats programming admitted trim_col
8744
+ id
8745
+ 38 yes 2.65 Advanced Beginner 1 nner
8746
+ 7 yes 2.33 Novice Novice 1 Novic
8747
+ 26 yes 3.57 Advanced Advanced 1 Advanced
8748
+ 5 no 3.44 Novice Novice 0 Novic
8749
+ 3 no 3.70 Novice Beginner 1 nner
8750
+ 22 yes 3.46 Novice Beginner 0 nner
8751
+ 24 no 1.87 Advanced Novice 1 Novic
8752
+ 36 no 3.00 Advanced Novice 0 Novic
8753
+ 19 yes 1.98 Advanced Advanced 0 Advanced
8754
+ 40 yes 3.95 Novice Beginner 0 nner
8755
+
8756
+ # Example 2: Filter the rows where values in the column "programming" result
8757
+ # in "nner" after it is trimmed with 'Begi'.
8758
+ >>> df[df.programming.trim("Begi") == "nner"]
8759
+ masters gpa stats programming admitted
8760
+ id
8761
+ 3 no 3.70 Novice Beginner 1
8762
+ 1 yes 3.95 Beginner Beginner 0
8763
+ 39 yes 3.75 Advanced Beginner 0
8764
+ 34 yes 3.85 Advanced Beginner 0
8765
+ 35 no 3.68 Novice Beginner 1
8766
+ 31 yes 3.50 Advanced Beginner 1
8767
+ 29 yes 4.00 Novice Beginner 0
8768
+ 32 yes 3.46 Advanced Beginner 0
8769
+ 22 yes 3.46 Novice Beginner 0
8770
+ 38 yes 2.65 Advanced Beginner 1
8771
+
8772
+ # Example 3: Trim string in "programing" column using "masters" column as argument.
8773
+ >>> res = df.assign(trim_col = df.programming.trim(df.masters))
8774
+ >>> res
8775
+ masters gpa stats programming admitted trim_col
8776
+ id
8777
+ 38 yes 2.65 Advanced Beginner 1 Beginner
8778
+ 7 yes 2.33 Novice Novice 1 Novic
8779
+ 26 yes 3.57 Advanced Advanced 1 Advanced
8780
+ 17 no 3.83 Advanced Advanced 1 Advanced
8781
+ 34 yes 3.85 Advanced Beginner 0 Beginner
8782
+ 13 no 4.00 Advanced Novice 1 Novice
8783
+ 32 yes 3.46 Advanced Beginner 0 Beginner
8784
+ 11 no 3.13 Advanced Advanced 1 Advanced
8785
+ 15 yes 4.00 Advanced Advanced 1 Advanced
8786
+ 36 no 3.00 Advanced Novice 0 Novice
8787
+
8788
+ """
8789
+ arg_validate = []
8790
+ arg_validate.append(["expression", expression, True, (str, ColumnExpression), False])
8791
+
8792
+ # Validate argument types
8793
+ _Validators._validate_function_arguments(arg_validate)
8794
+
8795
+ if isinstance(expression, ColumnExpression):
8796
+ expression=expression.expression
8797
+ return _SQLColumnExpression(func.rtrim(func.ltrim(self.expression, expression), expression), type=VARCHAR())
8798
+
8799
+ def to_char(self, formatter=None):
8800
+ """
8801
+ DESCRIPTION:
8802
+ Converts numeric type or datetype to character type.
8803
+
8804
+ PARAMETERS:
8805
+ formatter:
8806
+ Optional Argument.
8807
+ Specifies the string to format the values of a column.
8808
+ Type: str
8809
+ Note:
8810
+ * If 'formatter' is omitted, numeric values is converted to a string exactly
8811
+ long enough to hold its significant digits.
8812
+
8813
+ * Formatter for Numeric types:
8814
+ +--------------------------------------------------------------------------------------------------+
8815
+ | FORMATTER DESCRIPTION |
8816
+ +--------------------------------------------------------------------------------------------------+
8817
+ | , (comma) A comma in the specified position. |
8818
+ | A comma cannot begin a number format. |
8819
+ | A comma cannot appear to the right of a decimal |
8820
+ | character or period in a number format. |
8821
+ | Example: |
8822
+ | +-------------------------------------------------+ |
8823
+ | | data formatter result | |
8824
+ | +-------------------------------------------------+ |
8825
+ | | 1234 9,999 1,234 | |
8826
+ | +-------------------------------------------------+ |
8827
+ +--------------------------------------------------------------------------------------------------+
8828
+ | . (period) A decimal point. |
8829
+ | User can only specify one period in a number format. |
8830
+ | Example: |
8831
+ | +-------------------------------------------------+ |
8832
+ | | data formatter result | |
8833
+ | +-------------------------------------------------+ |
8834
+ | | 123.46 9999.9 123.5 | |
8835
+ | +-------------------------------------------------+ |
8836
+ +--------------------------------------------------------------------------------------------------+
8837
+ | $ A value with a leading dollar sign. |
8838
+ | Example: |
8839
+ | +-------------------------------------------------+ |
8840
+ | | data formatter result | |
8841
+ | +-------------------------------------------------+ |
8842
+ | | 1234 $9999 $1234 | |
8843
+ | +-------------------------------------------------+ |
8844
+ +--------------------------------------------------------------------------------------------------+
8845
+ | 0 Leading zeros. |
8846
+ | Trailing zeros. |
8847
+ | Example: |
8848
+ | +-------------------------------------------------+ |
8849
+ | | data formatter result | |
8850
+ | +-------------------------------------------------+ |
8851
+ | | 1234 09999 01234 | |
8852
+ | +-------------------------------------------------+ |
8853
+ +--------------------------------------------------------------------------------------------------+
8854
+ | 9 A value with the specified number of digits with a |
8855
+ | leading space if positive or with a leading minus |
8856
+ | if negative. |
8857
+ | Example: |
8858
+ | +-------------------------------------------------+ |
8859
+ | | data formatter result | |
8860
+ | +-------------------------------------------------+ |
8861
+ | | 1234 9999 1234 | |
8862
+ | | 1234 999 #### | |
8863
+ | +-------------------------------------------------+ |
8864
+ +--------------------------------------------------------------------------------------------------+
8865
+ | B Blank space for the integer part of a fixed point number|
8866
+ | when the integer part is zero. |
8867
+ | Example: |
8868
+ | +-------------------------------------------------+ |
8869
+ | | data formatter result | |
8870
+ | +-------------------------------------------------+ |
8871
+ | | 0.1234 B.999 Blank space| |
8872
+ | +-------------------------------------------------+ |
8873
+ +--------------------------------------------------------------------------------------------------+
8874
+ | C The ISO currency symbol as specified in the ISOCurrency |
8875
+ | element in the SDF file. |
8876
+ | Example: |
8877
+ | +-------------------------------------------------+ |
8878
+ | | data formatter result | |
8879
+ | +-------------------------------------------------+ |
8880
+ | | 234 C999 USD234 | |
8881
+ | +-------------------------------------------------+ |
8882
+ +--------------------------------------------------------------------------------------------------+
8883
+ | D The character that separates the integer and fractional |
8884
+ | part of non-monetary values. |
8885
+ | Example: |
8886
+ | +-------------------------------------------------+ |
8887
+ | | data formatter result | |
8888
+ | +-------------------------------------------------+ |
8889
+ | | 234.56 999D9 234.6 | |
8890
+ | +-------------------------------------------------+ |
8891
+ +--------------------------------------------------------------------------------------------------+
8892
+ | EEEE A value in scientific notation. |
8893
+ | Example: |
8894
+ | +-------------------------------------------------+ |
8895
+ | | data formatter result | |
8896
+ | +-------------------------------------------------+ |
8897
+ | | 234.56 9.9EEEE 2.3E+02 | |
8898
+ | +-------------------------------------------------+ |
8899
+ +--------------------------------------------------------------------------------------------------+
8900
+ | G The character that separates groups of digits in the |
8901
+ | integer part of non-monetary values. |
8902
+ | +-------------------------------------------------+ |
8903
+ | | data formatter result | |
8904
+ | +-------------------------------------------------+ |
8905
+ | | 123456 9G99G99 1,234,56 | |
8906
+ | +-------------------------------------------------+ |
8907
+ +--------------------------------------------------------------------------------------------------+
8908
+ | L The string representing the local currency as specified |
8909
+ | in the Currency element according to system settings. |
8910
+ | Example: |
8911
+ | +-------------------------------------------------+ |
8912
+ | | data formatter result | |
8913
+ | +-------------------------------------------------+ |
8914
+ | | 234 L999 $234 | |
8915
+ | +-------------------------------------------------+ |
8916
+ +--------------------------------------------------------------------------------------------------+
8917
+ | MI A trailing minus sign if the value is negative. |
8918
+ | The MI format element can appear only in the last |
8919
+ | position of a number format. |
8920
+ | Example: |
8921
+ | +-------------------------------------------------+ |
8922
+ | | data formatter result | |
8923
+ | +-------------------------------------------------+ |
8924
+ | | -1234 9999MI 1234- | |
8925
+ | +-------------------------------------------------+ |
8926
+ +--------------------------------------------------------------------------------------------------+
8927
+ | PR A negative value in <angle brackets>, or |
8928
+ | a positive value with a leading and trailing blank. |
8929
+ | The PR format element can appear only in the last |
8930
+ | position of a number format. |
8931
+ | Example: |
8932
+ | +-------------------------------------------------+ |
8933
+ | | data formatter result | |
8934
+ | +-------------------------------------------------+ |
8935
+ | | -1234 9999PR <1234> | |
8936
+ | +-------------------------------------------------+ |
8937
+ +--------------------------------------------------------------------------------------------------+
8938
+ | S A negative value with a leading or trailing minus sign. |
8939
+ | a positive value with a leading or trailing plus sign. |
8940
+ | The S format element can appear only in the first or |
8941
+ | last position of a number format. |
8942
+ | Example: |
8943
+ | +-------------------------------------------------+ |
8944
+ | | data formatter result | |
8945
+ | +-------------------------------------------------+ |
8946
+ | | +1234 S9999 +1234 | |
8947
+ | +-------------------------------------------------+ |
8948
+ +--------------------------------------------------------------------------------------------------+
8949
+ | TM (text minimum format) Returns the smallest number of |
8950
+ | characters possible. This element is case insensitive. |
8951
+ | TM or TM9 return the number in fixed notation unless |
8952
+ | the output exceeds 64 characters. If the output exceeds |
8953
+ | 64 characters, the number is returned in scientific |
8954
+ | notation. |
8955
+ | TME returns the number in scientific notation with the |
8956
+ | smallest number of characters. |
8957
+ | You cannot precede this element with an other element. |
8958
+ | You can follow this element only with one 9 or one E |
8959
+ | (or e), but not with any combination of these. |
8960
+ | Example: |
8961
+ | +-------------------------------------------------+ |
8962
+ | | data formatter result | |
8963
+ | +-------------------------------------------------+ |
8964
+ | | 1234 TM 1234 | |
8965
+ | +-------------------------------------------------+ |
8966
+ +--------------------------------------------------------------------------------------------------+
8967
+ | U (dual currency) The string that represents the dual |
8968
+ | currency as specified in the DualCurrency element |
8969
+ | according to system settings. |
8970
+ | Example: |
8971
+ | +-------------------------------------------------+ |
8972
+ | | data formatter result | |
8973
+ | +-------------------------------------------------+ |
8974
+ | | 1234 U9999 $1234 | |
8975
+ | +-------------------------------------------------+ |
8976
+ +--------------------------------------------------------------------------------------------------+
8977
+ | V A value multiplied by 10 to the n (and, if necessary, |
8978
+ | rounded up), where n is the number of 9's after the V. |
8979
+ | Example: |
8980
+ | +-------------------------------------------------+ |
8981
+ | | data formatter result | |
8982
+ | +-------------------------------------------------+ |
8983
+ | | 1234 9999V99 123400 | |
8984
+ | +-------------------------------------------------+ |
8985
+ +--------------------------------------------------------------------------------------------------+
8986
+ | X The hexadecimal value of the specified number of digits.|
8987
+ | If the specified number is not an integer, the function |
8988
+ | will round it to an integer. |
8989
+ | This element accepts only positive values or zero. |
8990
+ | Negative values return an error. You can precede this |
8991
+ | element only with zero (which returns leading zeros) or |
8992
+ | FM. Any other elements return an error. If you do not |
8993
+ | specify zero or FM, the return always has one leading |
8994
+ | blank. |
8995
+ | Example: |
8996
+ | +-------------------------------------------------+ |
8997
+ | | data formatter result | |
8998
+ | +-------------------------------------------------+ |
8999
+ | | 1234 XXXX 4D2 | |
9000
+ | +-------------------------------------------------+ |
9001
+ +--------------------------------------------------------------------------------------------------+
9002
+
9003
+ * Formatter for Date types:
9004
+ +--------------------------------------------------------------------------------------------------+
9005
+ | FORMATTER DESCRIPTION |
9006
+ +--------------------------------------------------------------------------------------------------+
9007
+ | - |
9008
+ | / |
9009
+ | , Punctuation characters are ignored and text enclosed in |
9010
+ | . quotation marks is ignored. |
9011
+ | ; |
9012
+ | : |
9013
+ | "text" |
9014
+ | Example: |
9015
+ | +-------------------------------------------------+ |
9016
+ | | data formatter result | |
9017
+ | +-------------------------------------------------+ |
9018
+ | | 03/09/17 MM-DD 09-17 | |
9019
+ | +-------------------------------------------------+ |
9020
+ +--------------------------------------------------------------------------------------------------+
9021
+ | AD AD indicator. |
9022
+ | A.D. |
9023
+ | Example: |
9024
+ | +-------------------------------------------------+ |
9025
+ | | data formatter result | |
9026
+ | +-------------------------------------------------+ |
9027
+ | | 03/09/17 CCAD 21AD | |
9028
+ | +-------------------------------------------------+ |
9029
+ +--------------------------------------------------------------------------------------------------+
9030
+ | AM Meridian indicator. |
9031
+ | A.M. |
9032
+ | Example: |
9033
+ | +-------------------------------------------------+ |
9034
+ | | data formatter result | |
9035
+ | +-------------------------------------------------+ |
9036
+ | | 03/09/17 CCAM 21AM | |
9037
+ | +-------------------------------------------------+ |
9038
+ +--------------------------------------------------------------------------------------------------+
9039
+ | BC |
9040
+ | B.C. BC indicator. |
9041
+ | Example: |
9042
+ | +-------------------------------------------------+ |
9043
+ | | data formatter result | |
9044
+ | +-------------------------------------------------+ |
9045
+ | | 03/09/17 CCBC 21BC | |
9046
+ | +-------------------------------------------------+ |
9047
+ +--------------------------------------------------------------------------------------------------+
9048
+ | CC Century. |
9049
+ | SCC If the last 2 digits of a 4-digit year are between 01 |
9050
+ | and 99 inclusive, the century is 1 greater than the |
9051
+ | first 2 digits of that year. |
9052
+ | If the last 2 digits of a 4-digit year are 00, the |
9053
+ | century is the same as the first 2 digits of that year. |
9054
+ | Example: |
9055
+ | +-------------------------------------------------+ |
9056
+ | | data formatter result | |
9057
+ | +-------------------------------------------------+ |
9058
+ | | 03/09/17 CCBC 21BC | |
9059
+ | +-------------------------------------------------+ |
9060
+ +--------------------------------------------------------------------------------------------------+
9061
+ | D Day of week (1-7). |
9062
+ | Example: |
9063
+ | +-------------------------------------------------+ |
9064
+ | | data formatter result | |
9065
+ | +-------------------------------------------------+ |
9066
+ | | 03/09/17 D 4 | |
9067
+ | +-------------------------------------------------+ |
9068
+ +--------------------------------------------------------------------------------------------------+
9069
+ | DAY Name of day. |
9070
+ | Example: |
9071
+ | +-------------------------------------------------+ |
9072
+ | | data formatter result | |
9073
+ | +-------------------------------------------------+ |
9074
+ | | 03/09/17 DAY WEDNESDAY | |
9075
+ | +-------------------------------------------------+ |
9076
+ +--------------------------------------------------------------------------------------------------+
9077
+ | DD Day of month (1-31). |
9078
+ | Example: |
9079
+ | +-------------------------------------------------+ |
9080
+ | | data formatter result | |
9081
+ | +-------------------------------------------------+ |
9082
+ | | 03/09/17 DD 17 | |
9083
+ | +-------------------------------------------------+ |
9084
+ +--------------------------------------------------------------------------------------------------+
9085
+ | DDD Day of year (1-366). |
9086
+ | Example: |
9087
+ | +-------------------------------------------------+ |
9088
+ | | data formatter result | |
9089
+ | +-------------------------------------------------+ |
9090
+ | | 03/09/17 DDD 260 | |
9091
+ | +-------------------------------------------------+ |
9092
+ +--------------------------------------------------------------------------------------------------+
9093
+ | DL Date Long. Equivalent to the format string ‘FMDay, |
9094
+ | Month FMDD, YYYY’. |
9095
+ | Example: |
9096
+ | +-------------------------------------------------+ |
9097
+ | | data formatter result | |
9098
+ | +-------------------------------------------------+ |
9099
+ | | 03/09/17 DL Wednesday, September 17, 2003| |
9100
+ | +-------------------------------------------------+ |
9101
+ +--------------------------------------------------------------------------------------------------+
9102
+ | DS Date Short. Equivalent to the format string |
9103
+ | ‘FMMM/DD/YYYYFM’. |
9104
+ | Example: |
9105
+ | +-------------------------------------------------+ |
9106
+ | | data formatter result | |
9107
+ | +-------------------------------------------------+ |
9108
+ | | 03/09/17 DS 9/17/2003 | |
9109
+ | +-------------------------------------------------+ |
9110
+ +--------------------------------------------------------------------------------------------------+
9111
+ | DY abbreviated name of day. |
9112
+ | Example: |
9113
+ | +-------------------------------------------------+ |
9114
+ | | data formatter result | |
9115
+ | +-------------------------------------------------+ |
9116
+ | | 03/09/17 DY WED | |
9117
+ | +-------------------------------------------------+ |
9118
+ +--------------------------------------------------------------------------------------------------+
9119
+ | FF [1..9] Fractional seconds. |
9120
+ | Use [1..9] to specify the number of fractional digits. |
9121
+ | FF without any number following it prints a decimal |
9122
+ | followed by digits equal to the number of fractional |
9123
+ | seconds in the input data type. If the data type has no |
9124
+ | fractional digits, FF prints nothing. |
9125
+ | Any fractional digits beyond 6 digits are truncated. |
9126
+ | Example: |
9127
+ | +-------------------------------------------------+ |
9128
+ | | data formatter result | |
9129
+ | +-------------------------------------------------+ |
9130
+ | | 2016-01-06 09:08:01.000000 FF 000000 | |
9131
+ | +-------------------------------------------------+ |
9132
+ +--------------------------------------------------------------------------------------------------+
9133
+ | HH |
9134
+ | HH12 Hour of day (1-12). |
9135
+ | Example: |
9136
+ | +-------------------------------------------------+ |
9137
+ | | data formatter result | |
9138
+ | +-------------------------------------------------+ |
9139
+ | | 2016-01-06 09:08:01.000000 HH 09 | |
9140
+ | +-------------------------------------------------+ |
9141
+ +--------------------------------------------------------------------------------------------------+
9142
+ | HH24 Hour of the day (0-23). |
9143
+ | Example: |
9144
+ | +-------------------------------------------------+ |
9145
+ | | data formatter result | |
9146
+ | +-------------------------------------------------+ |
9147
+ | | 2016-01-06 09:08:01.000000 HH24 09 | |
9148
+ | +-------------------------------------------------+ |
9149
+ +--------------------------------------------------------------------------------------------------+
9150
+ | IW Week of year (1-52 or 1-53) based on ISO model. |
9151
+ | Example: |
9152
+ | +-------------------------------------------------+ |
9153
+ | | data formatter result | |
9154
+ | +-------------------------------------------------+ |
9155
+ | | 2016-01-06 09:08:01.000000 IW 01 | |
9156
+ | +-------------------------------------------------+ |
9157
+ +--------------------------------------------------------------------------------------------------+
9158
+ | IYY |
9159
+ | IY Last 3, 2, or 1 digits of ISO year. |
9160
+ | I |
9161
+ | Example: |
9162
+ | +-------------------------------------------------+ |
9163
+ | | data formatter result | |
9164
+ | +-------------------------------------------------+ |
9165
+ | | 2016-01-06 09:08:01.000000 IY 16 | |
9166
+ | +-------------------------------------------------+ |
9167
+ +--------------------------------------------------------------------------------------------------+
9168
+ | IYYY 4-digit year based on the ISO standard. |
9169
+ | Example: |
9170
+ | +-------------------------------------------------+ |
9171
+ | | data formatter result | |
9172
+ | +-------------------------------------------------+ |
9173
+ | | 2016-01-06 09:08:01.000000 IYYY 2016 | |
9174
+ | +-------------------------------------------------+ |
9175
+ +--------------------------------------------------------------------------------------------------+
9176
+ | J Julian day, the number of days since January 1, 4713 BC. |
9177
+ | Number specified with J must be integers. |
9178
+ | Teradata uses the Gregorian calendar in calculations to |
9179
+ | and from Julian Days. |
9180
+ | Example: |
9181
+ | +-------------------------------------------------+ |
9182
+ | | data formatter result | |
9183
+ | +-------------------------------------------------+ |
9184
+ | | 2016-01-06 09:08:01.000000 J 2457394 | |
9185
+ | +-------------------------------------------------+ |
9186
+ +--------------------------------------------------------------------------------------------------+
9187
+ | MI Minute (0-59). |
9188
+ | Example: |
9189
+ | +-------------------------------------------------+ |
9190
+ | | data formatter result | |
9191
+ | +-------------------------------------------------+ |
9192
+ | | 2016-01-06 09:08:01.000000 MI 08 | |
9193
+ | +-------------------------------------------------+ |
9194
+ +--------------------------------------------------------------------------------------------------+
9195
+ | MM Month (01-12). |
9196
+ | Example: |
9197
+ | +-------------------------------------------------+ |
9198
+ | | data formatter result | |
9199
+ | +-------------------------------------------------+ |
9200
+ | | 2016-01-06 09:08:01.000000 MM 01 | |
9201
+ | +-------------------------------------------------+ |
9202
+ +--------------------------------------------------------------------------------------------------+
9203
+ | MON Abbreviated name of month. |
9204
+ | Example: |
9205
+ | +-------------------------------------------------+ |
9206
+ | | data formatter result | |
9207
+ | +-------------------------------------------------+ |
9208
+ | | 2016-01-06 09:08:01.000000 MON JAN | |
9209
+ | +-------------------------------------------------+ |
9210
+ +--------------------------------------------------------------------------------------------------+
9211
+ | MONTH Name of month. |
9212
+ | Example: |
9213
+ | +-------------------------------------------------+ |
9214
+ | | data formatter result | |
9215
+ | +-------------------------------------------------+ |
9216
+ | | 2016-01-06 09:08:01.000000 MONTH JANUARY | |
9217
+ | +-------------------------------------------------+ |
9218
+ +--------------------------------------------------------------------------------------------------+
9219
+ | PM |
9220
+ | P.M. Meridian indicator. |
9221
+ | Example: |
9222
+ | +-------------------------------------------------+ |
9223
+ | | data formatter result | |
9224
+ | +-------------------------------------------------+ |
9225
+ | | 2016-01-06 09:08:01.000000 HHPM 09PM | |
9226
+ | +-------------------------------------------------+ |
9227
+ +--------------------------------------------------------------------------------------------------+
9228
+ | Q Quarter of year (1, 2, 3, 4). |
9229
+ | Example: |
9230
+ | +-------------------------------------------------+ |
9231
+ | | data formatter result | |
9232
+ | +-------------------------------------------------+ |
9233
+ | | 2016-01-06 09:08:01.000000 Q 1 | |
9234
+ | +-------------------------------------------------+ |
9235
+ +--------------------------------------------------------------------------------------------------+
9236
+ | RM Roman numeral month (I - XII). |
9237
+ | Example: |
9238
+ | +-------------------------------------------------+ |
9239
+ | | data formatter result | |
9240
+ | +-------------------------------------------------+ |
9241
+ | | 2016-01-06 09:08:01.000000 RM I | |
9242
+ | +-------------------------------------------------+ |
9243
+ +--------------------------------------------------------------------------------------------------+
9244
+ | SP Spelled. Any numeric element followed by SP is spelled in|
9245
+ | English words. The words are capitalized according to how|
9246
+ | the element is capitalized. |
9247
+ | For example: 'DDDSP' specifies all uppercase, 'DddSP' |
9248
+ | specifies that the first letter is capitalized, and |
9249
+ | 'dddSP' specifies all lowercase. |
9250
+ | Example: |
9251
+ | +-------------------------------------------------+ |
9252
+ | | data formatter result | |
9253
+ | +-------------------------------------------------+ |
9254
+ | | 2016-01-06 09:08:01.000000 HHSP NINE | |
9255
+ | +-------------------------------------------------+ |
9256
+ +--------------------------------------------------------------------------------------------------+
9257
+ | SS Second (0-59). |
9258
+ | Example: |
9259
+ | +-------------------------------------------------+ |
9260
+ | | data formatter result | |
9261
+ | +-------------------------------------------------+ |
9262
+ | | 2016-01-06 09:08:01.000000 SS 03 | |
9263
+ | +-------------------------------------------------+ |
9264
+ +--------------------------------------------------------------------------------------------------+
9265
+ | SSSSS Seconds past midnight (0-86399). |
9266
+ | Example: |
9267
+ | +-------------------------------------------------+ |
9268
+ | | data formatter result | |
9269
+ | +-------------------------------------------------+ |
9270
+ | | 2016-01-06 09:08:01.000000 SSSSS 32883 | |
9271
+ | +-------------------------------------------------+ |
9272
+ +--------------------------------------------------------------------------------------------------+
9273
+ | TS Time Short. Equivalent to the format string |
9274
+ | 'HH:MI:SS AM'. |
9275
+ | Example: |
9276
+ | +-------------------------------------------------+ |
9277
+ | | data formatter result | |
9278
+ | +-------------------------------------------------+ |
9279
+ | | 2016-01-06 09:08:01.000000 TS 09:08:01 AM | |
9280
+ | +-------------------------------------------------+ |
9281
+ +--------------------------------------------------------------------------------------------------+
9282
+ | TZH Time zone hour. |
9283
+ | Example: |
9284
+ | +-------------------------------------------------+ |
9285
+ | | data formatter result | |
9286
+ | +-------------------------------------------------+ |
9287
+ | | 2016-01-06 09:08:01.000000 TZH +00 | |
9288
+ | +-------------------------------------------------+ |
9289
+ +--------------------------------------------------------------------------------------------------+
9290
+ | TZM Time zone minute. |
9291
+ | Example: |
9292
+ | +-------------------------------------------------+ |
9293
+ | | data formatter result | |
9294
+ | +-------------------------------------------------+ |
9295
+ | | 2016-01-06 09:08:01.000000 TZM 00 | |
9296
+ | +-------------------------------------------------+ |
9297
+ +--------------------------------------------------------------------------------------------------+
9298
+ | TZR Time zone region. Equivalent to the format string |
9299
+ | 'TZH:TZM'. |
9300
+ | Example: |
9301
+ | +-------------------------------------------------+ |
9302
+ | | data formatter result | |
9303
+ | +-------------------------------------------------+ |
9304
+ | | 2016-01-06 09:08:01.000000 TZR +00:00 | |
9305
+ | +-------------------------------------------------+ |
9306
+ +--------------------------------------------------------------------------------------------------+
9307
+ | WW Week of year (1-53) where week 1 starts on the first day |
9308
+ | of the year and continues to the 7th day of the year. |
9309
+ | Example: |
9310
+ | +-------------------------------------------------+ |
9311
+ | | data formatter result | |
9312
+ | +-------------------------------------------------+ |
9313
+ | | 2016-01-06 09:08:01.000000 WW 01 | |
9314
+ | +-------------------------------------------------+ |
9315
+ +--------------------------------------------------------------------------------------------------+
9316
+ | W Week of month (1-5) where week 1 starts on the first day |
9317
+ | of the month and ends on the seventh. |
9318
+ | Example: |
9319
+ | +-------------------------------------------------+ |
9320
+ | | data formatter result | |
9321
+ | +-------------------------------------------------+ |
9322
+ | | 2016-01-06 09:08:01.000000 W 1 | |
9323
+ | +-------------------------------------------------+ |
9324
+ +--------------------------------------------------------------------------------------------------+
9325
+ | X Local radix character. |
9326
+ | Example: |
9327
+ | +-------------------------------------------------+ |
9328
+ | | data formatter result | |
9329
+ | +-------------------------------------------------+ |
9330
+ | | 2016-01-06 09:08:01.000000 MMXYY 01.16 | |
9331
+ | +-------------------------------------------------+ |
9332
+ +--------------------------------------------------------------------------------------------------+
9333
+ | Y,YYY Year with comma in this position. |
9334
+ | Example: |
9335
+ | +-------------------------------------------------+ |
9336
+ | | data formatter result | |
9337
+ | +-------------------------------------------------+ |
9338
+ | | 2016-01-06 09:08:01.000000 Y,YYY 2,016 | |
9339
+ | +-------------------------------------------------+ |
9340
+ +--------------------------------------------------------------------------------------------------+
9341
+ | YEAR Year, spelled out. S prefixes BC dates with a minus sign.|
9342
+ | SYEAR |
9343
+ | Example: |
9344
+ | +-------------------------------------------------+ |
9345
+ | | data formatter result | |
9346
+ | +-------------------------------------------------+ |
9347
+ | | 2016-01-06 09:08:01.000000 YEAR TWENTY SIXTEEN| |
9348
+ | +-------------------------------------------------+ |
9349
+ +--------------------------------------------------------------------------------------------------+
9350
+ | YYYY |
9351
+ | SYYYY 4-digit year. S prefixes BC dates with a minus sign. |
9352
+ | Example: |
9353
+ | +-------------------------------------------------+ |
9354
+ | | data formatter result | |
9355
+ | +-------------------------------------------------+ |
9356
+ | | 2016-01-06 09:08:01.000000 YYYY 2016 | |
9357
+ | +-------------------------------------------------+ |
9358
+ +--------------------------------------------------------------------------------------------------+
9359
+ | YYY Last 3, 2, or 1 digit of year. |
9360
+ | YY If the current year and the specified year are both in |
9361
+ | Y the range of 0-49, the date is in the current century. |
9362
+ | Example: |
9363
+ | +-------------------------------------------------+ |
9364
+ | | data formatter result | |
9365
+ | +-------------------------------------------------+ |
9366
+ | | 2016-01-06 09:08:01.000000 YY 16 | |
9367
+ | +-------------------------------------------------+ |
9368
+ +--------------------------------------------------------------------------------------------------+
9369
+
9370
+ RAISES:
9371
+ TypeError, ValueError, TeradataMlException
9372
+
9373
+ Returns:
9374
+ ColumnExpression
9375
+
9376
+ EXAMPLES:
9377
+ # Load the data to run the example.
9378
+ >>> load_example_data("uaf", "stock_data")
9379
+
9380
+ # Create a DataFrame on 'stock_data' table.
9381
+ >>> df = DataFrame("stock_data")
9382
+ >>> df
9383
+ seq_no timevalue magnitude
9384
+ data_set_id
9385
+ 556 3 19/01/16 61.080
9386
+ 556 5 19/01/30 63.810
9387
+ 556 6 19/02/06 63.354
9388
+ 556 7 19/02/13 63.871
9389
+ 556 9 19/02/27 61.490
9390
+ 556 10 19/03/06 61.524
9391
+ 556 8 19/02/20 61.886
9392
+ 556 4 19/01/23 63.900
9393
+ 556 2 19/01/09 61.617
9394
+ 556 1 19/01/02 60.900
9395
+ >>> df.tdtypes
9396
+ column type
9397
+ data_set_id INTEGER()
9398
+ seq_no INTEGER()
9399
+ timevalue DATE()
9400
+ magnitude FLOAT()
9401
+
9402
+ # Example 1: Convert 'seq_no' column to character type.
9403
+ >>> res = df.assign(seq_no = df.seq_no.to_char())
9404
+ >>> res
9405
+ seq_no timevalue magnitude
9406
+ data_set_id
9407
+ 556 3 19/01/16 61.080
9408
+ 556 5 19/01/30 63.810
9409
+ 556 6 19/02/06 63.354
9410
+ 556 7 19/02/13 63.871
9411
+ 556 9 19/02/27 61.490
9412
+ 556 10 19/03/06 61.524
9413
+ 556 8 19/02/20 61.886
9414
+ 556 4 19/01/23 63.900
9415
+ 556 2 19/01/09 61.617
9416
+ 556 1 19/01/02 60.900
9417
+ >>> res.tdtypes
9418
+ columnn type
9419
+ data_set_id INTEGER()
9420
+ seq_no VARCHAR()
9421
+ timevalue DATE()
9422
+ magnitude FLOAT()
9423
+
9424
+ # Example 2: Convert "magnitude" column to character type in '$99.9' format.
9425
+ >>> res = df.assign(char_column = df.magnitude.to_char('$99.9'))
9426
+ >>> res
9427
+ seq_no timevalue magnitude char_column
9428
+ data_set_id
9429
+ 556 3 19/01/16 61.080 $61.1
9430
+ 556 5 19/01/30 63.810 $63.8
9431
+ 556 6 19/02/06 63.354 $63.4
9432
+ 556 7 19/02/13 63.871 $63.9
9433
+ 556 9 19/02/27 61.490 $61.5
9434
+ 556 10 19/03/06 61.524 $61.5
9435
+ 556 8 19/02/20 61.886 $61.9
9436
+ 556 4 19/01/23 63.900 $63.9
9437
+ 556 2 19/01/09 61.617 $61.6
9438
+ 556 1 19/01/02 60.900 $60.9
9439
+
9440
+ # Example 3: Convert "timevalue" column to character type in 'YYYY-DAY-MONTH' format
9441
+ >>> res = df.assign(timevalue = df.timevalue.to_char('YYYY-DAY-MONTH'))
9442
+ >>> res
9443
+ seq_no timevalue magnitude
9444
+ data_set_id
9445
+ 556 3 2019-WEDNESDAY-JANUARY 61.080
9446
+ 556 5 2019-WEDNESDAY-JANUARY 63.810
9447
+ 556 6 2019-WEDNESDAY-FEBRUARY 63.354
9448
+ 556 7 2019-WEDNESDAY-FEBRUARY 63.871
9449
+ 556 9 2019-WEDNESDAY-FEBRUARY 61.490
9450
+ 556 10 2019-WEDNESDAY-MARCH 61.524
9451
+ 556 8 2019-WEDNESDAY-FEBRUARY 61.886
9452
+ 556 4 2019-WEDNESDAY-JANUARY 63.900
9453
+ 556 2 2019-WEDNESDAY-JANUARY 61.617
9454
+ 556 1 2019-WEDNESDAY-JANUARY 60.900
9455
+ """
9456
+ arg_validate = []
9457
+ arg_validate.append(["formatter", formatter, True, (str), True])
9458
+
9459
+ # Validate argument types
9460
+ _Validators._validate_function_arguments(arg_validate)
9461
+
9462
+ _args=[self.expression]
9463
+ if formatter:
9464
+ _args.append(formatter)
9465
+ return _SQLColumnExpression(func.to_char(*_args), type=VARCHAR())
9466
+
9467
+ def to_date(self, formatter=None):
9468
+ """
9469
+ DESCRIPTION:
9470
+ Convert a string-like representation of a DATE or PERIOD type to Date type.
9471
+
9472
+ PARAMETERS:
9473
+ formatter:
9474
+ Optional Argument.
9475
+ Specifies a variable length string containing formatting characters
9476
+ that define the format of column.
9477
+ Type: str
9478
+ Note:
9479
+ * If "formatter" is omitted, the following default date format is used: 'YYYY-MM-DD'
9480
+ * formatter for date type:
9481
+ +--------------------------------------------------------------------------------------------------+
9482
+ | FORMATTER DESCRIPTION |
9483
+ +--------------------------------------------------------------------------------------------------+
9484
+ | - |
9485
+ | / |
9486
+ | , Punctuation characters are ignored and text enclosed in |
9487
+ | . quotation marks is ignored. |
9488
+ | ; |
9489
+ | : |
9490
+ | "text" |
9491
+ | Example: Date with value '2003-12-10' |
9492
+ | +-------------------------------------------------+ |
9493
+ | | data formatter value | |
9494
+ | +-------------------------------------------------+ |
9495
+ | | '2003-12-10' YYYY-MM-DD 03/12/10 | |
9496
+ | +-------------------------------------------------+ |
9497
+ +--------------------------------------------------------------------------------------------------+
9498
+ | D Day of week (1-7). |
9499
+ | Example: day of week with value '2' |
9500
+ | +-------------------------------------------------+ |
9501
+ | | data formatter value | |
9502
+ | +-------------------------------------------------+ |
9503
+ | | 2 D 24/01/01 | |
9504
+ | +-------------------------------------------------+ |
9505
+ +--------------------------------------------------------------------------------------------------+
9506
+ | DAY Name of day. |
9507
+ | Example: Date with value '2024-TUESDAY-01-30' |
9508
+ | +-------------------------------------------------+ |
9509
+ | | data formatter value | |
9510
+ | +-------------------------------------------------+ |
9511
+ | | 2024-TUESDAY-01-30 YYYY-DAY-MM-DD 24/01/30 | |
9512
+ | +-------------------------------------------------+ |
9513
+ +--------------------------------------------------------------------------------------------------+
9514
+ | DD Day of month (1-31). |
9515
+ | Example: Date with value '2003-10-25' |
9516
+ | +-------------------------------------------------+ |
9517
+ | | data formatter value | |
9518
+ | +-------------------------------------------------+ |
9519
+ | | 2003-10-25 YYYY-MM-DD 03/10/25 | |
9520
+ | +-------------------------------------------------+ |
9521
+ +--------------------------------------------------------------------------------------------------+
9522
+ | DDD Day of year (1-366). |
9523
+ | Example: Date with value '2024-366' |
9524
+ | +-------------------------------------------------+ |
9525
+ | | data formatter value | |
9526
+ | +-------------------------------------------------+ |
9527
+ | | 2024-366 YYYY-DDD 24/12/31 | |
9528
+ | +-------------------------------------------------+ |
9529
+ +--------------------------------------------------------------------------------------------------+
9530
+ | DY abbreviated name of day. |
9531
+ | Example: Date with value '2024-Mon-01-29' |
9532
+ | +-------------------------------------------------+ |
9533
+ | | data formatter value | |
9534
+ | +-------------------------------------------------+ |
9535
+ | | 2024-Mon-01-29 YYYY-DY-MM-DD 24/01/29 | |
9536
+ | +-------------------------------------------------+ |
9537
+ +--------------------------------------------------------------------------------------------------+
9538
+ | HH |
9539
+ | HH12 Hour of day (1-12). |
9540
+ | Example: Date with value '2016-01-06 09:08:01' |
9541
+ | +-------------------------------------------------+ |
9542
+ | | data formatter value | |
9543
+ | +-------------------------------------------------+ |
9544
+ | | 2016-01-06 09:08:01 YYYY-MM-DD HH:MI:SS 6/01/06| |
9545
+ | +-------------------------------------------------+ |
9546
+ +--------------------------------------------------------------------------------------------------+
9547
+ | HH24 Hour of the day (0-23). |
9548
+ | Example: Date with value '2016-01-06 23:08:01' |
9549
+ | +----------------------------------------------------+ |
9550
+ | | data formatter value | |
9551
+ | +----------------------------------------------------+ |
9552
+ | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9553
+ | +----------------------------------------------------+ |
9554
+ +--------------------------------------------------------------------------------------------------+
9555
+ | J Julian day, the number of days since January 1, 4713 BC. |
9556
+ | Number specified with J must be integers. |
9557
+ | Teradata uses the Gregorian calendar in calculations to |
9558
+ | and from Julian Days. |
9559
+ | Example: Number of julian days with value '2457394' |
9560
+ | +-------------------------------------------------+ |
9561
+ | | data formatter value | |
9562
+ | +-------------------------------------------------+ |
9563
+ | | 2457394 J 16/01/06 | |
9564
+ | +-------------------------------------------------+ |
9565
+ +--------------------------------------------------------------------------------------------------+
9566
+ | MI Minute (0-59). |
9567
+ | Example: Date with value '2016-01-06 23:08:01' |
9568
+ | +----------------------------------------------------+ |
9569
+ | | data formatter value | |
9570
+ | +----------------------------------------------------+ |
9571
+ | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9572
+ | +----------------------------------------------------+ |
9573
+ +--------------------------------------------------------------------------------------------------+
9574
+ | MM Month (01-12). |
9575
+ | Example: Date with value '2016-01-06 23:08:01' |
9576
+ | +----------------------------------------------------+ |
9577
+ | | data formatter value | |
9578
+ | +----------------------------------------------------+ |
9579
+ | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9580
+ | +----------------------------------------------------+ |
9581
+ +--------------------------------------------------------------------------------------------------+
9582
+ | MON Abbreviated name of month. |
9583
+ | Example: Date with value '2016-JAN-06' |
9584
+ | +----------------------------------------------------+ |
9585
+ | | data formatter value | |
9586
+ | +----------------------------------------------------+ |
9587
+ | | 2016-JAN-06 YYYY-MON-DD 16/01/06 | |
9588
+ | +----------------------------------------------------+ |
9589
+ +--------------------------------------------------------------------------------------------------+
9590
+ | MONTH Name of month. |
9591
+ | Example: Date with value '2016-JANUARY-06' |
9592
+ | +-------------------------------------------------+ |
9593
+ | | data formatter value | |
9594
+ | +-------------------------------------------------+ |
9595
+ | | 2016-JANUARY-06 YYYY-MONTH-DD 16/01/06 | |
9596
+ | +-------------------------------------------------+ |
9597
+ +--------------------------------------------------------------------------------------------------+
9598
+ | PM |
9599
+ | P.M. Meridian indicator. |
9600
+ | Example: Date with value '2016-01-06 23:08:01 PM' |
9601
+ | +---------------------------------------------------------+ |
9602
+ | | data formatter value | |
9603
+ | +---------------------------------------------------------+ |
9604
+ | | 2016-01-06 23:08:01 PM YYYY-MM-DD HH24:MI:SS PM 16/01/06| |
9605
+ | +---------------------------------------------------------+ |
9606
+ +--------------------------------------------------------------------------------------------------+
9607
+ | RM Roman numeral month (I - XII). |
9608
+ | Example: Date with value '2024-XII' |
9609
+ | +-------------------------------------------------+ |
9610
+ | | data formatter value | |
9611
+ | +-------------------------------------------------+ |
9612
+ | | 2024-XII YYYY-RM 24/12/01 | |
9613
+ | +-------------------------------------------------+ |
9614
+ +--------------------------------------------------------------------------------------------------+
9615
+ | RR Stores 20th century dates in the 21st century using only |
9616
+ | 2 digits. If the current year and the specified year are |
9617
+ | both in the range of 0-49, the date is in the current |
9618
+ | century. |
9619
+ | Example: Date with value '2024-365, 21' |
9620
+ | +-------------------------------------------------+ |
9621
+ | | data formatter value | |
9622
+ | +-------------------------------------------------+ |
9623
+ | | 2024-365, 21 YYYY-DDD, RR 21/12/31 | |
9624
+ | +-------------------------------------------------+ |
9625
+ +--------------------------------------------------------------------------------------------------+
9626
+ | RRRR Round year. Accepts either 4-digit or 2-digit input. |
9627
+ | 2-digit input provides the same return as RR. |
9628
+ | Example: Date with value '2024-365, 21' |
9629
+ | +-------------------------------------------------+ |
9630
+ | | data formatter value | |
9631
+ | +-------------------------------------------------+ |
9632
+ | | 2024-365, 21 YYYY-DDD, RRRR 24/12/31 | |
9633
+ | +-------------------------------------------------+ |
9634
+ +--------------------------------------------------------------------------------------------------+
9635
+ | SS Second (0-59). |
9636
+ | Example: Date with value '2016-01-06 23:08:01' |
9637
+ | +----------------------------------------------------+ |
9638
+ | | data formatter value | |
9639
+ | +----------------------------------------------------+ |
9640
+ | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9641
+ | +----------------------------------------------------+ |
9642
+ +--------------------------------------------------------------------------------------------------+
9643
+ | SSSSS Seconds past midnight (0-86399). |
9644
+ +--------------------------------------------------------------------------------------------------+
9645
+ | TZH Time zone hour. |
9646
+ +--------------------------------------------------------------------------------------------------+
9647
+ | TZM Time zone minute. |
9648
+ +--------------------------------------------------------------------------------------------------+
9649
+ | X Local radix character. |
9650
+ | Example: Date with value '2024.366' |
9651
+ | +-------------------------------------------------+ |
9652
+ | | data formatter value | |
9653
+ | +-------------------------------------------------+ |
9654
+ | | 2024.366 YYYYXDDD 24/12/31 | |
9655
+ | +-------------------------------------------------+ |
9656
+ +--------------------------------------------------------------------------------------------------+
9657
+ | Y,YYY Year with comma in this position. |
9658
+ | Example: Date with value '2,024-366' |
9659
+ | +-------------------------------------------------+ |
9660
+ | | data formatter value | |
9661
+ | +-------------------------------------------------+ |
9662
+ | | 2,024-366 Y,YYY-DDD 24/12/31 | |
9663
+ | +-------------------------------------------------+ |
9664
+ +--------------------------------------------------------------------------------------------------+
9665
+ | YYYY |
9666
+ | SYYYY 4-digit year. S prefixes BC dates with a minus sign. |
9667
+ | Example: Date with value '2024-366' |
9668
+ | +-------------------------------------------------+ |
9669
+ | | data formatter value | |
9670
+ | +-------------------------------------------------+ |
9671
+ | | 2024-366 YYYY-DDD 24/12/31 | |
9672
+ | +-------------------------------------------------+ |
9673
+ +--------------------------------------------------------------------------------------------------+
9674
+ | YYY Last 3, 2, or 1 digit of year. |
9675
+ | YY If the current year and the specified year are both in |
9676
+ | Y the range of 0-49, the date is in the current century. |
9677
+ | Example: Date with value '24-366' |
9678
+ | +-------------------------------------------------+ |
9679
+ | | data formatter value | |
9680
+ | +-------------------------------------------------+ |
9681
+ | | 24-366 YY-DDD 24/12/31 | |
9682
+ | +-------------------------------------------------+ |
9683
+ +--------------------------------------------------------------------------------------------------+
9684
+
9685
+ RAISES:
9686
+ TypeError, ValueError, TeradataMlException
9687
+
9688
+ Returns:
9689
+ ColumnExpression
9690
+
9691
+ EXAMPLES:
9692
+ # Load the data to run the example.
9693
+ >>> load_example_data("uaf", "stock_data")
9694
+
9695
+ # Create a DataFrame on 'stock_data' table.
9696
+ >>> df = DataFrame("stock_data")
9697
+ >>> df
9698
+ seq_no timevalue magnitude
9699
+ data_set_id
9700
+ 556 3 19/01/16 61.080
9701
+ 556 5 19/01/30 63.810
9702
+ 556 6 19/02/06 63.354
9703
+ 556 7 19/02/13 63.871
9704
+ 556 9 19/02/27 61.490
9705
+ 556 10 19/03/06 61.524
9706
+ 556 8 19/02/20 61.886
9707
+ 556 4 19/01/23 63.900
9708
+ 556 2 19/01/09 61.617
9709
+ 556 1 19/01/02 60.900
9710
+
9711
+ # create new_column "timevalue_char" using to_char().
9712
+ >>> new_df = df.assign(timevalue_char=df.timevalue.to_char('DD-MON-YYYY'))
9713
+ >>> new_df
9714
+ seq_no timevalue magnitude timevalue_char
9715
+ data_set_id
9716
+ 556 3 19/01/16 61.080 16-JAN-2019
9717
+ 556 5 19/01/30 63.810 30-JAN-2019
9718
+ 556 6 19/02/06 63.354 06-FEB-2019
9719
+ 556 7 19/02/13 63.871 13-FEB-2019
9720
+ 556 9 19/02/27 61.490 27-FEB-2019
9721
+ 556 10 19/03/06 61.524 06-MAR-2019
9722
+ 556 8 19/02/20 61.886 20-FEB-2019
9723
+ 556 4 19/01/23 63.900 23-JAN-2019
9724
+ 556 2 19/01/09 61.617 09-JAN-2019
9725
+ 556 1 19/01/02 60.900 02-JAN-2019
9726
+
9727
+ # Example 1: convert "timevalue_char" column to DATE type.
9728
+ >>> res = new_df.assign(timevalue_char=new_df.timevalue_char.to_date('DD-MON-YYYY'))
9729
+ >>> res
9730
+ seq_no timevalue magnitude timevalue_char
9731
+ data_set_id
9732
+ 556 3 19/01/16 61.080 19/01/16
9733
+ 556 5 19/01/30 63.810 19/01/30
9734
+ 556 6 19/02/06 63.354 19/02/06
9735
+ 556 7 19/02/13 63.871 19/02/13
9736
+ 556 9 19/02/27 61.490 19/02/27
9737
+ 556 10 19/03/06 61.524 19/03/06
9738
+ 556 8 19/02/20 61.886 19/02/20
9739
+ 556 4 19/01/23 63.900 19/01/23
9740
+ 556 2 19/01/09 61.617 19/01/09
9741
+ 556 1 19/01/02 60.900 19/01/02
9742
+ >>> res.tdtypes
9743
+ column type
9744
+ data_set_id INTEGER()
9745
+ seq_no INTEGER()
9746
+ timevalue DATE()
9747
+ magnitude FLOAT()
9748
+ timevalue_char DATE()
9749
+ """
9750
+ arg_validate = []
9751
+ arg_validate.append(["formatter", formatter, True, (str), True])
9752
+
9753
+ # Validate argument types
9754
+ _Validators._validate_function_arguments(arg_validate)
9755
+
9756
+ _args = [self.expression]
9757
+ if formatter:
9758
+ _args.append(formatter)
9759
+ return _SQLColumnExpression(func.to_date(*_args), type=DATE())
9760
+
9761
+ def trunc(self, expression=0, formatter=None):
9762
+ """
9763
+ DESCRIPTION:
9764
+ Function to truncate the values inside the column based on formatter.
9765
+ Numeric type column:
9766
+ Function returns the values in column truncated places_value (expression) places to the right or left
9767
+ of the decimal point.
9768
+ trunc() functions as follows:
9769
+ * It truncates places_value places to the right of the decimal point if
9770
+ places_value is positive.
9771
+ * It truncates (makes 0) places_value places to the left of the decimal
9772
+ point if places_value is negative.
9773
+ * It truncates to 0 places if places_value is zero or is omitted.
9774
+ * If numeric_value or places_value is NULL, the function returns NULL.
9775
+ Date type column:
9776
+ Function truncates date type based on the format specified by formatter.
9777
+ Example:
9778
+ First example truncates data to first day of the week.
9779
+ Second example truncates data to beginning of the month.
9780
+ +------------------------------------------+
9781
+ | data formatter result|
9782
+ +------------------------------------------+
9783
+ | 19/01/16 'D' 19/01/13|
9784
+ | 19/02/27 'MON' 19/02/01|
9785
+ +------------------------------------------+
9786
+ PARAMETERS:
9787
+ expression:
9788
+ Optional Argument.
9789
+ Specifies to truncate the "expression" number of digits.
9790
+ Note:
9791
+ This argument applicable only for Numeric columns.
9792
+ Default Value: 0
9793
+ Types: ColumnExpression OR int
9794
+
9795
+ formatter:
9796
+ Optional Argument.
9797
+ Specifies a literal string to truncate the values of column.
9798
+ If 'formatter' is omitted, date_value is truncated to the nearest day.
9799
+ Type: str
9800
+ Note:
9801
+ * This argument applicable only for Date type columns.
9802
+ * Various formatter given below:
9803
+ +--------------------------------------------------------------------------------------------------+
9804
+ | FORMATTER DESCRIPTION |
9805
+ +--------------------------------------------------------------------------------------------------+
9806
+ | CC |
9807
+ | SCC One year greater than the first two digits of a 4-digit year.|
9808
+ | Example: |
9809
+ | +-------------------------------------------------+ |
9810
+ | | data formatter result | |
9811
+ | +-------------------------------------------------+ |
9812
+ | | 19/01/16 CC 01/01/01 | |
9813
+ | +-------------------------------------------------+ |
9814
+ +--------------------------------------------------------------------------------------------------+
9815
+ | SYYY |
9816
+ | YYYY |
9817
+ | YEAR |
9818
+ | SYEAR Year. Returns a value of 1, the first day of the year. |
9819
+ | YYY |
9820
+ | YY |
9821
+ | Y |
9822
+ | Example: |
9823
+ | +-------------------------------------------------+ |
9824
+ | | data formatter result | |
9825
+ | +-------------------------------------------------+ |
9826
+ | | 19/01/16 CC 19/01/01 | |
9827
+ | +-------------------------------------------------+ |
9828
+ +--------------------------------------------------------------------------------------------------+
9829
+ | IYYY |
9830
+ | IYY ISO year |
9831
+ | IY |
9832
+ | I |
9833
+ | Example: |
9834
+ | +-------------------------------------------------+ |
9835
+ | | data formatter result | |
9836
+ | +-------------------------------------------------+ |
9837
+ | | 19/01/16 CC 18/12/31 | |
9838
+ | +-------------------------------------------------+ |
9839
+ +--------------------------------------------------------------------------------------------------+
9840
+ | MONTH |
9841
+ | MON Month. Returns a value of 1, the first day of the month. |
9842
+ | MM |
9843
+ | RM |
9844
+ | Example: |
9845
+ | +-------------------------------------------------+ |
9846
+ | | data formatter result | |
9847
+ | +-------------------------------------------------+ |
9848
+ | | 19/02/16 RM 19/02/01 | |
9849
+ | +-------------------------------------------------+ |
9850
+ +--------------------------------------------------------------------------------------------------+
9851
+ | Q Quarter. Returns a value of 1, the first day of the quarter. |
9852
+ | Example: |
9853
+ | +-------------------------------------------------+ |
9854
+ | | data formatter result | |
9855
+ | +-------------------------------------------------+ |
9856
+ | | 19/02/16 Q 19/01/01 | |
9857
+ | +-------------------------------------------------+ |
9858
+ +--------------------------------------------------------------------------------------------------+
9859
+ | WW Same day of the week as the 1st day of the year. |
9860
+ | Example: |
9861
+ | +-------------------------------------------------+ |
9862
+ | | data formatter result | |
9863
+ | +-------------------------------------------------+ |
9864
+ | | 19/02/16 WW 19/02/15 | |
9865
+ | +-------------------------------------------------+ |
9866
+ +--------------------------------------------------------------------------------------------------+
9867
+ | IW Same day of the week as the first day of the ISO year. |
9868
+ | Example: |
9869
+ | +-------------------------------------------------+ |
9870
+ | | data formatter result | |
9871
+ | +-------------------------------------------------+ |
9872
+ | | 19/02/16 RM 19/02/14 | |
9873
+ | +-------------------------------------------------+ |
9874
+ +--------------------------------------------------------------------------------------------------+
9875
+ | W Same day of the week as the first day of the month. |
9876
+ | Example: |
9877
+ | +-------------------------------------------------+ |
9878
+ | | data formatter result | |
9879
+ | +-------------------------------------------------+ |
9880
+ | | 19/02/16 W 19/02/15 | |
9881
+ | +-------------------------------------------------+ |
9882
+ +--------------------------------------------------------------------------------------------------+
9883
+ | DDD |
9884
+ | DD Day. |
9885
+ | J |
9886
+ | Example: |
9887
+ | +-------------------------------------------------+ |
9888
+ | | data formatter result | |
9889
+ | +-------------------------------------------------+ |
9890
+ | | 19/02/16 DDD 19/02/16 | |
9891
+ | +-------------------------------------------------+ |
9892
+ +--------------------------------------------------------------------------------------------------+
9893
+ | DAY |
9894
+ | DY Starting day of the week. |
9895
+ | D |
9896
+ | Example: |
9897
+ | +-------------------------------------------------+ |
9898
+ | | data formatter result | |
9899
+ | +-------------------------------------------------+ |
9900
+ | | 19/01/16 DAY 19/02/13 | |
9901
+ | +-------------------------------------------------+ |
9902
+ +--------------------------------------------------------------------------------------------------+
9903
+ | HH |
9904
+ | HH12 Hour. |
9905
+ | HH24 |
9906
+ | Example: |
9907
+ | +-------------------------------------------------+ |
9908
+ | | data formatter result | |
9909
+ | +-------------------------------------------------+ |
9910
+ | | 19/02/16 HH 19/02/16 | |
9911
+ | +-------------------------------------------------+ |
9912
+ +--------------------------------------------------------------------------------------------------+
9913
+ | MI Minute. |
9914
+ | Example: |
9915
+ | +-------------------------------------------------+ |
9916
+ | | data formatter result | |
9917
+ | +-------------------------------------------------+ |
9918
+ | | 2016-01-06 09:08:01.000000 MI 16/01/06 | |
9919
+ | +-------------------------------------------------+ |
9920
+ +--------------------------------------------------------------------------------------------------+
9921
+
9922
+ RAISES:
9923
+ TypeError, ValueError, TeradataMlException
9924
+
9925
+ RETURNS:
9926
+ ColumnExpression
9927
+
9928
+ EXAMPLES:
9929
+ # Load the data to execute the example.
9930
+ >>> load_example_data("dataframe", "admissions_train")
9931
+ >>> load_example_data("uaf", "stock_data")
9932
+
9933
+ # Create a DataFrame on 'admissions_train' table.
9934
+ >>> df = DataFrame("admissions_train").iloc[:4]
9935
+ >>> df
9936
+ masters gpa stats programming admitted
9937
+ id
9938
+ 3 no 3.70 Novice Beginner 1
9939
+ 4 yes 3.50 Beginner Novice 1
9940
+ 2 yes 3.76 Beginner Beginner 0
9941
+ 1 yes 3.95 Beginner Beginner 0
9942
+
9943
+ # Create a DataFrame on 'stock_data' table.
9944
+ >>> df1 = DataFrame("stock_data")
9945
+ >>> df1
9946
+ seq_no timevalue magnitude
9947
+ data_set_id
9948
+ 556 3 19/01/16 61.080
9949
+ 556 5 19/01/30 63.810
9950
+ 556 6 19/02/06 63.354
9951
+ 556 7 19/02/13 63.871
9952
+ 556 9 19/02/27 61.490
9953
+ 556 10 19/03/06 61.524
9954
+ 556 8 19/02/20 61.886
9955
+ 556 4 19/01/23 63.900
9956
+ 556 2 19/01/09 61.617
9957
+ 556 1 19/01/02 60.900
9958
+
9959
+ # Example 1: Truncate the value of 'gpa' to 0 decimal place and 1 decimal place.
9960
+ >>> res = df.assign(col = df.gpa.trunc(),
9961
+ col_1 = df.gpa.trunc(1))
9962
+ >>> res
9963
+ masters gpa stats programming admitted col col_1
9964
+ id
9965
+ 3 no 3.70 Novice Beginner 1 3.0 3.7
9966
+ 4 yes 3.50 Beginner Novice 1 3.0 3.5
9967
+ 2 yes 3.76 Beginner Beginner 0 3.0 3.7
9968
+ 1 yes 3.95 Beginner Beginner 0 3.0 3.9
9969
+
9970
+ # Example 2: Get the records with gpa > 3.7 by rounding the gpa to single decimal point.
9971
+ >>> df[df.gpa.trunc(1) > 3.7]
9972
+ masters gpa stats programming admitted
9973
+ id
9974
+ 1 yes 3.95 Beginner Beginner 0
9975
+
9976
+ # Example 3: Truncate the value of 'timevalue' to beginning of the month.
9977
+ >>> res=df1.assign(timevalue=df1.timevalue.trunc(formatter="MON"))
9978
+ >>> res
9979
+ seq_no timevalue magnitude time_value
9980
+ data_set_id
9981
+ 556 3 19/01/16 61.080 19/01/01
9982
+ 556 5 19/01/30 63.810 19/01/01
9983
+ 556 6 19/02/06 63.354 19/02/01
9984
+ 556 7 19/02/13 63.871 19/02/01
9985
+ 556 9 19/02/27 61.490 19/02/01
9986
+ 556 10 19/03/06 61.524 19/03/01
9987
+ 556 8 19/02/20 61.886 19/02/01
9988
+ 556 4 19/01/23 63.900 19/01/01
9989
+ 556 2 19/01/09 61.617 19/01/01
9990
+ 556 1 19/01/02 60.900 19/01/01
9991
+
9992
+ """
9993
+ numeric_types=[INTEGER, SMALLINT, BIGINT, BYTEINT, DECIMAL, FLOAT, NUMBER]
9994
+ _args = [self.expression]
9995
+ if type(self.type) in numeric_types:
9996
+ if isinstance(expression, ColumnExpression):
9997
+ _args.append(expression.expression)
9998
+ else:
9999
+ _args.append(expression)
10000
+ elif formatter:
10001
+ _args.append(formatter)
10002
+ return _SQLColumnExpression(func.trunc(*_args))
10003
+
10004
+ def __get_columns(self, col_expr):
10005
+ """
10006
+ DESCRIPTION:
10007
+ Function to get the columns involved in a sqlalchemy expression.
10008
+
10009
+ PARAMETERS:
10010
+ col_expr:
10011
+ Required Argument.
10012
+ Specifies the sqlalchemy expression.
10013
+ Types: BinaryExpression OR Grouping OR GenericFunction OR ClauseList OR Column
10014
+
10015
+ RAISES:
10016
+ None
10017
+
10018
+ RETURNS:
10019
+ list
10020
+
10021
+ EXAMPLES:
10022
+ >>> self.__get_columns(self.expression)
10023
+ """
10024
+ # If it is a column, return the name of the column.
10025
+ if isinstance(col_expr, Column):
10026
+ return [col_expr.name]
10027
+
10028
+ # Every other type exposes a method to retrieve the children. Recursively, walk through all
10029
+ # the childs till a Column or a Bind Parameter is reached.
10030
+ elif isinstance(col_expr, (BinaryExpression, Grouping, GenericFunction, ClauseList, Function)):
10031
+ res = []
10032
+ for c in col_expr.get_children():
10033
+ res = res + self.__get_columns(c)
10034
+ return res
10035
+ else:
10036
+ try:
10037
+ if isinstance(col_expr, ExpressionClauseList):
10038
+ res = []
10039
+ for c in col_expr.get_children():
10040
+ res = res + self.__get_columns(c)
10041
+ return res
10042
+ except NameError:
10043
+ pass
10044
+ # If the child is a Bind Parameter, return empty string.
10045
+ return []
10046
+
10047
+ @property
10048
+ def _all_columns(self):
10049
+ """
10050
+ DESCRIPTION:
10051
+ A property to get the columns involved in ColumnExpression.
10052
+
10053
+ RAISES:
10054
+ None
10055
+
10056
+ RETURNS:
10057
+ list
10058
+
10059
+ EXAMPLES:
10060
+ >>> self._all_columns
10061
+ """
10062
+ return list(set(self.__get_columns(self.expression)))
10063
+
10064
+ def _get_sqlalchemy_tables(self, expression):
10065
+ """
10066
+ DESCRIPTION:
10067
+ Internal function to get the corresponding SQLAlchemy tables involved
10068
+ in an expression.
10069
+
10070
+ RAISES:
10071
+ None
10072
+
10073
+ RETURNS:
10074
+ list
10075
+
10076
+ EXAMPLES:
10077
+ >>> self._get_sqlalchemy_tables(expression)
10078
+ """
10079
+
10080
+ # check if it is a sqlalchemy Column or not.
10081
+ if isinstance(expression, Column):
10082
+ return [expression.table]
10083
+
10084
+ result = []
10085
+ if hasattr(expression, "get_children"):
10086
+ for obj in expression.get_children():
10087
+ result = result + self._get_sqlalchemy_tables(obj)
10088
+ return list(set(result))
10089
+
10090
+ return []