teradataml 20.0.0.5__py3-none-any.whl → 20.0.0.7__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 (119) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/README.md +306 -0
  3. teradataml/__init__.py +1 -1
  4. teradataml/_version.py +1 -1
  5. teradataml/analytics/analytic_function_executor.py +162 -76
  6. teradataml/analytics/byom/__init__.py +1 -1
  7. teradataml/analytics/json_parser/__init__.py +2 -0
  8. teradataml/analytics/json_parser/analytic_functions_argument.py +95 -2
  9. teradataml/analytics/json_parser/metadata.py +22 -4
  10. teradataml/analytics/sqle/DecisionTreePredict.py +3 -2
  11. teradataml/analytics/sqle/NaiveBayesPredict.py +3 -2
  12. teradataml/analytics/sqle/__init__.py +3 -0
  13. teradataml/analytics/utils.py +59 -11
  14. teradataml/automl/__init__.py +2369 -464
  15. teradataml/automl/autodataprep/__init__.py +15 -0
  16. teradataml/automl/custom_json_utils.py +184 -112
  17. teradataml/automl/data_preparation.py +113 -58
  18. teradataml/automl/data_transformation.py +154 -53
  19. teradataml/automl/feature_engineering.py +113 -53
  20. teradataml/automl/feature_exploration.py +548 -25
  21. teradataml/automl/model_evaluation.py +260 -32
  22. teradataml/automl/model_training.py +399 -206
  23. teradataml/clients/auth_client.py +10 -6
  24. teradataml/clients/keycloak_client.py +165 -0
  25. teradataml/common/aed_utils.py +11 -2
  26. teradataml/common/bulk_exposed_utils.py +4 -2
  27. teradataml/common/constants.py +72 -2
  28. teradataml/common/exceptions.py +32 -0
  29. teradataml/common/garbagecollector.py +50 -21
  30. teradataml/common/messagecodes.py +73 -1
  31. teradataml/common/messages.py +27 -1
  32. teradataml/common/sqlbundle.py +25 -7
  33. teradataml/common/utils.py +210 -22
  34. teradataml/context/aed_context.py +16 -10
  35. teradataml/context/context.py +37 -9
  36. teradataml/data/Employee.csv +5 -0
  37. teradataml/data/Employee_Address.csv +4 -0
  38. teradataml/data/Employee_roles.csv +5 -0
  39. teradataml/data/JulesBelvezeDummyData.csv +100 -0
  40. teradataml/data/byom_example.json +5 -0
  41. teradataml/data/creditcard_data.csv +284618 -0
  42. teradataml/data/docs/byom/docs/ONNXSeq2Seq.py +255 -0
  43. teradataml/data/docs/sqle/docs_17_10/NGramSplitter.py +1 -1
  44. teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +1 -1
  45. teradataml/data/docs/sqle/docs_17_20/TextParser.py +1 -1
  46. teradataml/data/jsons/byom/ONNXSeq2Seq.json +287 -0
  47. teradataml/data/jsons/byom/onnxembeddings.json +1 -0
  48. teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +3 -7
  49. teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +3 -7
  50. teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +3 -7
  51. teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +3 -7
  52. teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +3 -7
  53. teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +3 -7
  54. teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +3 -7
  55. teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +3 -7
  56. teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +3 -7
  57. teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +3 -7
  58. teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +3 -7
  59. teradataml/data/jsons/sqle/20.00/TD_API_AzureML.json +151 -0
  60. teradataml/data/jsons/sqle/20.00/TD_API_Sagemaker.json +182 -0
  61. teradataml/data/jsons/sqle/20.00/TD_API_VertexAI.json +183 -0
  62. teradataml/data/load_example_data.py +29 -11
  63. teradataml/data/pattern_matching_data.csv +11 -0
  64. teradataml/data/payment_fraud_dataset.csv +10001 -0
  65. teradataml/data/sdk/modelops/modelops_spec.json +101737 -0
  66. teradataml/data/teradataml_example.json +75 -1
  67. teradataml/data/url_data.csv +10 -9
  68. teradataml/dataframe/copy_to.py +715 -55
  69. teradataml/dataframe/dataframe.py +2115 -97
  70. teradataml/dataframe/dataframe_utils.py +66 -28
  71. teradataml/dataframe/functions.py +1130 -2
  72. teradataml/dataframe/setop.py +4 -1
  73. teradataml/dataframe/sql.py +710 -1039
  74. teradataml/dbutils/dbutils.py +470 -35
  75. teradataml/dbutils/filemgr.py +1 -1
  76. teradataml/hyperparameter_tuner/optimizer.py +456 -142
  77. teradataml/hyperparameter_tuner/utils.py +4 -2
  78. teradataml/lib/aed_0_1.dll +0 -0
  79. teradataml/lib/libaed_0_1.dylib +0 -0
  80. teradataml/lib/libaed_0_1.so +0 -0
  81. teradataml/lib/libaed_0_1_aarch64.so +0 -0
  82. teradataml/opensource/_base.py +7 -1
  83. teradataml/options/configure.py +20 -4
  84. teradataml/scriptmgmt/UserEnv.py +247 -36
  85. teradataml/scriptmgmt/lls_utils.py +140 -39
  86. teradataml/sdk/README.md +79 -0
  87. teradataml/sdk/__init__.py +4 -0
  88. teradataml/sdk/_auth_modes.py +422 -0
  89. teradataml/sdk/_func_params.py +487 -0
  90. teradataml/sdk/_json_parser.py +453 -0
  91. teradataml/sdk/_openapi_spec_constants.py +249 -0
  92. teradataml/sdk/_utils.py +236 -0
  93. teradataml/sdk/api_client.py +900 -0
  94. teradataml/sdk/constants.py +62 -0
  95. teradataml/sdk/modelops/__init__.py +98 -0
  96. teradataml/sdk/modelops/_client.py +409 -0
  97. teradataml/sdk/modelops/_constants.py +304 -0
  98. teradataml/sdk/modelops/models.py +2308 -0
  99. teradataml/sdk/spinner.py +107 -0
  100. teradataml/series/series.py +12 -7
  101. teradataml/store/feature_store/constants.py +601 -234
  102. teradataml/store/feature_store/feature_store.py +2886 -616
  103. teradataml/store/feature_store/mind_map.py +639 -0
  104. teradataml/store/feature_store/models.py +5831 -214
  105. teradataml/store/feature_store/utils.py +390 -0
  106. teradataml/table_operators/query_generator.py +4 -21
  107. teradataml/table_operators/table_operator_util.py +1 -1
  108. teradataml/table_operators/templates/dataframe_register.template +6 -2
  109. teradataml/table_operators/templates/dataframe_udf.template +6 -2
  110. teradataml/utils/docstring.py +527 -0
  111. teradataml/utils/dtypes.py +95 -1
  112. teradataml/utils/internal_buffer.py +2 -2
  113. teradataml/utils/utils.py +41 -3
  114. teradataml/utils/validators.py +699 -18
  115. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/METADATA +312 -2
  116. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/RECORD +119 -87
  117. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/WHEEL +0 -0
  118. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/top_level.txt +0 -0
  119. {teradataml-20.0.0.5.dist-info → teradataml-20.0.0.7.dist-info}/zip-safe +0 -0
@@ -200,11 +200,10 @@ class _MetaExpression(object):
200
200
  RAISES:
201
201
  AttributeError if attribute can't be found
202
202
  """
203
-
204
- res = getattr(self.__t, key, None)
205
- if res is None:
203
+ try:
204
+ res = getattr(self.__t, key)
205
+ except AttributeError:
206
206
  raise AttributeError('Unable to find attribute: %s' % key)
207
-
208
207
  return res
209
208
 
210
209
  @property
@@ -501,7 +500,7 @@ class _SQLTableExpression(_PandasTableExpression):
501
500
  self.c = [_SQLColumnExpression(c) for c in table.c]
502
501
 
503
502
  self._n_rows = 0
504
-
503
+ self._datalake = kw.get('datalake', None)
505
504
 
506
505
  @property
507
506
  def c(self):
@@ -557,6 +556,13 @@ class _SQLTableExpression(_PandasTableExpression):
557
556
 
558
557
  self.__t = table
559
558
 
559
+ @property
560
+ def datalake(self):
561
+ """
562
+ Returns the underlying datalake information
563
+ """
564
+ return self._datalake
565
+
560
566
  def __repr__(self):
561
567
  """
562
568
  Returns a SELECT TOP string representing the underlying table.
@@ -6738,8 +6744,42 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6738
6744
  """
6739
6745
  return _SQLColumnExpression(self.expression.distinct().label(self.name))
6740
6746
 
6747
+ def _format_ilike_like_args(self, other, escape_char=None):
6748
+ """
6749
+ DESCRIPTION:
6750
+ Internal function to validate and format the arguments passed to
6751
+ 'ilike' and 'like' functions.
6752
+
6753
+ PARAMETERS:
6754
+ other:
6755
+ Required Argument.
6756
+ Specifies a string to match.
6757
+ Types: str OR ColumnExpression
6758
+
6759
+ escape_char:
6760
+ Optional Argument.
6761
+ Specifies the escape character to be used in the pattern.
6762
+ Types: str with one character
6763
+
6764
+ RETURNS:
6765
+ tuple
6766
+
6767
+ EXAMPLES:
6768
+ self._format_ilike_like_args(other='A!%', escape_char='!')
6769
+ """
6770
+ # Validate the arguments.
6771
+ arg_validate = []
6772
+ arg_validate.append(["other", other, False, (str, ColumnExpression), True])
6773
+ arg_validate.append(["escape_char", escape_char, True, (str), True])
6774
+ _Validators._validate_function_arguments(arg_validate)
6775
+
6776
+ # Format the arguments for ilike/like function.
6777
+ other = "{}".format(other.compile()) if isinstance(other, ColumnExpression) else "'{}'".format(other)
6778
+ escape = " ESCAPE '{}'".format(escape_char) if escape_char is not None else ""
6779
+ return other, escape
6780
+
6741
6781
  @collect_queryband(queryband="DFC_ilike")
6742
- def ilike(self, other):
6782
+ def ilike(self, other, escape_char=None):
6743
6783
  """
6744
6784
  DESCRIPTION:
6745
6785
  Function which is used to match the pattern.
@@ -6748,67 +6788,95 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6748
6788
  other:
6749
6789
  Required Argument.
6750
6790
  Specifies a string to match. String match is case insensitive.
6751
- Types: str
6791
+ Types: str OR ColumnExpression
6792
+
6793
+ escape_char:
6794
+ Optional Argument.
6795
+ Specifies the escape character to be used in the pattern.
6796
+ Types: str with one character
6752
6797
 
6753
6798
  RETURNS:
6754
6799
  ColumnExpression.
6755
6800
 
6756
6801
  EXAMPLES:
6757
- >>> load_example_data("dataframe","admissions_train")
6758
- >>> df = DataFrame.from_table('admissions_train')
6759
- masters gpa stats programming admitted
6760
- id
6761
- 13 no 4.00 Advanced Novice 1
6762
- 26 yes 3.57 Advanced Advanced 1
6763
- 5 no 3.44 Novice Novice 0
6764
- 19 yes 1.98 Advanced Advanced 0
6765
- 15 yes 4.00 Advanced Advanced 1
6766
- 40 yes 3.95 Novice Beginner 0
6767
- 7 yes 2.33 Novice Novice 1
6768
- 22 yes 3.46 Novice Beginner 0
6769
- 36 no 3.00 Advanced Novice 0
6770
- 38 yes 2.65 Advanced Beginner 1
6771
-
6772
- # Example 1: Find out the records whose stats starts with 'A'.
6773
- >>> df = df[df.stats.ilike('a%')]
6802
+ # Load example data.
6803
+ >>> load_example_data("teradataml", "pattern_matching_data")
6804
+ >>> df = DataFrame('pattern_matching_data')
6805
+ data pattern level
6806
+ id
6807
+ 5 prod_01 prod_01% Beginner
6808
+ 8 log%2024 l_g% Beginner
6809
+ 2 user%2025 user!%% Beginner
6810
+ 6 prod%v2 prod!_% Novice
6811
+ 4 data%backup data@%% Advanced
6812
+ 10 backup_9 restore!_9 Beginner
6813
+ 7 log_file log^_file Advanced
6814
+ 1 user_Alpha user!_% Advanced
6815
+ 3 data_2024 d% Novice
6816
+ 9 temp_file temp!__% Novice
6817
+
6818
+ # Example 1: Find out the records which starts with 'A' in the column 'level'.
6819
+ >>> df = df[df.level.ilike('A%')]
6774
6820
  >>> df
6775
- masters gpa stats programming admitted
6776
- id
6777
- 19 yes 1.98 Advanced Advanced 0
6778
- 15 yes 4.00 Advanced Advanced 1
6779
- 38 yes 2.65 Advanced Beginner 1
6780
- 26 yes 3.57 Advanced Advanced 1
6781
- 17 no 3.83 Advanced Advanced 1
6782
- 34 yes 3.85 Advanced Beginner 0
6783
- 13 no 4.00 Advanced Novice 1
6784
- 24 no 1.87 Advanced Novice 1
6785
- 36 no 3.00 Advanced Novice 0
6786
- 27 yes 3.96 Advanced Advanced 0
6821
+ data pattern level
6822
+ id
6823
+ 4 data%backup data@%% Advanced
6824
+ 7 log_file log^_file Advanced
6825
+ 1 user_Alpha user!_% Advanced
6787
6826
  >>>
6788
6827
 
6789
6828
  # Example 2: Create a new Column with values as -
6790
- # 1 if value of column 'stats' starts with 'a' and third letter is 'v',
6829
+ # 1 if value of column 'level' starts with 'n' and third letter is 'v',
6791
6830
  # 0 otherwise. Ignore case.
6792
- >>> df.assign(new_col = case_when((df.stats.ilike('a_v%').expression, 1), else_=0))
6793
- masters gpa stats programming admitted n
6794
- id
6795
- 13 no 4.00 Advanced Novice 1 1
6796
- 26 yes 3.57 Advanced Advanced 1 1
6797
- 5 no 3.44 Novice Novice 0 0
6798
- 19 yes 1.98 Advanced Advanced 0 1
6799
- 15 yes 4.00 Advanced Advanced 1 1
6800
- 40 yes 3.95 Novice Beginner 0 0
6801
- 7 yes 2.33 Novice Novice 1 0
6802
- 22 yes 3.46 Novice Beginner 0 0
6803
- 36 no 3.00 Advanced Novice 0 1
6804
- 38 yes 2.65 Advanced Beginner 1 1
6831
+ >>> from sqlalchemy.sql.expression import case as case_when
6832
+ >>> df.assign(new_col = case_when((df.level.ilike('n_v%').expression, 1), else_=0))
6833
+ data pattern level new_col
6834
+ id
6835
+ 3 data_2024 d% Novice 1
6836
+ 1 user_Alpha user!_% Advanced 0
6837
+ 8 log%2024 l_g% Beginner 0
6838
+ 2 user%2025 user!%% Beginner 0
6839
+ 10 backup_9 restore!_9 Beginner 0
6840
+ 9 temp_file temp!__% Novice 1
6841
+ 6 prod%v2 prod!_% Novice 1
6842
+ 5 prod_01 prod_01% Beginner 0
6843
+ 4 data%backup data@%% Advanced 0
6844
+ 7 log_file log^_file Advanced 0
6845
+ >>>
6846
+
6847
+ # Example 3: Find out the records where the value in the 'data' column
6848
+ # matches the pattern specified in the 'pattern' column.
6849
+ >>> df = df[df.data.ilike(df.pattern)]
6850
+ >>> df
6851
+ data pattern level
6852
+ id
6853
+ 3 data_2024 d% Novice
6854
+ 8 log%2024 l_g% Beginner
6855
+ 5 prod_01 prod_01% Beginner
6856
+ >>>
6857
+
6858
+ # Example 4: Find out the records where the value in the 'data' column
6859
+ # matches the pattern specified in the 'pattern' column considering the
6860
+ # escape character as '!'.
6861
+ >>> df = df[df.data.ilike(df.pattern, escape_char='!')]
6862
+ >>> df
6863
+ data pattern level
6864
+ id
6865
+ 8 log%2024 l_g% Beginner
6866
+ 9 temp_file temp!__% Novice
6867
+ 3 data_2024 d% Novice
6868
+ 2 user%2025 user!%% Beginner
6869
+ 1 user_Alpha user!_% Advanced
6870
+ 5 prod_01 prod_01% Beginner
6805
6871
  >>>
6806
6872
  """
6873
+ # Validate and format arguments
6874
+ other, escape = self._format_ilike_like_args(other, escape_char)
6807
6875
  return _SQLColumnExpression(
6808
- literal_column("{} (NOT CASESPECIFIC) LIKE '{}'".format(self.compile(), other)))
6876
+ literal_column("{} (NOT CASESPECIFIC) LIKE {}{}".format(self.compile(), other, escape)))
6809
6877
 
6810
6878
  @collect_queryband(queryband="DFC_like")
6811
- def like(self, other):
6879
+ def like(self, other, escape_char=None):
6812
6880
  """
6813
6881
  DESCRIPTION:
6814
6882
  Function which is used to match the pattern.
@@ -6816,66 +6884,190 @@ class _SQLColumnExpression(_LogicalColumnExpression,
6816
6884
  PARAMETERS:
6817
6885
  other:
6818
6886
  Required Argument.
6819
- Specifies a string to match. String match is case insensitive.
6820
- Types: str
6887
+ Specifies a string to match. String match is case sensitive.
6888
+ Types: str OR ColumnExpression
6889
+
6890
+ escape_char:
6891
+ Optional Argument.
6892
+ Specifies the escape character to be used in the pattern.
6893
+ Types: str with one character
6821
6894
 
6822
6895
  RETURNS:
6823
6896
  ColumnExpression.
6824
6897
 
6825
6898
  EXAMPLES:
6826
- >>> load_example_data("dataframe","admissions_train")
6827
- >>> df = DataFrame.from_table('admissions_train')
6828
- masters gpa stats programming admitted
6829
- id
6830
- 13 no 4.00 Advanced Novice 1
6831
- 26 yes 3.57 Advanced Advanced 1
6832
- 5 no 3.44 Novice Novice 0
6833
- 19 yes 1.98 Advanced Advanced 0
6834
- 15 yes 4.00 Advanced Advanced 1
6835
- 40 yes 3.95 Novice Beginner 0
6836
- 7 yes 2.33 Novice Novice 1
6837
- 22 yes 3.46 Novice Beginner 0
6838
- 36 no 3.00 Advanced Novice 0
6839
- 38 yes 2.65 Advanced Beginner 1
6840
-
6841
- # Example 1: Find out the records whose stats starts with 'A'.
6842
- >>> df = df[df.stats.like('A%')]
6899
+ # Load example data.
6900
+ >>> load_example_data("teradataml", "pattern_matching_data")
6901
+ >>> df = DataFrame('pattern_matching_data')
6902
+ data pattern level
6903
+ id
6904
+ 5 prod_01 prod_01% Beginner
6905
+ 8 log%2024 l_g% Beginner
6906
+ 2 user%2025 user!%% Beginner
6907
+ 6 prod%v2 prod!_% Novice
6908
+ 4 data%backup data@%% Advanced
6909
+ 10 backup_9 restore!_9 Beginner
6910
+ 7 log_file log^_file Advanced
6911
+ 1 user_Alpha user!_% Advanced
6912
+ 3 data_2024 d% Novice
6913
+ 9 temp_file temp!__% Novice
6914
+
6915
+ # Example 1: Find out the records which starts with 'A' in the column 'level'.
6916
+ >>> df = df[df.level.like('A%')]
6843
6917
  >>> df
6844
- masters gpa stats programming admitted
6845
- id
6846
- 19 yes 1.98 Advanced Advanced 0
6847
- 15 yes 4.00 Advanced Advanced 1
6848
- 38 yes 2.65 Advanced Beginner 1
6849
- 26 yes 3.57 Advanced Advanced 1
6850
- 17 no 3.83 Advanced Advanced 1
6851
- 34 yes 3.85 Advanced Beginner 0
6852
- 13 no 4.00 Advanced Novice 1
6853
- 24 no 1.87 Advanced Novice 1
6854
- 36 no 3.00 Advanced Novice 0
6855
- 27 yes 3.96 Advanced Advanced 0
6918
+ data pattern level
6919
+ id
6920
+ 4 data%backup data@%% Advanced
6921
+ 7 log_file log^_file Advanced
6922
+ 1 user_Alpha user!_% Advanced
6856
6923
  >>>
6857
6924
 
6858
6925
  # Example 2: Create a new Column with values as -
6859
- # 1 if value of column 'stats' starts with 'A' and third letter is 'v',
6926
+ # 1 if value of column 'stats' starts with 'N' and third letter is 'v',
6860
6927
  # 0 otherwise. Do not ignore case.
6861
- >>> df.assign(new_col = case_when((df.stats.like('A_v%').expression, 1), else_=0))
6928
+ >>> from sqlalchemy.sql.expression import case as case_when
6929
+ >>> df.assign(new_col = case_when((df.level.like('N_v%').expression, 1), else_=0))
6930
+ data pattern level new_col
6931
+ id
6932
+ 3 data_2024 d% Novice 1
6933
+ 1 user_Alpha user!_% Advanced 0
6934
+ 8 log%2024 l_g% Beginner 0
6935
+ 2 user%2025 user!%% Beginner 0
6936
+ 10 backup_9 restore!_9 Beginner 0
6937
+ 9 temp_file temp!__% Novice 1
6938
+ 6 prod%v2 prod!_% Novice 1
6939
+ 5 prod_01 prod_01% Beginner 0
6940
+ 4 data%backup data@%% Advanced 0
6941
+ 7 log_file log^_file Advanced 0
6942
+ >>>
6943
+
6944
+ # Example 3: Find out the records where the value in the 'data' column
6945
+ # matches the pattern specified in the 'pattern' column.
6946
+ >>> df = df[df.data.like(df.pattern)]
6947
+ >>> df
6948
+ data pattern level
6949
+ id
6950
+ 3 data_2024 d% Novice
6951
+ 8 log%2024 l_g% Beginner
6952
+ 5 prod_01 prod_01% Beginner
6953
+ >>>
6954
+
6955
+ # Example 4: Find out the records where the value in the 'data' column
6956
+ # matches the pattern specified in the 'pattern' column considering the
6957
+ # escape character as '!'.
6958
+ >>> df = df[df.data.like(df.pattern, escape_char='!')]
6862
6959
  >>> df
6863
- masters gpa stats programming admitted n
6864
- id
6865
- 13 no 4.00 Advanced Novice 1 1
6866
- 26 yes 3.57 Advanced Advanced 1 1
6867
- 5 no 3.44 Novice Novice 0 0
6868
- 19 yes 1.98 Advanced Advanced 0 1
6869
- 15 yes 4.00 Advanced Advanced 1 1
6870
- 40 yes 3.95 Novice Beginner 0 0
6871
- 7 yes 2.33 Novice Novice 1 0
6872
- 22 yes 3.46 Novice Beginner 0 0
6873
- 36 no 3.00 Advanced Novice 0 1
6874
- 38 yes 2.65 Advanced Beginner 1 1
6960
+ data pattern level
6961
+ id
6962
+ 8 log%2024 l_g% Beginner
6963
+ 9 temp_file temp!__% Novice
6964
+ 3 data_2024 d% Novice
6965
+ 2 user%2025 user!%% Beginner
6966
+ 1 user_Alpha user!_% Advanced
6967
+ 5 prod_01 prod_01% Beginner
6875
6968
  >>>
6876
6969
  """
6970
+ # Validate and format arguments
6971
+ other, escape = self._format_ilike_like_args(other, escape_char)
6972
+ return _SQLColumnExpression(
6973
+ literal_column("{} (CASESPECIFIC) LIKE {}{}".format(self.compile(), other, escape)))
6974
+
6975
+ def rlike(self, pattern, case_sensitive=True):
6976
+ """
6977
+ DESCRIPTION:
6978
+ Function to match a string against a regular expression pattern.
6979
+
6980
+ PARAMETERS:
6981
+ pattern:
6982
+ Required Argument.
6983
+ Specifies a regular expression pattern to match against the column values.
6984
+ Note:
6985
+ The pattern follows POSIX regular expression syntax.
6986
+ Type: str OR ColumnExpression
6987
+
6988
+ case_sensitive:
6989
+ Optional Argument.
6990
+ Specifies whether the pattern matching is case-sensitive.
6991
+ When set to False, the function ignores case sensitivity and matches
6992
+ the regex. Otherwise, function considers case sensitivity while matching regex.
6993
+ Default: True
6994
+ Type: bool
6995
+
6996
+ RAISES:
6997
+ TeradataMlException
6998
+
6999
+ RETURNS:
7000
+ ColumnExpression
7001
+
7002
+ EXAMPLES:
7003
+ >>> load_example_data("dataframe","admissions_train")
7004
+ >>> df = DataFrame("admissions_train")
7005
+ >>> df
7006
+ masters gpa stats programming admitted
7007
+ id
7008
+ 13 no 4.00 Advanced Novice 1
7009
+ 26 yes 3.57 Advanced Advanced 1
7010
+ 5 no 3.44 Novice Novice 0
7011
+ 19 yes 1.98 Advanced Advanced 0
7012
+ 15 yes 4.00 Advanced Advanced 1
7013
+ 40 yes 3.95 Novice Beginner 0
7014
+ 7 yes 2.33 Novice Novice 1
7015
+ 22 yes 3.46 Novice Beginner 0
7016
+ 36 no 3.00 Advanced Novice 0
7017
+ 38 yes 2.65 Advanced Beginner 1
7018
+
7019
+ # Example 1: Find records whose 'stats' column contains 'van'.
7020
+ >>> result = df[df.stats.rlike('.*van.*')]
7021
+ >>> result
7022
+ masters gpa stats programming admitted
7023
+ id
7024
+ 13 no 4.00 Advanced Novice 1
7025
+ 26 yes 3.57 Advanced Advanced 1
7026
+ 34 yes 3.85 Advanced Beginner 0
7027
+ 19 yes 1.98 Advanced Advanced 0
7028
+ 15 yes 4.00 Advanced Advanced 1
7029
+ 36 no 3.00 Advanced Novice 0
7030
+ 38 yes 2.65 Advanced Beginner 1
7031
+
7032
+ # Example 2: Find records whose 'stats' column ends with 'ced'.
7033
+ >>> result = df[df.stats.rlike('.*ced$')]
7034
+ >>> result
7035
+ masters gpa stats programming admitted
7036
+ id
7037
+ 34 yes 3.85 Advanced Beginner 0
7038
+ 32 yes 3.46 Advanced Beginner 0
7039
+ 11 no 3.13 Advanced Advanced 1
7040
+ 30 yes 3.79 Advanced Novice 0
7041
+ 28 no 3.93 Advanced Advanced 1
7042
+ 16 no 3.70 Advanced Advanced 1
7043
+ 14 yes 3.45 Advanced Advanced 0
7044
+
7045
+ # Example 3: Case-insensitive search for records containing 'NOVICE'.
7046
+ >>> result = df[df.stats.rlike('NOVICE', case_sensitive=False)]
7047
+ >>> result
7048
+ masters gpa stats programming admitted
7049
+ id
7050
+ 12 no 3.65 Novice Novice 1
7051
+ 40 yes 3.95 Novice Beginner 0
7052
+ 7 yes 2.33 Novice Novice 1
7053
+ 5 no 3.44 Novice Novice 0
7054
+ 22 yes 3.46 Novice Beginner 0
7055
+ 37 no 3.52 Novice Novice 1
7056
+ """
7057
+ # Validate arguments
7058
+ arg_validate = []
7059
+ arg_validate.append(["pattern", pattern, False, (str, ColumnExpression), True])
7060
+ arg_validate.append(["case_sensitive", case_sensitive, True, (bool), True])
7061
+ _Validators._validate_function_arguments(arg_validate)
7062
+
7063
+ if isinstance(pattern, ColumnExpression):
7064
+ pattern = pattern.expression
7065
+
7066
+ # Set the case sensitivity modifier based on the parameter.
7067
+ case_modifier = 'c' if case_sensitive else 'i'
6877
7068
  return _SQLColumnExpression(
6878
- literal_column("{} (CASESPECIFIC) LIKE '{}'".format(self.compile(), other)))
7069
+ func.regexp_similar(self.expression, pattern, case_modifier) == 1,
7070
+ type=INTEGER())
6879
7071
 
6880
7072
  @collect_queryband(queryband="DFC_startswith")
6881
7073
  def startswith(self, other):
@@ -7057,6 +7249,202 @@ class _SQLColumnExpression(_LogicalColumnExpression,
7057
7249
  return _SQLColumnExpression(func.substr(self.expression, start_pos_expr, length_expr),
7058
7250
  type=self.type)
7059
7251
 
7252
+ def count_delimiters(self, delimiter):
7253
+ """
7254
+ DESCRIPTION:
7255
+ Function to count the total number of occurrences of a specified delimiter.
7256
+
7257
+ PARAMETERS:
7258
+ delimiter:
7259
+ Required Argument.
7260
+ Specifies the delimiter to count in the column values.
7261
+ Types: str
7262
+
7263
+ RETURNS:
7264
+ ColumnExpression.
7265
+
7266
+ EXAMPLES:
7267
+ # Load sample data
7268
+ >>> load_example_data("dataframe", "admissions_train")
7269
+ >>> df = DataFrame("admissions_train")
7270
+
7271
+ # Create a DataFrame with a column containing delimiters.
7272
+ >>> df1 = df.assign(delim_col = 'ab.c.def.g')
7273
+ >>> df1
7274
+ masters gpa stats programming admitted delim_col
7275
+ id
7276
+ 38 yes 2.65 Advanced Beginner 1 ab.c.def.g
7277
+ 7 yes 2.33 Novice Novice 1 ab.c.def.g
7278
+ 26 yes 3.57 Advanced Advanced 1 ab.c.def.g
7279
+
7280
+ # Example 1: Count the number of periods in column 'delim_col'.
7281
+ >>> res = df1.assign(dot_count = df1.delim_col.count_delimiters('.'))
7282
+ >>> res
7283
+ masters gpa stats programming admitted delim_col dot_count
7284
+ id
7285
+ 38 yes 2.65 Advanced Beginner 1 ab.c.def.g 3
7286
+ 7 yes 2.33 Novice Novice 1 ab.c.def.g 3
7287
+ 26 yes 3.57 Advanced Advanced 1 ab.c.def.g 3
7288
+
7289
+ # Example 2: Count multiple delimiters in a string.
7290
+ >>> df2 = df.assign(delim_col = 'a,b;c;d-e')
7291
+ >>> res = df2.assign(
7292
+ ... comma_count = df2.delim_col.count_delimiters(','),
7293
+ ... semicolon_count = df2.delim_col.count_delimiters(';'),
7294
+ ... colon_count = df2.delim_col.count_delimiters(':'),
7295
+ ... dash_count = df2.delim_col.count_delimiters('-')
7296
+ ... )
7297
+ >>> res
7298
+ masters gpa stats programming admitted delim_col colon_count comma_count dash_count semicolon_count
7299
+ id
7300
+ 38 yes 2.65 Advanced Beginner 1 a,b;c;d-e 0 1 1 2
7301
+ 7 yes 2.33 Novice Novice 1 a,b;c;d-e 0 1 1 2
7302
+ 26 yes 3.57 Advanced Advanced 1 a,b;c;d-e 0 1 1 2
7303
+ 5 no 3.44 Novice Novice 0 a,b;c;d-e 0 1 1 2
7304
+ """
7305
+
7306
+ # Validate arguments
7307
+ arg_validate = []
7308
+ arg_validate.append(["delimiter", delimiter, False, (str), True])
7309
+ _Validators._validate_function_arguments(arg_validate)
7310
+
7311
+ # Calculate the count by comparing the original string length
7312
+ # with the length after removing all delimiters.
7313
+ expression = (func.characters(self.expression) - func.characters(
7314
+ func.oreplace(self.expression, delimiter, '')))// func.characters(delimiter)
7315
+
7316
+ return _SQLColumnExpression(expression, type=INTEGER())
7317
+
7318
+ @collect_queryband(queryband="DFC_substringIndex")
7319
+ def substring_index(self, delimiter, count):
7320
+ """
7321
+ DESCRIPTION:
7322
+ Function to return the substring from a column before a specified
7323
+ delimiter, up to a given occurrence count.
7324
+
7325
+ PARAMETERS:
7326
+ delimiter:
7327
+ Required Argument.
7328
+ Specifies the delimiter string to split the column values.
7329
+ Types: str
7330
+
7331
+ count:
7332
+ Required Argument.
7333
+ Specifies the number of occurrences of the delimiter to consider.
7334
+ If positive, the substring is extracted from the start of the string.
7335
+ If negative, the substring is extracted from the end of the string.
7336
+ If zero, an empty string is returned.
7337
+ Types: int
7338
+
7339
+ RAISES:
7340
+ TeradataMlException
7341
+
7342
+ RETURNS:
7343
+ ColumnExpression.
7344
+
7345
+ EXAMPLES:
7346
+ # Load the data to run the example.
7347
+ >>> load_example_data("dataframe","admissions_train")
7348
+ >>> df = DataFrame('admissions_train')
7349
+
7350
+ # Create a new column 'delim_col' with string.
7351
+ >>> df1 = df.assign(delim_col = 'ab.c.def.g')
7352
+ >>> df1
7353
+ masters gpa stats programming admitted delim_col
7354
+ id
7355
+ 38 yes 2.65 Advanced Beginner 1 ab.c.def.g
7356
+ 7 yes 2.33 Novice Novice 1 ab.c.def.g
7357
+ 26 yes 3.57 Advanced Advanced 1 ab.c.def.g
7358
+ 5 no 3.44 Novice Novice 0 ab.c.def.g
7359
+ 3 no 3.70 Novice Beginner 1 ab.c.def.g
7360
+ 22 yes 3.46 Novice Beginner 0 ab.c.def.g
7361
+ 1 yes 3.95 Beginner Beginner 0 ab.c.def.g
7362
+ 17 no 3.83 Advanced Advanced 1 ab.c.def.g
7363
+ 15 yes 4.00 Advanced Advanced 1 ab.c.def.g
7364
+ 34 yes 3.85 Advanced Beginner 0 ab.c.def.g
7365
+
7366
+ # Example 1: Create a new column 'new_column' by extracting the substring
7367
+ based on positive count.
7368
+ >>> res = df1.assign(new_column = df1.delim_col.substring_index('.', 2))
7369
+ >>> res
7370
+ masters gpa stats programming admitted delim_col new_column
7371
+ id
7372
+ 34 yes 3.85 Advanced Beginner 0 ab.c.def.g ab.c
7373
+ 32 yes 3.46 Advanced Beginner 0 ab.c.def.g ab.c
7374
+ 11 no 3.13 Advanced Advanced 1 ab.c.def.g ab.c
7375
+ 30 yes 3.79 Advanced Novice 0 ab.c.def.g ab.c
7376
+ 28 no 3.93 Advanced Advanced 1 ab.c.def.g ab.c
7377
+ 16 no 3.70 Advanced Advanced 1 ab.c.def.g ab.c
7378
+ 35 no 3.68 Novice Beginner 1 ab.c.def.g ab.c
7379
+ 40 yes 3.95 Novice Beginner 0 ab.c.def.g ab.c
7380
+ 19 yes 1.98 Advanced Advanced 0 ab.c.def.g ab.c
7381
+
7382
+ # Example 2: Create a new column 'new_column' by extracting the substring
7383
+ based on negative count.
7384
+ >>> res = df1.assign(new_column = df1.delim_col.substring_index('.', -3))
7385
+ >>> res
7386
+ masters gpa stats programming admitted delim_col new_column
7387
+ id
7388
+ 34 yes 3.85 Advanced Beginner 0 ab.c.def.g c.def.g
7389
+ 32 yes 3.46 Advanced Beginner 0 ab.c.def.g c.def.g
7390
+ 11 no 3.13 Advanced Advanced 1 ab.c.def.g c.def.g
7391
+ 30 yes 3.79 Advanced Novice 0 ab.c.def.g c.def.g
7392
+ 28 no 3.93 Advanced Advanced 1 ab.c.def.g c.def.g
7393
+ 16 no 3.70 Advanced Advanced 1 ab.c.def.g c.def.g
7394
+ 35 no 3.68 Novice Beginner 1 ab.c.def.g c.def.g
7395
+ 40 yes 3.95 Novice Beginner 0 ab.c.def.g c.def.g
7396
+ 19 yes 1.98 Advanced Advanced 0 ab.c.def.g c.def.g
7397
+
7398
+ # Example 3: Create a new column 'new_column' by extracting the substring
7399
+ with 2-character delimiter based on positive count.
7400
+ >>> res = df1.assign(new_column = df1.delim_col.substring_index('c.d', 1))
7401
+ >>> res
7402
+ masters gpa stats programming admitted delim_col new_column
7403
+ id
7404
+ 34 yes 3.85 Advanced Beginner 0 ab.c.def.g ab.
7405
+ 32 yes 3.46 Advanced Beginner 0 ab.c.def.g ab.
7406
+ 11 no 3.13 Advanced Advanced 1 ab.c.def.g ab.
7407
+ 30 yes 3.79 Advanced Novice 0 ab.c.def.g ab.
7408
+ 28 no 3.93 Advanced Advanced 1 ab.c.def.g ab.
7409
+ 16 no 3.70 Advanced Advanced 1 ab.c.def.g ab.
7410
+ 35 no 3.68 Novice Beginner 1 ab.c.def.g ab.
7411
+ 40 yes 3.95 Novice Beginner 0 ab.c.def.g ab.
7412
+
7413
+ """
7414
+ # Validate arguments
7415
+ arg_validate = []
7416
+ arg_validate.append(["delimiter", delimiter, False, (str), True])
7417
+ arg_validate.append(["count", count, False, (int), True])
7418
+ _Validators._validate_function_arguments(arg_validate)
7419
+
7420
+ # Create the SQL expression for substring_index.
7421
+ if count == 0:
7422
+ return _SQLColumnExpression(literal(""), type=self.type)
7423
+
7424
+ elif count > 0:
7425
+ # For positive count, return substring before the nth occurrence.
7426
+ position = func.instr(self.expression, delimiter, 1, count)
7427
+ # Handle the case where the delimiter is not found.
7428
+ expression = case_when((position == 0, self.expression),
7429
+ else_=func.substring(self.expression, 1, position - 1))
7430
+ else:
7431
+ # For negative count, we need to find substring after the (total - |count|)th delimiter
7432
+ # First, get the total number of delimiters
7433
+ total_delimiters = self.count_delimiters(delimiter).expression
7434
+
7435
+ # Calculate the position to start from (convert negative count to positive position).
7436
+ position = total_delimiters + count + 1
7437
+
7438
+ # Handle the case where the absolute negative count exceeds the total number of delimiters.
7439
+ expression = case_when((position > 0,
7440
+ # Get substring after the nth occurrence from the beginning.
7441
+ func.substring(self.expression,
7442
+ func.instr(self.expression, delimiter, 1, position) + len(delimiter),
7443
+ func.characters(self.expression))),
7444
+ else_=self.expression)
7445
+
7446
+ return _SQLColumnExpression(expression, type=self.type)
7447
+
7060
7448
  @collect_queryband(queryband="DFC_replace")
7061
7449
  def replace(self, to_replace, value=None):
7062
7450
  """
@@ -8969,566 +9357,11 @@ class _SQLColumnExpression(_LogicalColumnExpression,
8969
9357
  Optional Argument.
8970
9358
  Specifies the format for formatting the values of the column.
8971
9359
  Type: str OR ColumnExpression
8972
- Note:
9360
+ Notes:
8973
9361
  * If 'formatter' is omitted, numeric values is converted to a string exactly
8974
9362
  long enough to hold its significant digits.
9363
+ * Get the supported formatters using `get_formatters("CHAR")` function.
8975
9364
 
8976
- * Formatter for Numeric types:
8977
- +--------------------------------------------------------------------------------------------------+
8978
- | FORMATTER DESCRIPTION |
8979
- +--------------------------------------------------------------------------------------------------+
8980
- | , (comma) A comma in the specified position. |
8981
- | A comma cannot begin a number format. |
8982
- | A comma cannot appear to the right of a decimal |
8983
- | character or period in a number format. |
8984
- | Example: |
8985
- | +-------------------------------------------------+ |
8986
- | | data formatter result | |
8987
- | +-------------------------------------------------+ |
8988
- | | 1234 9,999 1,234 | |
8989
- | +-------------------------------------------------+ |
8990
- +--------------------------------------------------------------------------------------------------+
8991
- | . (period) A decimal point. |
8992
- | User can only specify one period in a number format. |
8993
- | Example: |
8994
- | +-------------------------------------------------+ |
8995
- | | data formatter result | |
8996
- | +-------------------------------------------------+ |
8997
- | | 123.46 9999.9 123.5 | |
8998
- | +-------------------------------------------------+ |
8999
- +--------------------------------------------------------------------------------------------------+
9000
- | $ A value with a leading dollar sign. |
9001
- | Example: |
9002
- | +-------------------------------------------------+ |
9003
- | | data formatter result | |
9004
- | +-------------------------------------------------+ |
9005
- | | 1234 $9999 $1234 | |
9006
- | +-------------------------------------------------+ |
9007
- +--------------------------------------------------------------------------------------------------+
9008
- | 0 Leading zeros. |
9009
- | Trailing zeros. |
9010
- | Example: |
9011
- | +-------------------------------------------------+ |
9012
- | | data formatter result | |
9013
- | +-------------------------------------------------+ |
9014
- | | 1234 09999 01234 | |
9015
- | +-------------------------------------------------+ |
9016
- +--------------------------------------------------------------------------------------------------+
9017
- | 9 A value with the specified number of digits with a |
9018
- | leading space if positive or with a leading minus |
9019
- | if negative. |
9020
- | Example: |
9021
- | +-------------------------------------------------+ |
9022
- | | data formatter result | |
9023
- | +-------------------------------------------------+ |
9024
- | | 1234 9999 1234 | |
9025
- | | 1234 999 #### | |
9026
- | +-------------------------------------------------+ |
9027
- +--------------------------------------------------------------------------------------------------+
9028
- | B Blank space for the integer part of a fixed point number|
9029
- | when the integer part is zero. |
9030
- | Example: |
9031
- | +-------------------------------------------------+ |
9032
- | | data formatter result | |
9033
- | +-------------------------------------------------+ |
9034
- | | 0.1234 B.999 Blank space| |
9035
- | +-------------------------------------------------+ |
9036
- +--------------------------------------------------------------------------------------------------+
9037
- | C The ISO currency symbol as specified in the ISOCurrency |
9038
- | element in the SDF file. |
9039
- | Example: |
9040
- | +-------------------------------------------------+ |
9041
- | | data formatter result | |
9042
- | +-------------------------------------------------+ |
9043
- | | 234 C999 USD234 | |
9044
- | +-------------------------------------------------+ |
9045
- +--------------------------------------------------------------------------------------------------+
9046
- | D The character that separates the integer and fractional |
9047
- | part of non-monetary values. |
9048
- | Example: |
9049
- | +-------------------------------------------------+ |
9050
- | | data formatter result | |
9051
- | +-------------------------------------------------+ |
9052
- | | 234.56 999D9 234.6 | |
9053
- | +-------------------------------------------------+ |
9054
- +--------------------------------------------------------------------------------------------------+
9055
- | EEEE A value in scientific notation. |
9056
- | Example: |
9057
- | +-------------------------------------------------+ |
9058
- | | data formatter result | |
9059
- | +-------------------------------------------------+ |
9060
- | | 234.56 9.9EEEE 2.3E+02 | |
9061
- | +-------------------------------------------------+ |
9062
- +--------------------------------------------------------------------------------------------------+
9063
- | G The character that separates groups of digits in the |
9064
- | integer part of non-monetary values. |
9065
- | +-------------------------------------------------+ |
9066
- | | data formatter result | |
9067
- | +-------------------------------------------------+ |
9068
- | | 123456 9G99G99 1,234,56 | |
9069
- | +-------------------------------------------------+ |
9070
- +--------------------------------------------------------------------------------------------------+
9071
- | L The string representing the local currency as specified |
9072
- | in the Currency element according to system settings. |
9073
- | Example: |
9074
- | +-------------------------------------------------+ |
9075
- | | data formatter result | |
9076
- | +-------------------------------------------------+ |
9077
- | | 234 L999 $234 | |
9078
- | +-------------------------------------------------+ |
9079
- +--------------------------------------------------------------------------------------------------+
9080
- | MI A trailing minus sign if the value is negative. |
9081
- | The MI format element can appear only in the last |
9082
- | position of a number format. |
9083
- | Example: |
9084
- | +-------------------------------------------------+ |
9085
- | | data formatter result | |
9086
- | +-------------------------------------------------+ |
9087
- | | -1234 9999MI 1234- | |
9088
- | +-------------------------------------------------+ |
9089
- +--------------------------------------------------------------------------------------------------+
9090
- | PR A negative value in <angle brackets>, or |
9091
- | a positive value with a leading and trailing blank. |
9092
- | The PR format element can appear only in the last |
9093
- | position of a number format. |
9094
- | Example: |
9095
- | +-------------------------------------------------+ |
9096
- | | data formatter result | |
9097
- | +-------------------------------------------------+ |
9098
- | | -1234 9999PR <1234> | |
9099
- | +-------------------------------------------------+ |
9100
- +--------------------------------------------------------------------------------------------------+
9101
- | S A negative value with a leading or trailing minus sign. |
9102
- | a positive value with a leading or trailing plus sign. |
9103
- | The S format element can appear only in the first or |
9104
- | last position of a number format. |
9105
- | Example: |
9106
- | +-------------------------------------------------+ |
9107
- | | data formatter result | |
9108
- | +-------------------------------------------------+ |
9109
- | | +1234 S9999 +1234 | |
9110
- | +-------------------------------------------------+ |
9111
- +--------------------------------------------------------------------------------------------------+
9112
- | TM (text minimum format) Returns the smallest number of |
9113
- | characters possible. This element is case insensitive. |
9114
- | TM or TM9 return the number in fixed notation unless |
9115
- | the output exceeds 64 characters. If the output exceeds |
9116
- | 64 characters, the number is returned in scientific |
9117
- | notation. |
9118
- | TME returns the number in scientific notation with the |
9119
- | smallest number of characters. |
9120
- | You cannot precede this element with an other element. |
9121
- | You can follow this element only with one 9 or one E |
9122
- | (or e), but not with any combination of these. |
9123
- | Example: |
9124
- | +-------------------------------------------------+ |
9125
- | | data formatter result | |
9126
- | +-------------------------------------------------+ |
9127
- | | 1234 TM 1234 | |
9128
- | +-------------------------------------------------+ |
9129
- +--------------------------------------------------------------------------------------------------+
9130
- | U (dual currency) The string that represents the dual |
9131
- | currency as specified in the DualCurrency element |
9132
- | according to system settings. |
9133
- | Example: |
9134
- | +-------------------------------------------------+ |
9135
- | | data formatter result | |
9136
- | +-------------------------------------------------+ |
9137
- | | 1234 U9999 $1234 | |
9138
- | +-------------------------------------------------+ |
9139
- +--------------------------------------------------------------------------------------------------+
9140
- | V A value multiplied by 10 to the n (and, if necessary, |
9141
- | rounded up), where n is the number of 9's after the V. |
9142
- | Example: |
9143
- | +-------------------------------------------------+ |
9144
- | | data formatter result | |
9145
- | +-------------------------------------------------+ |
9146
- | | 1234 9999V99 123400 | |
9147
- | +-------------------------------------------------+ |
9148
- +--------------------------------------------------------------------------------------------------+
9149
- | X The hexadecimal value of the specified number of digits.|
9150
- | If the specified number is not an integer, the function |
9151
- | will round it to an integer. |
9152
- | This element accepts only positive values or zero. |
9153
- | Negative values return an error. You can precede this |
9154
- | element only with zero (which returns leading zeros) or |
9155
- | FM. Any other elements return an error. If you do not |
9156
- | specify zero or FM, the return always has one leading |
9157
- | blank. |
9158
- | Example: |
9159
- | +-------------------------------------------------+ |
9160
- | | data formatter result | |
9161
- | +-------------------------------------------------+ |
9162
- | | 1234 XXXX 4D2 | |
9163
- | +-------------------------------------------------+ |
9164
- +--------------------------------------------------------------------------------------------------+
9165
-
9166
- * Formatter for Date types:
9167
- +--------------------------------------------------------------------------------------------------+
9168
- | FORMATTER DESCRIPTION |
9169
- +--------------------------------------------------------------------------------------------------+
9170
- | - |
9171
- | / |
9172
- | , Punctuation characters are ignored and text enclosed in |
9173
- | . quotation marks is ignored. |
9174
- | ; |
9175
- | : |
9176
- | "text" |
9177
- | Example: |
9178
- | +-------------------------------------------------+ |
9179
- | | data formatter result | |
9180
- | +-------------------------------------------------+ |
9181
- | | 03/09/17 MM-DD 09-17 | |
9182
- | +-------------------------------------------------+ |
9183
- +--------------------------------------------------------------------------------------------------+
9184
- | AD AD indicator. |
9185
- | A.D. |
9186
- | Example: |
9187
- | +-------------------------------------------------+ |
9188
- | | data formatter result | |
9189
- | +-------------------------------------------------+ |
9190
- | | 03/09/17 CCAD 21AD | |
9191
- | +-------------------------------------------------+ |
9192
- +--------------------------------------------------------------------------------------------------+
9193
- | AM Meridian indicator. |
9194
- | A.M. |
9195
- | Example: |
9196
- | +-------------------------------------------------+ |
9197
- | | data formatter result | |
9198
- | +-------------------------------------------------+ |
9199
- | | 03/09/17 CCAM 21AM | |
9200
- | +-------------------------------------------------+ |
9201
- +--------------------------------------------------------------------------------------------------+
9202
- | BC |
9203
- | B.C. BC indicator. |
9204
- | Example: |
9205
- | +-------------------------------------------------+ |
9206
- | | data formatter result | |
9207
- | +-------------------------------------------------+ |
9208
- | | 03/09/17 CCBC 21BC | |
9209
- | +-------------------------------------------------+ |
9210
- +--------------------------------------------------------------------------------------------------+
9211
- | CC Century. |
9212
- | SCC If the last 2 digits of a 4-digit year are between 01 |
9213
- | and 99 inclusive, the century is 1 greater than the |
9214
- | first 2 digits of that year. |
9215
- | If the last 2 digits of a 4-digit year are 00, the |
9216
- | century is the same as the first 2 digits of that year. |
9217
- | Example: |
9218
- | +-------------------------------------------------+ |
9219
- | | data formatter result | |
9220
- | +-------------------------------------------------+ |
9221
- | | 03/09/17 CCBC 21BC | |
9222
- | +-------------------------------------------------+ |
9223
- +--------------------------------------------------------------------------------------------------+
9224
- | D Day of week (1-7). |
9225
- | Example: |
9226
- | +-------------------------------------------------+ |
9227
- | | data formatter result | |
9228
- | +-------------------------------------------------+ |
9229
- | | 03/09/17 D 4 | |
9230
- | +-------------------------------------------------+ |
9231
- +--------------------------------------------------------------------------------------------------+
9232
- | DAY Name of day. |
9233
- | Example: |
9234
- | +-------------------------------------------------+ |
9235
- | | data formatter result | |
9236
- | +-------------------------------------------------+ |
9237
- | | 03/09/17 DAY WEDNESDAY | |
9238
- | +-------------------------------------------------+ |
9239
- +--------------------------------------------------------------------------------------------------+
9240
- | DD Day of month (1-31). |
9241
- | Example: |
9242
- | +-------------------------------------------------+ |
9243
- | | data formatter result | |
9244
- | +-------------------------------------------------+ |
9245
- | | 03/09/17 DD 17 | |
9246
- | +-------------------------------------------------+ |
9247
- +--------------------------------------------------------------------------------------------------+
9248
- | DDD Day of year (1-366). |
9249
- | Example: |
9250
- | +-------------------------------------------------+ |
9251
- | | data formatter result | |
9252
- | +-------------------------------------------------+ |
9253
- | | 03/09/17 DDD 260 | |
9254
- | +-------------------------------------------------+ |
9255
- +--------------------------------------------------------------------------------------------------+
9256
- | DL Date Long. Equivalent to the format string ‘FMDay, |
9257
- | Month FMDD, YYYY’. |
9258
- | Example: |
9259
- | +-------------------------------------------------+ |
9260
- | | data formatter result | |
9261
- | +-------------------------------------------------+ |
9262
- | | 03/09/17 DL Wednesday, September 17, 2003| |
9263
- | +-------------------------------------------------+ |
9264
- +--------------------------------------------------------------------------------------------------+
9265
- | DS Date Short. Equivalent to the format string |
9266
- | ‘FMMM/DD/YYYYFM’. |
9267
- | Example: |
9268
- | +-------------------------------------------------+ |
9269
- | | data formatter result | |
9270
- | +-------------------------------------------------+ |
9271
- | | 03/09/17 DS 9/17/2003 | |
9272
- | +-------------------------------------------------+ |
9273
- +--------------------------------------------------------------------------------------------------+
9274
- | DY abbreviated name of day. |
9275
- | Example: |
9276
- | +-------------------------------------------------+ |
9277
- | | data formatter result | |
9278
- | +-------------------------------------------------+ |
9279
- | | 03/09/17 DY WED | |
9280
- | +-------------------------------------------------+ |
9281
- +--------------------------------------------------------------------------------------------------+
9282
- | FF [1..9] Fractional seconds. |
9283
- | Use [1..9] to specify the number of fractional digits. |
9284
- | FF without any number following it prints a decimal |
9285
- | followed by digits equal to the number of fractional |
9286
- | seconds in the input data type. If the data type has no |
9287
- | fractional digits, FF prints nothing. |
9288
- | Any fractional digits beyond 6 digits are truncated. |
9289
- | Example: |
9290
- | +-------------------------------------------------+ |
9291
- | | data formatter result | |
9292
- | +-------------------------------------------------+ |
9293
- | | 2016-01-06 09:08:01.000000 FF 000000 | |
9294
- | +-------------------------------------------------+ |
9295
- +--------------------------------------------------------------------------------------------------+
9296
- | HH |
9297
- | HH12 Hour of day (1-12). |
9298
- | Example: |
9299
- | +-------------------------------------------------+ |
9300
- | | data formatter result | |
9301
- | +-------------------------------------------------+ |
9302
- | | 2016-01-06 09:08:01.000000 HH 09 | |
9303
- | +-------------------------------------------------+ |
9304
- +--------------------------------------------------------------------------------------------------+
9305
- | HH24 Hour of the day (0-23). |
9306
- | Example: |
9307
- | +-------------------------------------------------+ |
9308
- | | data formatter result | |
9309
- | +-------------------------------------------------+ |
9310
- | | 2016-01-06 09:08:01.000000 HH24 09 | |
9311
- | +-------------------------------------------------+ |
9312
- +--------------------------------------------------------------------------------------------------+
9313
- | IW Week of year (1-52 or 1-53) based on ISO model. |
9314
- | Example: |
9315
- | +-------------------------------------------------+ |
9316
- | | data formatter result | |
9317
- | +-------------------------------------------------+ |
9318
- | | 2016-01-06 09:08:01.000000 IW 01 | |
9319
- | +-------------------------------------------------+ |
9320
- +--------------------------------------------------------------------------------------------------+
9321
- | IYY |
9322
- | IY Last 3, 2, or 1 digits of ISO year. |
9323
- | I |
9324
- | Example: |
9325
- | +-------------------------------------------------+ |
9326
- | | data formatter result | |
9327
- | +-------------------------------------------------+ |
9328
- | | 2016-01-06 09:08:01.000000 IY 16 | |
9329
- | +-------------------------------------------------+ |
9330
- +--------------------------------------------------------------------------------------------------+
9331
- | IYYY 4-digit year based on the ISO standard. |
9332
- | Example: |
9333
- | +-------------------------------------------------+ |
9334
- | | data formatter result | |
9335
- | +-------------------------------------------------+ |
9336
- | | 2016-01-06 09:08:01.000000 IYYY 2016 | |
9337
- | +-------------------------------------------------+ |
9338
- +--------------------------------------------------------------------------------------------------+
9339
- | J Julian day, the number of days since January 1, 4713 BC. |
9340
- | Number specified with J must be integers. |
9341
- | Teradata uses the Gregorian calendar in calculations to |
9342
- | and from Julian Days. |
9343
- | Example: |
9344
- | +-------------------------------------------------+ |
9345
- | | data formatter result | |
9346
- | +-------------------------------------------------+ |
9347
- | | 2016-01-06 09:08:01.000000 J 2457394 | |
9348
- | +-------------------------------------------------+ |
9349
- +--------------------------------------------------------------------------------------------------+
9350
- | MI Minute (0-59). |
9351
- | Example: |
9352
- | +-------------------------------------------------+ |
9353
- | | data formatter result | |
9354
- | +-------------------------------------------------+ |
9355
- | | 2016-01-06 09:08:01.000000 MI 08 | |
9356
- | +-------------------------------------------------+ |
9357
- +--------------------------------------------------------------------------------------------------+
9358
- | MM Month (01-12). |
9359
- | Example: |
9360
- | +-------------------------------------------------+ |
9361
- | | data formatter result | |
9362
- | +-------------------------------------------------+ |
9363
- | | 2016-01-06 09:08:01.000000 MM 01 | |
9364
- | +-------------------------------------------------+ |
9365
- +--------------------------------------------------------------------------------------------------+
9366
- | MON Abbreviated name of month. |
9367
- | Example: |
9368
- | +-------------------------------------------------+ |
9369
- | | data formatter result | |
9370
- | +-------------------------------------------------+ |
9371
- | | 2016-01-06 09:08:01.000000 MON JAN | |
9372
- | +-------------------------------------------------+ |
9373
- +--------------------------------------------------------------------------------------------------+
9374
- | MONTH Name of month. |
9375
- | Example: |
9376
- | +-------------------------------------------------+ |
9377
- | | data formatter result | |
9378
- | +-------------------------------------------------+ |
9379
- | | 2016-01-06 09:08:01.000000 MONTH JANUARY | |
9380
- | +-------------------------------------------------+ |
9381
- +--------------------------------------------------------------------------------------------------+
9382
- | PM |
9383
- | P.M. Meridian indicator. |
9384
- | Example: |
9385
- | +-------------------------------------------------+ |
9386
- | | data formatter result | |
9387
- | +-------------------------------------------------+ |
9388
- | | 2016-01-06 09:08:01.000000 HHPM 09PM | |
9389
- | +-------------------------------------------------+ |
9390
- +--------------------------------------------------------------------------------------------------+
9391
- | Q Quarter of year (1, 2, 3, 4). |
9392
- | Example: |
9393
- | +-------------------------------------------------+ |
9394
- | | data formatter result | |
9395
- | +-------------------------------------------------+ |
9396
- | | 2016-01-06 09:08:01.000000 Q 1 | |
9397
- | +-------------------------------------------------+ |
9398
- +--------------------------------------------------------------------------------------------------+
9399
- | RM Roman numeral month (I - XII). |
9400
- | Example: |
9401
- | +-------------------------------------------------+ |
9402
- | | data formatter result | |
9403
- | +-------------------------------------------------+ |
9404
- | | 2016-01-06 09:08:01.000000 RM I | |
9405
- | +-------------------------------------------------+ |
9406
- +--------------------------------------------------------------------------------------------------+
9407
- | SP Spelled. Any numeric element followed by SP is spelled in|
9408
- | English words. The words are capitalized according to how|
9409
- | the element is capitalized. |
9410
- | For example: 'DDDSP' specifies all uppercase, 'DddSP' |
9411
- | specifies that the first letter is capitalized, and |
9412
- | 'dddSP' specifies all lowercase. |
9413
- | Example: |
9414
- | +-------------------------------------------------+ |
9415
- | | data formatter result | |
9416
- | +-------------------------------------------------+ |
9417
- | | 2016-01-06 09:08:01.000000 HHSP NINE | |
9418
- | +-------------------------------------------------+ |
9419
- +--------------------------------------------------------------------------------------------------+
9420
- | SS Second (0-59). |
9421
- | Example: |
9422
- | +-------------------------------------------------+ |
9423
- | | data formatter result | |
9424
- | +-------------------------------------------------+ |
9425
- | | 2016-01-06 09:08:01.000000 SS 03 | |
9426
- | +-------------------------------------------------+ |
9427
- +--------------------------------------------------------------------------------------------------+
9428
- | SSSSS Seconds past midnight (0-86399). |
9429
- | Example: |
9430
- | +-------------------------------------------------+ |
9431
- | | data formatter result | |
9432
- | +-------------------------------------------------+ |
9433
- | | 2016-01-06 09:08:01.000000 SSSSS 32883 | |
9434
- | +-------------------------------------------------+ |
9435
- +--------------------------------------------------------------------------------------------------+
9436
- | TS Time Short. Equivalent to the format string |
9437
- | 'HH:MI:SS AM'. |
9438
- | Example: |
9439
- | +-------------------------------------------------+ |
9440
- | | data formatter result | |
9441
- | +-------------------------------------------------+ |
9442
- | | 2016-01-06 09:08:01.000000 TS 09:08:01 AM | |
9443
- | +-------------------------------------------------+ |
9444
- +--------------------------------------------------------------------------------------------------+
9445
- | TZH Time zone hour. |
9446
- | Example: |
9447
- | +-------------------------------------------------+ |
9448
- | | data formatter result | |
9449
- | +-------------------------------------------------+ |
9450
- | | 2016-01-06 09:08:01.000000 TZH +00 | |
9451
- | +-------------------------------------------------+ |
9452
- +--------------------------------------------------------------------------------------------------+
9453
- | TZM Time zone minute. |
9454
- | Example: |
9455
- | +-------------------------------------------------+ |
9456
- | | data formatter result | |
9457
- | +-------------------------------------------------+ |
9458
- | | 2016-01-06 09:08:01.000000 TZM 00 | |
9459
- | +-------------------------------------------------+ |
9460
- +--------------------------------------------------------------------------------------------------+
9461
- | TZR Time zone region. Equivalent to the format string |
9462
- | 'TZH:TZM'. |
9463
- | Example: |
9464
- | +-------------------------------------------------+ |
9465
- | | data formatter result | |
9466
- | +-------------------------------------------------+ |
9467
- | | 2016-01-06 09:08:01.000000 TZR +00:00 | |
9468
- | +-------------------------------------------------+ |
9469
- +--------------------------------------------------------------------------------------------------+
9470
- | WW Week of year (1-53) where week 1 starts on the first day |
9471
- | of the year and continues to the 7th day of the year. |
9472
- | Example: |
9473
- | +-------------------------------------------------+ |
9474
- | | data formatter result | |
9475
- | +-------------------------------------------------+ |
9476
- | | 2016-01-06 09:08:01.000000 WW 01 | |
9477
- | +-------------------------------------------------+ |
9478
- +--------------------------------------------------------------------------------------------------+
9479
- | W Week of month (1-5) where week 1 starts on the first day |
9480
- | of the month and ends on the seventh. |
9481
- | Example: |
9482
- | +-------------------------------------------------+ |
9483
- | | data formatter result | |
9484
- | +-------------------------------------------------+ |
9485
- | | 2016-01-06 09:08:01.000000 W 1 | |
9486
- | +-------------------------------------------------+ |
9487
- +--------------------------------------------------------------------------------------------------+
9488
- | X Local radix character. |
9489
- | Example: |
9490
- | +-------------------------------------------------+ |
9491
- | | data formatter result | |
9492
- | +-------------------------------------------------+ |
9493
- | | 2016-01-06 09:08:01.000000 MMXYY 01.16 | |
9494
- | +-------------------------------------------------+ |
9495
- +--------------------------------------------------------------------------------------------------+
9496
- | Y,YYY Year with comma in this position. |
9497
- | Example: |
9498
- | +-------------------------------------------------+ |
9499
- | | data formatter result | |
9500
- | +-------------------------------------------------+ |
9501
- | | 2016-01-06 09:08:01.000000 Y,YYY 2,016 | |
9502
- | +-------------------------------------------------+ |
9503
- +--------------------------------------------------------------------------------------------------+
9504
- | YEAR Year, spelled out. S prefixes BC dates with a minus sign.|
9505
- | SYEAR |
9506
- | Example: |
9507
- | +-------------------------------------------------+ |
9508
- | | data formatter result | |
9509
- | +-------------------------------------------------+ |
9510
- | | 2016-01-06 09:08:01.000000 YEAR TWENTY SIXTEEN| |
9511
- | +-------------------------------------------------+ |
9512
- +--------------------------------------------------------------------------------------------------+
9513
- | YYYY |
9514
- | SYYYY 4-digit year. S prefixes BC dates with a minus sign. |
9515
- | Example: |
9516
- | +-------------------------------------------------+ |
9517
- | | data formatter result | |
9518
- | +-------------------------------------------------+ |
9519
- | | 2016-01-06 09:08:01.000000 YYYY 2016 | |
9520
- | +-------------------------------------------------+ |
9521
- +--------------------------------------------------------------------------------------------------+
9522
- | YYY Last 3, 2, or 1 digit of year. |
9523
- | YY If the current year and the specified year are both in |
9524
- | Y the range of 0-49, the date is in the current century. |
9525
- | Example: |
9526
- | +-------------------------------------------------+ |
9527
- | | data formatter result | |
9528
- | +-------------------------------------------------+ |
9529
- | | 2016-01-06 09:08:01.000000 YY 16 | |
9530
- | +-------------------------------------------------+ |
9531
- +--------------------------------------------------------------------------------------------------+
9532
9365
 
9533
9366
  RAISES:
9534
9367
  TypeError, ValueError, TeradataMlException
@@ -9654,156 +9487,11 @@ class _SQLColumnExpression(_LogicalColumnExpression,
9654
9487
  Specifies a variable length string containing formatting characters
9655
9488
  that define the format of the columns.
9656
9489
  Type: str OR ColumnExpression
9657
- Note:
9490
+ Notes:
9658
9491
  * If 'formatter' is omitted, numeric values is converted to a string exactly
9659
9492
  long enough to hold its significant digits.
9660
-
9661
- * Formatters:
9662
- +--------------------------------------------------------------------------------------------------+
9663
- | FORMATTER DESCRIPTION |
9664
- +--------------------------------------------------------------------------------------------------+
9665
- | , (comma) A comma in the specified position. |
9666
- | A comma cannot begin a number format. |
9667
- | A comma cannot appear to the right of a decimal |
9668
- | character or period in a number format. |
9669
- | Example: |
9670
- | +-------------------------------------------------+ |
9671
- | | data formatter result | |
9672
- | +-------------------------------------------------+ |
9673
- | | "1,234" "9,999" 1234 | |
9674
- | +-------------------------------------------------+ |
9675
- +--------------------------------------------------------------------------------------------------+
9676
- | . (period) A decimal point. Only one allowed in a format. |
9677
- | Example: |
9678
- | +-------------------------------------------------+ |
9679
- | | data formatter result | |
9680
- | +-------------------------------------------------+ |
9681
- | | "12.34" "99.99" 12.34 | |
9682
- | +-------------------------------------------------+ |
9683
- +--------------------------------------------------------------------------------------------------+
9684
- | $ A value with a leading dollar sign. |
9685
- | Example: |
9686
- | +-------------------------------------------------+ |
9687
- | | data formatter result | |
9688
- | +-------------------------------------------------+ |
9689
- | | "$1234" "$9999" 1234 | |
9690
- | +-------------------------------------------------+ |
9691
- +--------------------------------------------------------------------------------------------------+
9692
- | 0 Leading or trailing zeros. |
9693
- | Example: |
9694
- | +-------------------------------------------------+ |
9695
- | | data formatter result | |
9696
- | +-------------------------------------------------+ |
9697
- | | "0123" "0999" 123 | |
9698
- | | "1230" "9990" 1230 | |
9699
- | +-------------------------------------------------+ |
9700
- +--------------------------------------------------------------------------------------------------+
9701
- | 9 Specified number of digits. |
9702
- | Leading space if positive, minus if negative. |
9703
- | Example: |
9704
- | +-------------------------------------------------+ |
9705
- | | data formatter result | |
9706
- | +-------------------------------------------------+ |
9707
- | | "1234" "9999" 1234 | |
9708
- | | "-1234" "9999" -1234 | |
9709
- | +-------------------------------------------------+ |
9710
- +--------------------------------------------------------------------------------------------------+
9711
- | B Blanks if integer part is zero. |
9712
- | Example: |
9713
- | +-------------------------------------------------+ |
9714
- | | data formatter result | |
9715
- | +-------------------------------------------------+ |
9716
- | | "0" "B9999" 0 | |
9717
- | +-------------------------------------------------+ |
9718
- +--------------------------------------------------------------------------------------------------+
9719
- | C ISO currency symbol (from SDF ISOCurrency). |
9720
- | Example: |
9721
- | +-------------------------------------------------+ |
9722
- | | data formatter result | |
9723
- | +-------------------------------------------------+ |
9724
- | | "USD123" "C999" 123 | |
9725
- | +-------------------------------------------------+ |
9726
- +--------------------------------------------------------------------------------------------------+
9727
- | D Radix separator for non-monetary values. |
9728
- | From SDF RadixSeparator. |
9729
- | Example: |
9730
- | +-------------------------------------------------+ |
9731
- | | data formatter result | |
9732
- | +-------------------------------------------------+ |
9733
- | | "12.34" "99D99" 12.34 | |
9734
- | +-------------------------------------------------+ |
9735
- +--------------------------------------------------------------------------------------------------+
9736
- | EEEE Scientific notation. |
9737
- | Example: |
9738
- | +-------------------------------------------------+ |
9739
- | | data formatter result | |
9740
- | +-------------------------------------------------+ |
9741
- | | "1.2E+04" "9.9EEEE" 12000 | |
9742
- | +-------------------------------------------------+ |
9743
- +--------------------------------------------------------------------------------------------------+
9744
- | G Group separator for non-monetary values. |
9745
- | From SDF GroupSeparator. |
9746
- | Example: |
9747
- | +-------------------------------------------------+ |
9748
- | | data formatter result | |
9749
- | +-------------------------------------------------+ |
9750
- | | "1,234,567" "9G999G999" 1234567 | |
9751
- | +-------------------------------------------------+ |
9752
- +--------------------------------------------------------------------------------------------------+
9753
- | L Local currency (from SDF Currency element). |
9754
- | Example: |
9755
- | +-------------------------------------------------+ |
9756
- | | data formatter result | |
9757
- | +-------------------------------------------------+ |
9758
- | | "$123" "L999" 123 | |
9759
- | +-------------------------------------------------+ |
9760
- +--------------------------------------------------------------------------------------------------+
9761
- | MI Trailing minus sign if value is negative. |
9762
- | Can only appear in the last position. |
9763
- | Example: |
9764
- | +-------------------------------------------------+ |
9765
- | | data formatter result | |
9766
- | +-------------------------------------------------+ |
9767
- | | "1234-" "9999MI" -1234 | |
9768
- | +-------------------------------------------------+ |
9769
- +--------------------------------------------------------------------------------------------------+
9770
- | PR Negative value in angle brackets. |
9771
- | Positive value with leading/trailing blank. |
9772
- | Only in the last position. |
9773
- | Example: |
9774
- | +-------------------------------------------------+ |
9775
- | | data formatter result | |
9776
- | +-------------------------------------------------+ |
9777
- | | " 123 " "9999PR" 123 | |
9778
- | +-------------------------------------------------+ |
9779
- +--------------------------------------------------------------------------------------------------+
9780
- | S Sign indicator: + / - at beginning or end. |
9781
- | Can only appear in first or last position. |
9782
- | Example: |
9783
- | +-------------------------------------------------+ |
9784
- | | data formatter result | |
9785
- | +-------------------------------------------------+ |
9786
- | | "-1234" "S9999" -1234 | |
9787
- | +-------------------------------------------------+ |
9788
- +--------------------------------------------------------------------------------------------------+
9789
- | U Dual currency (from SDF DualCurrency). |
9790
- | Example: |
9791
- | +-------------------------------------------------+ |
9792
- | | data formatter result | |
9793
- | +-------------------------------------------------+ |
9794
- | | "$123" "U999" 123 | |
9795
- | +-------------------------------------------------+ |
9796
- +--------------------------------------------------------------------------------------------------+
9797
- | X Hexadecimal format. |
9798
- | Accepts only non-negative values. |
9799
- | Must be preceded by 0 or FM. |
9800
- | Example: |
9801
- | +-------------------------------------------------+ |
9802
- | | data formatter result | |
9803
- | +-------------------------------------------------+ |
9804
- | | "FF" "XX" 255 | |
9805
- | +-------------------------------------------------+ |
9806
- +--------------------------------------------------------------------------------------------------+
9493
+ * Get the supported formatters using `get_formatters("NUMERIC")` function.
9494
+
9807
9495
  RAISES:
9808
9496
  TypeError, ValueError, TeradataMlException
9809
9497
 
@@ -9877,213 +9565,10 @@ class _SQLColumnExpression(_LogicalColumnExpression,
9877
9565
  Specifies a variable length string containing formatting characters
9878
9566
  that define the format of column.
9879
9567
  Type: str
9880
- Note:
9568
+ Notes:
9881
9569
  * If "formatter" is omitted, the following default date format is used: 'YYYY-MM-DD'
9882
- * formatter for date type:
9883
- +--------------------------------------------------------------------------------------------------+
9884
- | FORMATTER DESCRIPTION |
9885
- +--------------------------------------------------------------------------------------------------+
9886
- | - |
9887
- | / |
9888
- | , Punctuation characters are ignored and text enclosed in |
9889
- | . quotation marks is ignored. |
9890
- | ; |
9891
- | : |
9892
- | "text" |
9893
- | Example: Date with value '2003-12-10' |
9894
- | +-------------------------------------------------+ |
9895
- | | data formatter value | |
9896
- | +-------------------------------------------------+ |
9897
- | | '2003-12-10' YYYY-MM-DD 03/12/10 | |
9898
- | +-------------------------------------------------+ |
9899
- +--------------------------------------------------------------------------------------------------+
9900
- | D Day of week (1-7). |
9901
- | Example: day of week with value '2' |
9902
- | +-------------------------------------------------+ |
9903
- | | data formatter value | |
9904
- | +-------------------------------------------------+ |
9905
- | | 2 D 24/01/01 | |
9906
- | +-------------------------------------------------+ |
9907
- +--------------------------------------------------------------------------------------------------+
9908
- | DAY Name of day. |
9909
- | Example: Date with value '2024-TUESDAY-01-30' |
9910
- | +-------------------------------------------------+ |
9911
- | | data formatter value | |
9912
- | +-------------------------------------------------+ |
9913
- | | 2024-TUESDAY-01-30 YYYY-DAY-MM-DD 24/01/30 | |
9914
- | +-------------------------------------------------+ |
9915
- +--------------------------------------------------------------------------------------------------+
9916
- | DD Day of month (1-31). |
9917
- | Example: Date with value '2003-10-25' |
9918
- | +-------------------------------------------------+ |
9919
- | | data formatter value | |
9920
- | +-------------------------------------------------+ |
9921
- | | 2003-10-25 YYYY-MM-DD 03/10/25 | |
9922
- | +-------------------------------------------------+ |
9923
- +--------------------------------------------------------------------------------------------------+
9924
- | DDD Day of year (1-366). |
9925
- | Example: Date with value '2024-366' |
9926
- | +-------------------------------------------------+ |
9927
- | | data formatter value | |
9928
- | +-------------------------------------------------+ |
9929
- | | 2024-366 YYYY-DDD 24/12/31 | |
9930
- | +-------------------------------------------------+ |
9931
- +--------------------------------------------------------------------------------------------------+
9932
- | DY abbreviated name of day. |
9933
- | Example: Date with value '2024-Mon-01-29' |
9934
- | +-------------------------------------------------+ |
9935
- | | data formatter value | |
9936
- | +-------------------------------------------------+ |
9937
- | | 2024-Mon-01-29 YYYY-DY-MM-DD 24/01/29 | |
9938
- | +-------------------------------------------------+ |
9939
- +--------------------------------------------------------------------------------------------------+
9940
- | HH |
9941
- | HH12 Hour of day (1-12). |
9942
- | Example: Date with value '2016-01-06 09:08:01' |
9943
- | +-------------------------------------------------+ |
9944
- | | data formatter value | |
9945
- | +-------------------------------------------------+ |
9946
- | | 2016-01-06 09:08:01 YYYY-MM-DD HH:MI:SS 6/01/06| |
9947
- | +-------------------------------------------------+ |
9948
- +--------------------------------------------------------------------------------------------------+
9949
- | HH24 Hour of the day (0-23). |
9950
- | Example: Date with value '2016-01-06 23:08:01' |
9951
- | +----------------------------------------------------+ |
9952
- | | data formatter value | |
9953
- | +----------------------------------------------------+ |
9954
- | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9955
- | +----------------------------------------------------+ |
9956
- +--------------------------------------------------------------------------------------------------+
9957
- | J Julian day, the number of days since January 1, 4713 BC. |
9958
- | Number specified with J must be integers. |
9959
- | Teradata uses the Gregorian calendar in calculations to |
9960
- | and from Julian Days. |
9961
- | Example: Number of julian days with value '2457394' |
9962
- | +-------------------------------------------------+ |
9963
- | | data formatter value | |
9964
- | +-------------------------------------------------+ |
9965
- | | 2457394 J 16/01/06 | |
9966
- | +-------------------------------------------------+ |
9967
- +--------------------------------------------------------------------------------------------------+
9968
- | MI Minute (0-59). |
9969
- | Example: Date with value '2016-01-06 23:08:01' |
9970
- | +----------------------------------------------------+ |
9971
- | | data formatter value | |
9972
- | +----------------------------------------------------+ |
9973
- | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9974
- | +----------------------------------------------------+ |
9975
- +--------------------------------------------------------------------------------------------------+
9976
- | MM Month (01-12). |
9977
- | Example: Date with value '2016-01-06 23:08:01' |
9978
- | +----------------------------------------------------+ |
9979
- | | data formatter value | |
9980
- | +----------------------------------------------------+ |
9981
- | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
9982
- | +----------------------------------------------------+ |
9983
- +--------------------------------------------------------------------------------------------------+
9984
- | MON Abbreviated name of month. |
9985
- | Example: Date with value '2016-JAN-06' |
9986
- | +----------------------------------------------------+ |
9987
- | | data formatter value | |
9988
- | +----------------------------------------------------+ |
9989
- | | 2016-JAN-06 YYYY-MON-DD 16/01/06 | |
9990
- | +----------------------------------------------------+ |
9991
- +--------------------------------------------------------------------------------------------------+
9992
- | MONTH Name of month. |
9993
- | Example: Date with value '2016-JANUARY-06' |
9994
- | +-------------------------------------------------+ |
9995
- | | data formatter value | |
9996
- | +-------------------------------------------------+ |
9997
- | | 2016-JANUARY-06 YYYY-MONTH-DD 16/01/06 | |
9998
- | +-------------------------------------------------+ |
9999
- +--------------------------------------------------------------------------------------------------+
10000
- | PM |
10001
- | P.M. Meridian indicator. |
10002
- | Example: Date with value '2016-01-06 23:08:01 PM' |
10003
- | +---------------------------------------------------------+ |
10004
- | | data formatter value | |
10005
- | +---------------------------------------------------------+ |
10006
- | | 2016-01-06 23:08:01 PM YYYY-MM-DD HH24:MI:SS PM 16/01/06| |
10007
- | +---------------------------------------------------------+ |
10008
- +--------------------------------------------------------------------------------------------------+
10009
- | RM Roman numeral month (I - XII). |
10010
- | Example: Date with value '2024-XII' |
10011
- | +-------------------------------------------------+ |
10012
- | | data formatter value | |
10013
- | +-------------------------------------------------+ |
10014
- | | 2024-XII YYYY-RM 24/12/01 | |
10015
- | +-------------------------------------------------+ |
10016
- +--------------------------------------------------------------------------------------------------+
10017
- | RR Stores 20th century dates in the 21st century using only |
10018
- | 2 digits. If the current year and the specified year are |
10019
- | both in the range of 0-49, the date is in the current |
10020
- | century. |
10021
- | Example: Date with value '2024-365, 21' |
10022
- | +-------------------------------------------------+ |
10023
- | | data formatter value | |
10024
- | +-------------------------------------------------+ |
10025
- | | 2024-365, 21 YYYY-DDD, RR 21/12/31 | |
10026
- | +-------------------------------------------------+ |
10027
- +--------------------------------------------------------------------------------------------------+
10028
- | RRRR Round year. Accepts either 4-digit or 2-digit input. |
10029
- | 2-digit input provides the same return as RR. |
10030
- | Example: Date with value '2024-365, 21' |
10031
- | +-------------------------------------------------+ |
10032
- | | data formatter value | |
10033
- | +-------------------------------------------------+ |
10034
- | | 2024-365, 21 YYYY-DDD, RRRR 24/12/31 | |
10035
- | +-------------------------------------------------+ |
10036
- +--------------------------------------------------------------------------------------------------+
10037
- | SS Second (0-59). |
10038
- | Example: Date with value '2016-01-06 23:08:01' |
10039
- | +----------------------------------------------------+ |
10040
- | | data formatter value | |
10041
- | +----------------------------------------------------+ |
10042
- | | 2016-01-06 23:08:01 YYYY-MM-DD HH24:MI:SS 6/01/06 | |
10043
- | +----------------------------------------------------+ |
10044
- +--------------------------------------------------------------------------------------------------+
10045
- | SSSSS Seconds past midnight (0-86399). |
10046
- +--------------------------------------------------------------------------------------------------+
10047
- | TZH Time zone hour. |
10048
- +--------------------------------------------------------------------------------------------------+
10049
- | TZM Time zone minute. |
10050
- +--------------------------------------------------------------------------------------------------+
10051
- | X Local radix character. |
10052
- | Example: Date with value '2024.366' |
10053
- | +-------------------------------------------------+ |
10054
- | | data formatter value | |
10055
- | +-------------------------------------------------+ |
10056
- | | 2024.366 YYYYXDDD 24/12/31 | |
10057
- | +-------------------------------------------------+ |
10058
- +--------------------------------------------------------------------------------------------------+
10059
- | Y,YYY Year with comma in this position. |
10060
- | Example: Date with value '2,024-366' |
10061
- | +-------------------------------------------------+ |
10062
- | | data formatter value | |
10063
- | +-------------------------------------------------+ |
10064
- | | 2,024-366 Y,YYY-DDD 24/12/31 | |
10065
- | +-------------------------------------------------+ |
10066
- +--------------------------------------------------------------------------------------------------+
10067
- | YYYY |
10068
- | SYYYY 4-digit year. S prefixes BC dates with a minus sign. |
10069
- | Example: Date with value '2024-366' |
10070
- | +-------------------------------------------------+ |
10071
- | | data formatter value | |
10072
- | +-------------------------------------------------+ |
10073
- | | 2024-366 YYYY-DDD 24/12/31 | |
10074
- | +-------------------------------------------------+ |
10075
- +--------------------------------------------------------------------------------------------------+
10076
- | YYY Last 3, 2, or 1 digit of year. |
10077
- | YY If the current year and the specified year are both in |
10078
- | Y the range of 0-49, the date is in the current century. |
10079
- | Example: Date with value '24-366' |
10080
- | +-------------------------------------------------+ |
10081
- | | data formatter value | |
10082
- | +-------------------------------------------------+ |
10083
- | | 24-366 YY-DDD 24/12/31 | |
10084
- | +-------------------------------------------------+ |
10085
- +--------------------------------------------------------------------------------------------------+
10086
-
9570
+ * Get the supported formatters using `get_formatters("DATE")` function.
9571
+
10087
9572
  RAISES:
10088
9573
  TypeError, ValueError, TeradataMlException
10089
9574
 
@@ -10159,7 +9644,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
10159
9644
  if formatter:
10160
9645
  _args.append(formatter)
10161
9646
  return _SQLColumnExpression(func.to_date(*_args), type=DATE())
10162
-
9647
+
10163
9648
  def trunc(self, expression=0, formatter=None):
10164
9649
  """
10165
9650
  DESCRIPTION:
@@ -10908,7 +10393,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
10908
10393
  value = value.expression if isinstance(value, _SQLColumnExpression) else value
10909
10394
  return _SQLColumnExpression(_fun(self.expression, value), type=type_)
10910
10395
 
10911
- def parse_url(self, url_part):
10396
+ def parse_url(self, url_part, key=None):
10912
10397
  """
10913
10398
  DESCRIPTION:
10914
10399
  Extracts a specific part from the URL.
@@ -10920,6 +10405,13 @@ class _SQLColumnExpression(_LogicalColumnExpression,
10920
10405
  Permitted Values: HOST, PATH, QUERY, REF, PROTOCOL, FILE, AUTHORITY, USERINFO
10921
10406
  Type: str or ColumnExpression
10922
10407
 
10408
+ key:
10409
+ Optional Argument.
10410
+ Specifies the key to be used for extracting the value from the query string.
10411
+ Note:
10412
+ * Applicable only when url_part is set to 'QUERY'.
10413
+ Type: str or ColumnExpression
10414
+
10923
10415
  Returns:
10924
10416
  ColumnExpression
10925
10417
 
@@ -10930,59 +10422,112 @@ class _SQLColumnExpression(_LogicalColumnExpression,
10930
10422
  # Create a DataFrame on 'url_data' table.
10931
10423
  >>> df = DataFrame("url_data")
10932
10424
  >>> df
10933
- urls part
10934
- id
10935
- 3 https://www.facebook.com HOST
10936
- 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO
10937
- 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY
10938
- 2 https://example.net/path4/path5/path6?query4=value4#fragment REF
10939
- 0 http://example.com:8080/path FILE
10940
- 1 ftp://example.net:21/path PATH
10941
- 5 http://pg.example.ml/path150#fragment90 AUTHORITY
10942
- 7 https://www.google.com PROTOCOL
10943
-
10944
- # Example 1: Extract components from column 'urls' using column 'part'
10425
+ urls part query_key
10426
+ id
10427
+ 3 https://www.facebook.com HOST facebook.com
10428
+ 8 http://example.com/api?query1=value1&query2=value2 QUERY query1
10429
+ 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO password
10430
+ 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY None
10431
+ 0 http://example.com:8080/path FILE path
10432
+ 2 https://example.net/path4/path5/path6?query4=value4#fragment REF fragment3
10433
+ 1 ftp://example.net:21/path PATH path
10434
+ 5 http://pg.example.ml/path150#fragment90 AUTHORITY fragment90
10435
+ 7 https://www.google.com PROTOCOL google.com
10436
+
10437
+ # Example 1: Extract components from column 'urls' using column 'part'.
10945
10438
  >>> df.assign(col = df.urls.parse_url(df.part))
10946
- urls part col
10947
- id
10948
- 3 https://www.facebook.com HOST www.facebook.com
10949
- 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO user:password
10950
- 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY None
10951
- 2 https://example.net/path4/path5/path6?query4=value4#fragment REF fragment
10952
- 0 http://example.com:8080/path FILE /path
10953
- 1 ftp://example.net:21/path PATH /path
10954
- 5 http://pg.example.ml/path150#fragment90 AUTHORITY pg.example.ml
10955
- 7 https://www.google.com PROTOCOL https
10956
- >>>
10439
+ urls part query_key col
10440
+ id
10441
+ 3 https://www.facebook.com HOST facebook.com www.facebook.com
10442
+ 8 http://example.com/api?query1=value1&query2=value2 QUERY query1 query1=value1&query2=value2
10443
+ 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO password user:password
10444
+ 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY None None
10445
+ 0 http://example.com:8080/path FILE path /path
10446
+ 2 https://example.net/path4/path5/path6?query4=value4#fragment REF fragment3 fragment
10447
+ 1 ftp://example.net:21/path PATH path /path
10448
+ 5 http://pg.example.ml/path150#fragment90 AUTHORITY fragment90 pg.example.ml
10449
+ 7 https://www.google.com PROTOCOL google.com https
10450
+
10451
+ # Example 2: Extract components from column 'urls' using 'part' and
10452
+ # 'query_key' column.
10453
+ >>> df.assign(col = df.urls.parse_url(df.part, df.query_key))
10454
+ urls part query_key col
10455
+ id
10456
+ 3 https://www.facebook.com HOST facebook.com None
10457
+ 8 http://example.com/api?query1=value1&query2=value2 QUERY query1 value1
10458
+ 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO password None
10459
+ 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY None None
10460
+ 0 http://example.com:8080/path FILE path None
10461
+ 2 https://example.net/path4/path5/path6?query4=value4#fragment REF fragment3 None
10462
+ 1 ftp://example.net:21/path PATH path None
10463
+ 5 http://pg.example.ml/path150#fragment90 AUTHORITY fragment90 None
10464
+ 7 https://www.google.com PROTOCOL google.com None
10465
+
10466
+ # Extract components from column 'urls' using 'part' and 'query_key' str.
10467
+ >>> df.assign(col = df.urls.parse_url('QUERY', 'query2'))
10468
+ urls part query_key col
10469
+ id
10470
+ 3 https://www.facebook.com HOST facebook.com None
10471
+ 8 http://example.com/api?query1=value1&query2=value2 QUERY query1 value2
10472
+ 6 smtp://user:password@smtp.example.com:21/file.txt USERINFO password None
10473
+ 4 https://teracloud-pod-services-pod-account-service.dummyvalu QUERY None None
10474
+ 0 http://example.com:8080/path FILE path None
10475
+ 2 https://example.net/path4/path5/path6?query4=value4#fragment REF fragment3 None
10476
+ 1 ftp://example.net:21/path PATH path None
10477
+ 5 http://pg.example.ml/path150#fragment90 AUTHORITY fragment90 None
10478
+ 7 https://www.google.com PROTOCOL google.com None
10957
10479
  """
10958
10480
 
10959
10481
  # Validating Arguments
10960
10482
  arg_type_matrix = []
10961
10483
  arg_type_matrix.append(["url_part", url_part, False, (str, ColumnExpression), True])
10484
+ arg_type_matrix.append(["key", key, True, (str, ColumnExpression), True])
10962
10485
  _Validators._validate_function_arguments(arg_type_matrix)
10963
10486
 
10487
+ # If key is provided and url_part is QUERY, then use regex to extract the value.
10488
+ if key is not None:
10489
+ query_expr = _SQLColumnExpression(func.regexp_substr(func.regexp_substr(self.expression,
10490
+ '[?&]' + (key.expression if isinstance(key, _SQLColumnExpression) else key) + '=([^&]*)'), '[^=]*$'), type=VARCHAR())
10491
+ # If url_part is a column expression, then use case statement to extract the value.
10492
+ if isinstance(url_part, _SQLColumnExpression):
10493
+ whens = [(url_part == 'HOST', None),
10494
+ (url_part == 'PATH', None ),
10495
+ (url_part == 'QUERY', query_expr),
10496
+ (url_part == 'REF', None),
10497
+ (url_part == 'PROTOCOL', None),
10498
+ (url_part == 'FILE',None),
10499
+ (url_part == 'AUTHORITY', None),
10500
+ (url_part == 'USERINFO', None)]
10501
+
10502
+ from teradataml.dataframe.sql_functions import case
10503
+ return case(whens)
10504
+
10505
+ # If url_part is a string, then return the query expression directly.
10506
+ if isinstance(url_part, str) and url_part == 'QUERY':
10507
+ return query_expr
10508
+
10964
10509
  # Regex pattern used to extract 'url_part' is '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?'.
10965
10510
  # teradataml does not support regex grouping hence in some cases first used 'regex_replace' and
10966
10511
  # then 'regex_substr' or vice-versa.
10967
10512
  _part_to_extract_dict = {'HOST': _SQLColumnExpression(
10968
- func.regexp_replace(func.regexp_substr(self.expression, '//([^/?#]*)'), '(//[^/?#]+@)|(//)|(:\d+)', ''),
10969
- type=VARCHAR()),
10513
+ func.regexp_replace(func.regexp_substr(self.expression, '//([^/?#]*)'), r'(//[^/?#]+@)|(//)|(:\d+)', ''),
10514
+ type=VARCHAR()),
10970
10515
  'PATH': _SQLColumnExpression(func.regexp_substr(
10971
10516
  func.regexp_replace(self.expression, '^(([^:/?#]+):)?(//([^/?#]*))?', ''),
10972
10517
  '([^?#]*)'), type=VARCHAR()),
10973
10518
  'QUERY': _SQLColumnExpression(func.ltrim(func.regexp_substr(
10974
10519
  func.regexp_replace(self.expression, '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)', ''),
10975
- '\?([^#]*)'), '?'), type=VARCHAR()),
10520
+ r'\?([^#]*)'), '?'), type=VARCHAR()),
10976
10521
  'REF': _SQLColumnExpression(func.ltrim(func.regexp_substr(
10977
10522
  func.regexp_replace(self.expression,
10978
- '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?', ''),
10523
+ r'^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?', ''),
10979
10524
  '(#(.*))'), '#'), type=VARCHAR()),
10980
10525
  'PROTOCOL': _SQLColumnExpression(
10981
10526
  func.rtrim(func.regexp_substr(self.expression, '^(([^:/?#]+):)'), ':'),
10982
10527
  type=VARCHAR()),
10983
10528
  'FILE': _SQLColumnExpression(func.regexp_substr(
10984
10529
  func.regexp_replace(self.expression, '^(([^:/?#]+):)?(//([^/?#]*))?', ''),
10985
- '([^?#]*)(\?([^#]*))?'), type=VARCHAR()),
10530
+ r'([^?#]*)(\?([^#]*))?'), type=VARCHAR()),
10986
10531
  'AUTHORITY': _SQLColumnExpression(
10987
10532
  func.ltrim(func.regexp_substr(self.expression, '//([^/?#]*)'), '//'),
10988
10533
  type=VARCHAR()),
@@ -11231,3 +10776,129 @@ class _SQLColumnExpression(_LogicalColumnExpression,
11231
10776
 
11232
10777
  """
11233
10778
  return _SQLColumnExpression(literal_column(f"TD_ISFINITE({self.compile()})"), type=INTEGER)
10779
+
10780
+ def between(self, lower, upper):
10781
+ """
10782
+ DESCRIPTION:
10783
+ Evaluates whether the column value is between the lower and upper bounds.
10784
+ The lower and upper bounds are inclusive.
10785
+
10786
+ PARAMETERS:
10787
+ lower:
10788
+ Required Argument.
10789
+ Specifies the lower bound value.
10790
+ Type: ColumnExpression or str or int or float
10791
+
10792
+ upper:
10793
+ Required Argument.
10794
+ Specifies the upper bound value.
10795
+ Type: ColumnExpression or str or int or float
10796
+
10797
+ RETURNS:
10798
+ ColumnExpression
10799
+
10800
+ EXAMPLES:
10801
+ # Load the data to run the example.
10802
+ >>> load_example_data("dataframe", "sales")
10803
+ >>> df = DataFrame("sales")
10804
+ >>> print(df)
10805
+ Feb Jan Mar Apr datetime
10806
+ accounts
10807
+ Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
10808
+ Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
10809
+ Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
10810
+ Yellow Inc 90.0 NaN NaN NaN 04/01/2017
10811
+ Red Inc 200.0 150.0 140.0 NaN 04/01/2017
10812
+ Orange Inc 210.0 NaN NaN 250.0 04/01/2017
10813
+
10814
+ # Example 1: Check if column 'Feb' is between 100 and 200.
10815
+ >>> new_df = df[df.Feb.between(100, 200)]
10816
+ >>> print(new_df)
10817
+ Feb Jan Mar Apr datetime
10818
+ accounts
10819
+ Jones LLC 200.0 150 140 180.0 04/01/2017
10820
+ Red Inc 200.0 150 140 NaN 04/01/2017
10821
+
10822
+ # Example 2: Check if column 'datetime' is between '01-01-2017' and '30-01-2017'.
10823
+ >>> new_df = df[df.datetime.between('01-01-2017', '30-01-2017')]
10824
+ >>> print(new_df)
10825
+ Feb Jan Mar Apr datetime
10826
+ accounts
10827
+ Jones LLC 200.0 150.0 140.0 180.0 04/01/2017
10828
+ Blue Inc 90.0 50.0 95.0 101.0 04/01/2017
10829
+ Yellow Inc 90.0 NaN NaN NaN 04/01/2017
10830
+ Red Inc 200.0 150.0 140.0 NaN 04/01/2017
10831
+ Alpha Co 210.0 200.0 215.0 250.0 04/01/2017
10832
+ Orange Inc 210.0 NaN NaN 250.0 04/01/2017
10833
+ """
10834
+ return _SQLColumnExpression(self.expression.between(lower, upper))
10835
+
10836
+ def begin(self):
10837
+ """
10838
+ DESCRIPTION:
10839
+ Retrieves the beginning date or timestamp from a PERIOD column.
10840
+
10841
+ PARAMETERS:
10842
+ None.
10843
+
10844
+ RETURNS:
10845
+ ColumnExpression.
10846
+
10847
+ RAISES:
10848
+ TeradataMlException.
10849
+
10850
+ EXAMPLES:
10851
+ # Load the data to run the example.
10852
+ >>> load_example_data("teradataml", "Employee_roles")
10853
+
10854
+ # Create a DataFrame on 'employee_roles' table.
10855
+ >>> df = DataFrame("employee_roles")
10856
+
10857
+ # Extract the starting date from the period column 'role_validity_period'
10858
+ # and assign it to a new column.
10859
+ >>> df = df.assign(start_date_col = df['role_validity_period'].begin())
10860
+ EmployeeID EmployeeName Department Salary role_validity_period start_date_col
10861
+ 1 John Doe IT 100.000 ('20/01/01', '24/12/31') 20/01/01
10862
+ 2 Jane Smith DA 200.000 ('20/01/01', '99/12/31') 20/01/01
10863
+ 3 Bob Marketing 330.000 ('25/01/01', '99/12/31') 25/01/01
10864
+ 3 Bob Sales 300.000 ('24/01/01', '24/12/31') 24/01/01
10865
+
10866
+ """
10867
+ _Validators._validate_period_column_type(self._type)
10868
+ element_type = DATE if isinstance(self._type, PERIOD_DATE) else TIMESTAMP
10869
+ return _SQLColumnExpression(literal_column(f"BEGIN({self.compile()})"), type = element_type)
10870
+
10871
+ def end(self):
10872
+ """
10873
+ DESCRIPTION:
10874
+ Retrieves the ending date or timestamp from a PERIOD column.
10875
+
10876
+ PARAMETERS:
10877
+ None.
10878
+
10879
+ RETURNS:
10880
+ ColumnExpression.
10881
+
10882
+ RAISES:
10883
+ TeradataMlException.
10884
+
10885
+ EXAMPLES:
10886
+ # Load the data to run the example.
10887
+ >>> load_example_data("teradataml", "Employee_roles")
10888
+
10889
+ # Create a DataFrame on 'employee_roles' table.
10890
+ >>> df = DataFrame("employee_roles")
10891
+
10892
+ # Extract the ending date from the period column 'role_validity_period'
10893
+ # and assign it to a new column.
10894
+ >>> df = df.assign(end_date_col = df['role_validity_period'].end())
10895
+ EmployeeID EmployeeName Department Salary role_validity_period end_date_col
10896
+ 1 John Doe IT 100.000 ('20/01/01', '24/12/31') 24/12/31
10897
+ 2 Jane Smith DA 200.000 ('20/01/01', '99/12/31') 99/12/31
10898
+ 3 Bob Marketing 330.000 ('25/01/01', '99/12/31') 99/12/31
10899
+ 3 Bob Sales 300.000 ('24/01/01', '24/12/31') 24/12/31
10900
+
10901
+ """
10902
+ _Validators._validate_period_column_type(self._type)
10903
+ element_type = DATE if isinstance(self._type, PERIOD_DATE) else TIMESTAMP
10904
+ return _SQLColumnExpression(literal_column(f"END({self.compile()})"), type = element_type)