teradataml 20.0.0.3__py3-none-any.whl → 20.0.0.5__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.
- teradataml/LICENSE-3RD-PARTY.pdf +0 -0
- teradataml/README.md +193 -1
- teradataml/__init__.py +2 -1
- teradataml/_version.py +2 -2
- teradataml/analytics/analytic_function_executor.py +25 -18
- teradataml/analytics/byom/__init__.py +1 -1
- teradataml/analytics/json_parser/analytic_functions_argument.py +4 -0
- teradataml/analytics/sqle/__init__.py +20 -2
- teradataml/analytics/utils.py +15 -1
- teradataml/analytics/valib.py +18 -4
- teradataml/automl/__init__.py +341 -112
- teradataml/automl/autodataprep/__init__.py +471 -0
- teradataml/automl/data_preparation.py +84 -42
- teradataml/automl/data_transformation.py +69 -33
- teradataml/automl/feature_engineering.py +76 -9
- teradataml/automl/feature_exploration.py +639 -25
- teradataml/automl/model_training.py +35 -14
- teradataml/clients/auth_client.py +2 -2
- teradataml/common/__init__.py +1 -2
- teradataml/common/constants.py +122 -63
- teradataml/common/messagecodes.py +14 -3
- teradataml/common/messages.py +8 -4
- teradataml/common/sqlbundle.py +40 -10
- teradataml/common/utils.py +366 -74
- teradataml/common/warnings.py +11 -0
- teradataml/context/context.py +348 -86
- teradataml/data/amazon_reviews_25.csv +26 -0
- teradataml/data/apriori_example.json +22 -0
- teradataml/data/byom_example.json +11 -0
- teradataml/data/docs/byom/docs/DataRobotPredict.py +2 -2
- teradataml/data/docs/byom/docs/DataikuPredict.py +40 -1
- teradataml/data/docs/byom/docs/H2OPredict.py +2 -2
- teradataml/data/docs/byom/docs/ONNXEmbeddings.py +242 -0
- teradataml/data/docs/byom/docs/ONNXPredict.py +2 -2
- teradataml/data/docs/byom/docs/PMMLPredict.py +2 -2
- teradataml/data/docs/sqle/docs_17_20/Apriori.py +138 -0
- teradataml/data/docs/sqle/docs_17_20/NERExtractor.py +121 -0
- teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +3 -3
- teradataml/data/docs/sqle/docs_17_20/SMOTE.py +212 -0
- teradataml/data/docs/sqle/docs_17_20/Shap.py +28 -6
- teradataml/data/docs/sqle/docs_17_20/TextMorph.py +119 -0
- teradataml/data/docs/sqle/docs_17_20/TextParser.py +54 -3
- teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/DFFT.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFT2.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/DWT2D.py +4 -1
- teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +4 -4
- teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +6 -6
- teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +4 -4
- teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/PACF.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
- teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/Resample.py +5 -5
- teradataml/data/docs/uaf/docs_17_20/SAX.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +1 -1
- teradataml/data/docs/uaf/docs_17_20/Smoothma.py +3 -3
- teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +1 -1
- teradataml/data/hnsw_alter_data.csv +5 -0
- teradataml/data/hnsw_data.csv +10 -0
- teradataml/data/jsons/byom/h2opredict.json +1 -1
- teradataml/data/jsons/byom/onnxembeddings.json +266 -0
- teradataml/data/jsons/sqle/17.20/NGramSplitter.json +6 -6
- teradataml/data/jsons/sqle/17.20/TD_Apriori.json +181 -0
- teradataml/data/jsons/sqle/17.20/TD_NERExtractor.json +145 -0
- teradataml/data/jsons/sqle/17.20/TD_SMOTE.json +267 -0
- teradataml/data/jsons/sqle/17.20/TD_Shap.json +0 -1
- teradataml/data/jsons/sqle/17.20/TD_TextMorph.json +134 -0
- teradataml/data/jsons/sqle/17.20/TD_TextParser.json +114 -9
- teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +420 -0
- teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +343 -0
- teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +328 -0
- teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +359 -0
- teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +360 -0
- teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +343 -0
- teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +343 -0
- teradataml/data/jsons/sqle/20.00/TD_HNSW.json +296 -0
- teradataml/data/jsons/sqle/20.00/TD_HNSWPredict.json +206 -0
- teradataml/data/jsons/sqle/20.00/TD_HNSWSummary.json +32 -0
- teradataml/data/jsons/sqle/20.00/TD_KMeans.json +2 -2
- teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +3 -3
- teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +6 -6
- teradataml/data/ner_dict.csv +8 -0
- teradataml/data/ner_input_eng.csv +7 -0
- teradataml/data/ner_rule.csv +5 -0
- teradataml/data/pos_input.csv +40 -0
- teradataml/data/tdnerextractor_example.json +14 -0
- teradataml/data/teradataml_example.json +21 -0
- teradataml/data/textmorph_example.json +5 -0
- teradataml/data/to_num_data.csv +4 -0
- teradataml/data/tochar_data.csv +5 -0
- teradataml/data/trans_dense.csv +16 -0
- teradataml/data/trans_sparse.csv +55 -0
- teradataml/data/vectordistance_example.json +1 -1
- teradataml/dataframe/copy_to.py +45 -29
- teradataml/dataframe/data_transfer.py +72 -46
- teradataml/dataframe/dataframe.py +642 -166
- teradataml/dataframe/dataframe_utils.py +167 -22
- teradataml/dataframe/functions.py +135 -20
- teradataml/dataframe/setop.py +11 -6
- teradataml/dataframe/sql.py +330 -78
- teradataml/dbutils/dbutils.py +556 -140
- teradataml/dbutils/filemgr.py +14 -10
- teradataml/hyperparameter_tuner/optimizer.py +12 -1
- teradataml/lib/aed_0_1.dll +0 -0
- teradataml/opensource/{sklearn/_sklearn_wrapper.py → _base.py} +168 -1013
- teradataml/opensource/_class.py +141 -17
- teradataml/opensource/{constants.py → _constants.py} +7 -3
- teradataml/opensource/_lightgbm.py +52 -53
- teradataml/opensource/_sklearn.py +1008 -0
- teradataml/opensource/_wrapper_utils.py +5 -5
- teradataml/options/__init__.py +47 -15
- teradataml/options/configure.py +103 -26
- teradataml/options/display.py +13 -2
- teradataml/plot/axis.py +47 -8
- teradataml/plot/figure.py +33 -0
- teradataml/plot/plot.py +63 -13
- teradataml/scriptmgmt/UserEnv.py +307 -40
- teradataml/scriptmgmt/lls_utils.py +428 -145
- teradataml/store/__init__.py +2 -3
- teradataml/store/feature_store/feature_store.py +102 -7
- teradataml/table_operators/Apply.py +48 -19
- teradataml/table_operators/Script.py +23 -2
- teradataml/table_operators/TableOperator.py +3 -1
- teradataml/table_operators/table_operator_util.py +58 -9
- teradataml/utils/dtypes.py +49 -1
- teradataml/utils/internal_buffer.py +38 -0
- teradataml/utils/validators.py +377 -62
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/METADATA +200 -4
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/RECORD +146 -112
- teradataml/data/SQL_Fundamentals.pdf +0 -0
- teradataml/libaed_0_1.dylib +0 -0
- teradataml/libaed_0_1.so +0 -0
- teradataml/opensource/sklearn/__init__.py +0 -0
- teradataml/store/vector_store/__init__.py +0 -1586
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/WHEEL +0 -0
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/top_level.txt +0 -0
- {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/zip-safe +0 -0
teradataml/dataframe/sql.py
CHANGED
|
@@ -265,7 +265,7 @@ class _PandasTableExpression(TableExpression):
|
|
|
265
265
|
|
|
266
266
|
existing = [(c.name, c) for c in self.c]
|
|
267
267
|
new = [(label, expression) for label, expression in kw.items() if label not in current]
|
|
268
|
-
new = sorted(new, key
|
|
268
|
+
new = sorted(new, key=lambda x: x[0])
|
|
269
269
|
|
|
270
270
|
for alias, expression in existing + new:
|
|
271
271
|
if drop_columns and alias not in kw:
|
|
@@ -5480,6 +5480,7 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
5480
5480
|
self._quotechar = kw.get("quotechar", None)
|
|
5481
5481
|
self._udf_script = kw.get("udf_script", None)
|
|
5482
5482
|
self.alias_name = self.compile() if (self._udf or self._udf_script) is None else None
|
|
5483
|
+
self._debug = kw.get("debug", False)
|
|
5483
5484
|
|
|
5484
5485
|
@property
|
|
5485
5486
|
def expression(self):
|
|
@@ -7002,12 +7003,12 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
7002
7003
|
Specifies starting position to extract string from column.
|
|
7003
7004
|
Note:
|
|
7004
7005
|
Index position starts with 1 instead of 0.
|
|
7005
|
-
Types: int
|
|
7006
|
+
Types: int OR ColumnExpression
|
|
7006
7007
|
|
|
7007
7008
|
length:
|
|
7008
7009
|
Required Argument.
|
|
7009
7010
|
Specifies the length of the string to extract from column.
|
|
7010
|
-
Types: int
|
|
7011
|
+
Types: int OR ColumnExpression
|
|
7011
7012
|
|
|
7012
7013
|
RETURNS:
|
|
7013
7014
|
ColumnExpression.
|
|
@@ -7040,8 +7041,20 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
7040
7041
|
emp_name mgr_id mgr_name new_col
|
|
7041
7042
|
emp_id
|
|
7042
7043
|
500 Fred 400 Kim on
|
|
7044
|
+
|
|
7045
|
+
# Example 3: Create a new column by passing ColumnExpression as
|
|
7046
|
+
# start_pos and length.
|
|
7047
|
+
>>> df.assign(new_column = df.emp_name.substr(df.emp_id, df.mgr_id))
|
|
7048
|
+
emp_name mgr_id mgr_name new_column
|
|
7049
|
+
emp_id
|
|
7050
|
+
1 Pat 2 Don Pa
|
|
7051
|
+
|
|
7043
7052
|
"""
|
|
7044
|
-
|
|
7053
|
+
# Handle cases where start_pos or length are ColumnExpressions.
|
|
7054
|
+
start_pos_expr = start_pos.expression if isinstance(start_pos, _SQLColumnExpression) else start_pos
|
|
7055
|
+
length_expr = length.expression if isinstance(length, _SQLColumnExpression) else length
|
|
7056
|
+
|
|
7057
|
+
return _SQLColumnExpression(func.substr(self.expression, start_pos_expr, length_expr),
|
|
7045
7058
|
type=self.type)
|
|
7046
7059
|
|
|
7047
7060
|
@collect_queryband(queryband="DFC_replace")
|
|
@@ -8954,8 +8967,8 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
8954
8967
|
PARAMETERS:
|
|
8955
8968
|
formatter:
|
|
8956
8969
|
Optional Argument.
|
|
8957
|
-
Specifies the
|
|
8958
|
-
Type: str
|
|
8970
|
+
Specifies the format for formatting the values of the column.
|
|
8971
|
+
Type: str OR ColumnExpression
|
|
8959
8972
|
Note:
|
|
8960
8973
|
* If 'formatter' is omitted, numeric values is converted to a string exactly
|
|
8961
8974
|
long enough to hold its significant digits.
|
|
@@ -9525,94 +9538,333 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
9525
9538
|
|
|
9526
9539
|
EXAMPLES:
|
|
9527
9540
|
# Load the data to run the example.
|
|
9528
|
-
>>> load_example_data("
|
|
9541
|
+
>>> load_example_data("teradataml", "tochar_data")
|
|
9529
9542
|
|
|
9530
|
-
# Create a DataFrame on '
|
|
9531
|
-
>>> df = DataFrame("
|
|
9543
|
+
# Create a DataFrame on 'tochar_data' table.
|
|
9544
|
+
>>> df = DataFrame("tochar_data")
|
|
9532
9545
|
>>> df
|
|
9533
|
-
|
|
9534
|
-
|
|
9535
|
-
|
|
9536
|
-
|
|
9537
|
-
|
|
9538
|
-
|
|
9539
|
-
|
|
9540
|
-
556 10 19/03/06 61.524
|
|
9541
|
-
556 8 19/02/20 61.886
|
|
9542
|
-
556 4 19/01/23 63.900
|
|
9543
|
-
556 2 19/01/09 61.617
|
|
9544
|
-
556 1 19/01/02 60.900
|
|
9546
|
+
int_col float_col date_col int_format float_format date_format
|
|
9547
|
+
id
|
|
9548
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY
|
|
9549
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD
|
|
9550
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY
|
|
9551
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD
|
|
9552
|
+
|
|
9545
9553
|
>>> df.tdtypes
|
|
9546
|
-
|
|
9547
|
-
|
|
9548
|
-
|
|
9549
|
-
|
|
9550
|
-
|
|
9551
|
-
|
|
9552
|
-
|
|
9553
|
-
|
|
9554
|
+
COLUMN NAME TYPE
|
|
9555
|
+
id INTEGER()
|
|
9556
|
+
int_col INTEGER()
|
|
9557
|
+
float_col FLOAT()
|
|
9558
|
+
date_col DATE()
|
|
9559
|
+
int_format VARCHAR(length=20, charset='LATIN')
|
|
9560
|
+
float_format VARCHAR(length=20, charset='LATIN')
|
|
9561
|
+
date_format VARCHAR(length=20, charset='LATIN')
|
|
9562
|
+
|
|
9563
|
+
# Example 1: Convert 'int_col' column to character type.
|
|
9564
|
+
>>> res = df.assign(int_col = df.int_col.to_char())
|
|
9554
9565
|
>>> res
|
|
9555
|
-
|
|
9556
|
-
|
|
9557
|
-
|
|
9558
|
-
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
556 10 19/03/06 61.524
|
|
9563
|
-
556 8 19/02/20 61.886
|
|
9564
|
-
556 4 19/01/23 63.900
|
|
9565
|
-
556 2 19/01/09 61.617
|
|
9566
|
-
556 1 19/01/02 60.900
|
|
9566
|
+
int_col float_col date_col int_format float_format date_format
|
|
9567
|
+
id
|
|
9568
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD
|
|
9569
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY
|
|
9570
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY
|
|
9571
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD
|
|
9572
|
+
|
|
9567
9573
|
>>> res.tdtypes
|
|
9568
|
-
|
|
9569
|
-
|
|
9570
|
-
|
|
9571
|
-
|
|
9572
|
-
|
|
9573
|
-
|
|
9574
|
-
|
|
9575
|
-
|
|
9574
|
+
COLUMN NAME TYPE
|
|
9575
|
+
id INTEGER()
|
|
9576
|
+
int_col VARCHAR()
|
|
9577
|
+
float_col FLOAT()
|
|
9578
|
+
date_col DATE()
|
|
9579
|
+
int_format VARCHAR(length=20, charset='LATIN')
|
|
9580
|
+
float_format VARCHAR(length=20, charset='LATIN')
|
|
9581
|
+
date_format VARCHAR(length=20, charset='LATIN')
|
|
9582
|
+
|
|
9583
|
+
# Example 2: Convert 'float_col' column to character type in '$999.9' format.
|
|
9584
|
+
>>> res = df.assign(char_col = df.float_col.to_char('$999.9'))
|
|
9576
9585
|
>>> res
|
|
9577
|
-
|
|
9578
|
-
|
|
9579
|
-
|
|
9580
|
-
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9585
|
-
|
|
9586
|
-
556 4 19/01/23 63.900 $63.9
|
|
9587
|
-
556 2 19/01/09 61.617 $61.6
|
|
9588
|
-
556 1 19/01/02 60.900 $60.9
|
|
9589
|
-
|
|
9590
|
-
# Example 3: Convert "timevalue" column to character type in 'YYYY-DAY-MONTH' format
|
|
9591
|
-
>>> res = df.assign(timevalue = df.timevalue.to_char('YYYY-DAY-MONTH'))
|
|
9586
|
+
int_col float_col date_col int_format float_format date_format char_col
|
|
9587
|
+
id
|
|
9588
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD $234.6
|
|
9589
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY $123.5
|
|
9590
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY $123.5
|
|
9591
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD $234.6
|
|
9592
|
+
|
|
9593
|
+
# Example 3: Convert 'date_col' column to character type in 'YYYY-DAY-MONTH' format
|
|
9594
|
+
>>> res = df.assign(char_col = df.date_col.to_char('YYYY-DAY-MONTH'))
|
|
9592
9595
|
>>> res
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9596
|
+
int_col float_col date_col int_format float_format date_format char_col
|
|
9597
|
+
id
|
|
9598
|
+
3 1314 123.4600 03/09/17 XXXX TM9 DY 1903-THURSDAY -SEPTEMBER
|
|
9599
|
+
0 1234 234.5600 03/09/17 9,999 999D9 MM-DD 1903-THURSDAY -SEPTEMBER
|
|
9600
|
+
2 789 123.4600 03/09/17 0999 9999.9 DAY 1903-THURSDAY -SEPTEMBER
|
|
9601
|
+
1 456 234.5600 03/09/17 $999 9.9EEEE CCAD 1903-THURSDAY -SEPTEMBER
|
|
9602
|
+
|
|
9603
|
+
# Example 4: Convert 'int_col' column to character type in 'int_format' column format.
|
|
9604
|
+
>>> res = df.assign(char_col = df.int_col.to_char(df.int_format))
|
|
9605
|
+
>>> res
|
|
9606
|
+
int_col float_col date_col int_format float_format date_format char_col
|
|
9607
|
+
id
|
|
9608
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD 1,234
|
|
9609
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY 522
|
|
9610
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY 0789
|
|
9611
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD $456
|
|
9612
|
+
|
|
9613
|
+
# Example 5: Convert 'float_col' column to character type in 'float_format' column format.
|
|
9614
|
+
>>> res = df.assign(char_col = df.float_col.to_char(df.float_format))
|
|
9615
|
+
>>> res
|
|
9616
|
+
int_col float_col date_col int_format float_format date_format char_col
|
|
9617
|
+
id
|
|
9618
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY 123.5
|
|
9619
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY 123.46
|
|
9620
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD 2.3E+02
|
|
9621
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD 234.6
|
|
9622
|
+
|
|
9623
|
+
# Example 4: Convert 'date_col' column to character type in 'date_format' column format.
|
|
9624
|
+
>>> res = df.assign(char_col = df.date_col.to_char(df.date_format))
|
|
9625
|
+
>>> res
|
|
9626
|
+
int_col float_col date_col int_format float_format date_format char_col
|
|
9627
|
+
id
|
|
9628
|
+
0 1234 234.56 03/09/17 9,999 999D9 MM-DD 09-17
|
|
9629
|
+
3 1314 123.46 03/09/17 XXXX TM9 DY THU
|
|
9630
|
+
2 789 123.46 03/09/17 0999 9999.9 DAY THURSDAY
|
|
9631
|
+
1 456 234.56 03/09/17 $999 9.9EEEE CCAD 20AD
|
|
9632
|
+
|
|
9605
9633
|
"""
|
|
9606
9634
|
arg_validate = []
|
|
9607
|
-
arg_validate.append(["formatter", formatter, True, (str), True])
|
|
9635
|
+
arg_validate.append(["formatter", formatter, True, (str, ColumnExpression), True])
|
|
9608
9636
|
|
|
9609
9637
|
# Validate argument types
|
|
9610
9638
|
_Validators._validate_function_arguments(arg_validate)
|
|
9611
9639
|
|
|
9612
9640
|
_args=[self.expression]
|
|
9613
9641
|
if formatter:
|
|
9642
|
+
formatter = formatter.expression if isinstance(formatter, ColumnExpression) else formatter
|
|
9614
9643
|
_args.append(formatter)
|
|
9615
9644
|
return _SQLColumnExpression(func.to_char(*_args), type=VARCHAR())
|
|
9645
|
+
|
|
9646
|
+
def to_number(self, formatter=None):
|
|
9647
|
+
"""
|
|
9648
|
+
DESCRIPTION:
|
|
9649
|
+
Converts a string-like representation of a number to NUMBER type.
|
|
9650
|
+
|
|
9651
|
+
PARAMETERS:
|
|
9652
|
+
formatter:
|
|
9653
|
+
Optional Argument.
|
|
9654
|
+
Specifies a variable length string containing formatting characters
|
|
9655
|
+
that define the format of the columns.
|
|
9656
|
+
Type: str OR ColumnExpression
|
|
9657
|
+
Note:
|
|
9658
|
+
* If 'formatter' is omitted, numeric values is converted to a string exactly
|
|
9659
|
+
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
|
+
+--------------------------------------------------------------------------------------------------+
|
|
9807
|
+
RAISES:
|
|
9808
|
+
TypeError, ValueError, TeradataMlException
|
|
9809
|
+
|
|
9810
|
+
RETURNS:
|
|
9811
|
+
ColumnExpression
|
|
9812
|
+
|
|
9813
|
+
EXAMPLES:
|
|
9814
|
+
# Load the data to run the example.
|
|
9815
|
+
>>> load_example_data("teradataml", "to_num_data")
|
|
9816
|
+
|
|
9817
|
+
# Create a DataFrame on 'to_num_data' table.
|
|
9818
|
+
>>> df = DataFrame("to_num_data")
|
|
9819
|
+
>>> df
|
|
9820
|
+
price col_format
|
|
9821
|
+
$1234 $9999
|
|
9822
|
+
USD123 C999
|
|
9823
|
+
78.12 99.99
|
|
9824
|
+
|
|
9825
|
+
# Example 1: Convert 'price' column to number type without passing any formatter.
|
|
9826
|
+
>>> res = df.assign(new_col=df.price.to_number())
|
|
9827
|
+
>>> res
|
|
9828
|
+
price col_format new_col
|
|
9829
|
+
$1234 $9999 NaN
|
|
9830
|
+
USD123 C999 NaN
|
|
9831
|
+
78.12 99.99 78.12
|
|
9832
|
+
|
|
9833
|
+
# Example 2: Convert 'price' column to number type by passing formatter as string.
|
|
9834
|
+
>>> res = df.assign(new_col=df.price.to_number('99.99'))
|
|
9835
|
+
>>> res
|
|
9836
|
+
price col_format new_col
|
|
9837
|
+
$1234 $9999 NaN
|
|
9838
|
+
USD123 C999 NaN
|
|
9839
|
+
78.12 99.99 78.12
|
|
9840
|
+
|
|
9841
|
+
# Example 3: Convert 'price' column to number type by passing formatter as ColumnExpression.
|
|
9842
|
+
>>> res = df.assign(new_col=df.price.to_number(df.col_format))
|
|
9843
|
+
>>> res
|
|
9844
|
+
price col_format new_col
|
|
9845
|
+
$1234 $9999 1234
|
|
9846
|
+
USD123 C999 123
|
|
9847
|
+
78.12 99.99 78.12
|
|
9848
|
+
|
|
9849
|
+
>>> df.tdtypes
|
|
9850
|
+
price VARCHAR(length=20, charset='LATIN')
|
|
9851
|
+
col_format VARCHAR(length=20, charset='LATIN')
|
|
9852
|
+
new_col NUMBER()
|
|
9853
|
+
|
|
9854
|
+
"""
|
|
9855
|
+
|
|
9856
|
+
arg_validate = []
|
|
9857
|
+
arg_validate.append(["formatter", formatter, True, (str, ColumnExpression), True])
|
|
9858
|
+
|
|
9859
|
+
# Validate argument types
|
|
9860
|
+
_Validators._validate_function_arguments(arg_validate)
|
|
9861
|
+
|
|
9862
|
+
_args = [self.expression]
|
|
9863
|
+
if formatter is not None:
|
|
9864
|
+
formatter = formatter.expression if isinstance(formatter, ColumnExpression) else formatter
|
|
9865
|
+
_args.append(formatter)
|
|
9866
|
+
|
|
9867
|
+
return _SQLColumnExpression(func.to_number(*_args), type=NUMBER())
|
|
9616
9868
|
|
|
9617
9869
|
def to_date(self, formatter=None):
|
|
9618
9870
|
"""
|
|
@@ -10978,4 +11230,4 @@ class _SQLColumnExpression(_LogicalColumnExpression,
|
|
|
10978
11230
|
>>>
|
|
10979
11231
|
|
|
10980
11232
|
"""
|
|
10981
|
-
return _SQLColumnExpression(literal_column(f"TD_ISFINITE({self.compile()})"), type=INTEGER)
|
|
11233
|
+
return _SQLColumnExpression(literal_column(f"TD_ISFINITE({self.compile()})"), type=INTEGER)
|