teradataml 20.0.0.0__py3-none-any.whl → 20.0.0.1__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 (108) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/LICENSE.pdf +0 -0
  3. teradataml/README.md +71 -0
  4. teradataml/_version.py +2 -2
  5. teradataml/analytics/analytic_function_executor.py +51 -24
  6. teradataml/analytics/json_parser/utils.py +11 -17
  7. teradataml/automl/__init__.py +103 -48
  8. teradataml/automl/data_preparation.py +55 -37
  9. teradataml/automl/data_transformation.py +131 -69
  10. teradataml/automl/feature_engineering.py +117 -185
  11. teradataml/automl/feature_exploration.py +9 -2
  12. teradataml/automl/model_evaluation.py +13 -25
  13. teradataml/automl/model_training.py +214 -75
  14. teradataml/catalog/model_cataloging_utils.py +1 -1
  15. teradataml/clients/auth_client.py +133 -0
  16. teradataml/common/aed_utils.py +3 -2
  17. teradataml/common/constants.py +11 -6
  18. teradataml/common/garbagecollector.py +5 -0
  19. teradataml/common/messagecodes.py +3 -1
  20. teradataml/common/messages.py +2 -1
  21. teradataml/common/utils.py +6 -0
  22. teradataml/context/context.py +49 -29
  23. teradataml/data/advertising.csv +201 -0
  24. teradataml/data/bank_marketing.csv +11163 -0
  25. teradataml/data/bike_sharing.csv +732 -0
  26. teradataml/data/boston2cols.csv +721 -0
  27. teradataml/data/breast_cancer.csv +570 -0
  28. teradataml/data/customer_segmentation_test.csv +2628 -0
  29. teradataml/data/customer_segmentation_train.csv +8069 -0
  30. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingFit.py +3 -1
  31. teradataml/data/docs/sqle/docs_17_10/OneHotEncodingTransform.py +6 -0
  32. teradataml/data/docs/sqle/docs_17_10/OutlierFilterTransform.py +5 -1
  33. teradataml/data/docs/sqle/docs_17_20/ANOVA.py +61 -1
  34. teradataml/data/docs/sqle/docs_17_20/ColumnTransformer.py +2 -0
  35. teradataml/data/docs/sqle/docs_17_20/FTest.py +105 -26
  36. teradataml/data/docs/sqle/docs_17_20/GLM.py +162 -1
  37. teradataml/data/docs/sqle/docs_17_20/GetFutileColumns.py +5 -3
  38. teradataml/data/docs/sqle/docs_17_20/KMeans.py +48 -1
  39. teradataml/data/docs/sqle/docs_17_20/NonLinearCombineFit.py +3 -2
  40. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingFit.py +5 -0
  41. teradataml/data/docs/sqle/docs_17_20/OneHotEncodingTransform.py +6 -0
  42. teradataml/data/docs/sqle/docs_17_20/ROC.py +3 -2
  43. teradataml/data/docs/sqle/docs_17_20/SVMPredict.py +13 -2
  44. teradataml/data/docs/sqle/docs_17_20/ScaleFit.py +119 -1
  45. teradataml/data/docs/sqle/docs_17_20/ScaleTransform.py +93 -1
  46. teradataml/data/docs/sqle/docs_17_20/TDGLMPredict.py +163 -1
  47. teradataml/data/docs/sqle/docs_17_20/XGBoost.py +12 -4
  48. teradataml/data/docs/sqle/docs_17_20/XGBoostPredict.py +7 -1
  49. teradataml/data/docs/sqle/docs_17_20/ZTest.py +72 -7
  50. teradataml/data/glm_example.json +28 -1
  51. teradataml/data/housing_train_segment.csv +201 -0
  52. teradataml/data/insect2Cols.csv +61 -0
  53. teradataml/data/jsons/sqle/17.20/TD_ANOVA.json +99 -27
  54. teradataml/data/jsons/sqle/17.20/TD_FTest.json +166 -83
  55. teradataml/data/jsons/sqle/17.20/TD_GLM.json +90 -14
  56. teradataml/data/jsons/sqle/17.20/TD_GLMPREDICT.json +48 -5
  57. teradataml/data/jsons/sqle/17.20/TD_GetFutileColumns.json +5 -3
  58. teradataml/data/jsons/sqle/17.20/TD_KMeans.json +31 -11
  59. teradataml/data/jsons/sqle/17.20/TD_NonLinearCombineFit.json +3 -2
  60. teradataml/data/jsons/sqle/17.20/TD_ROC.json +2 -1
  61. teradataml/data/jsons/sqle/17.20/TD_SVM.json +16 -16
  62. teradataml/data/jsons/sqle/17.20/TD_SVMPredict.json +19 -1
  63. teradataml/data/jsons/sqle/17.20/TD_ScaleFit.json +168 -15
  64. teradataml/data/jsons/sqle/17.20/TD_ScaleTransform.json +50 -1
  65. teradataml/data/jsons/sqle/17.20/TD_XGBoost.json +25 -7
  66. teradataml/data/jsons/sqle/17.20/TD_XGBoostPredict.json +17 -4
  67. teradataml/data/jsons/sqle/17.20/TD_ZTest.json +157 -80
  68. teradataml/data/kmeans_example.json +5 -0
  69. teradataml/data/kmeans_table.csv +10 -0
  70. teradataml/data/onehot_encoder_train.csv +4 -0
  71. teradataml/data/openml_example.json +29 -0
  72. teradataml/data/scale_attributes.csv +3 -0
  73. teradataml/data/scale_example.json +52 -1
  74. teradataml/data/scale_input_part_sparse.csv +31 -0
  75. teradataml/data/scale_input_partitioned.csv +16 -0
  76. teradataml/data/scale_input_sparse.csv +11 -0
  77. teradataml/data/scale_parameters.csv +3 -0
  78. teradataml/data/scripts/deploy_script.py +20 -1
  79. teradataml/data/scripts/sklearn/sklearn_fit.py +23 -27
  80. teradataml/data/scripts/sklearn/sklearn_fit_predict.py +20 -28
  81. teradataml/data/scripts/sklearn/sklearn_function.template +13 -18
  82. teradataml/data/scripts/sklearn/sklearn_model_selection_split.py +23 -33
  83. teradataml/data/scripts/sklearn/sklearn_neighbors.py +18 -27
  84. teradataml/data/scripts/sklearn/sklearn_score.py +20 -29
  85. teradataml/data/scripts/sklearn/sklearn_transform.py +30 -38
  86. teradataml/data/teradataml_example.json +77 -0
  87. teradataml/data/ztest_example.json +16 -0
  88. teradataml/dataframe/copy_to.py +8 -3
  89. teradataml/dataframe/data_transfer.py +120 -61
  90. teradataml/dataframe/dataframe.py +102 -17
  91. teradataml/dataframe/dataframe_utils.py +47 -9
  92. teradataml/dataframe/fastload.py +272 -89
  93. teradataml/dataframe/sql.py +84 -0
  94. teradataml/dbutils/dbutils.py +2 -2
  95. teradataml/lib/aed_0_1.dll +0 -0
  96. teradataml/opensource/sklearn/_sklearn_wrapper.py +102 -55
  97. teradataml/options/__init__.py +13 -4
  98. teradataml/options/configure.py +27 -6
  99. teradataml/scriptmgmt/UserEnv.py +19 -16
  100. teradataml/scriptmgmt/lls_utils.py +117 -14
  101. teradataml/table_operators/Script.py +2 -3
  102. teradataml/table_operators/TableOperator.py +58 -10
  103. teradataml/utils/validators.py +40 -2
  104. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.1.dist-info}/METADATA +78 -6
  105. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.1.dist-info}/RECORD +108 -90
  106. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.1.dist-info}/WHEEL +0 -0
  107. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.1.dist-info}/top_level.txt +0 -0
  108. {teradataml-20.0.0.0.dist-info → teradataml-20.0.0.1.dist-info}/zip-safe +0 -0
@@ -5,35 +5,24 @@ import base64
5
5
 
6
6
  DELIMITER = '\t'
7
7
 
8
- def get_value(value):
9
- ret_val = value
10
- try:
11
- ret_val = float(value.replace(' ', ''))
12
- except Exception as ex:
13
- # If the value can't be converted to float, then it is string.
14
- pass
15
- return ret_val
16
-
17
-
18
- def get_values_list(values, ignore_none=True):
8
+ def get_values_list(values, types, model_obj):
19
9
  ret_vals = []
20
- for val in values:
21
- if val == "" and ignore_none:
22
- # Empty cell value in the database table.
10
+ for i, val in enumerate(values):
11
+ if type(model_obj).__name__ == "MultiLabelBinarizer" and val == "":
23
12
  continue
24
- ret_vals.append(get_value(val))
25
-
13
+ ret_vals.append(convert_to_type(val, types[i]))
26
14
  return ret_vals
27
15
 
28
16
  def convert_to_type(val, typee):
29
17
  if typee == 'int':
30
- return int(val)
18
+ return int(val) if val != "" else np.nan
31
19
  if typee == 'float':
32
- val = get_value(val)
33
- return float(val)
20
+ if isinstance(val, str):
21
+ val = val.replace(' ', '')
22
+ return float(val) if val != "" else np.nan
34
23
  if typee == 'bool':
35
- return bool(val)
36
- return str(val)
24
+ return eval(val) if val != "" else None
25
+ return str(val) if val != "" else None
37
26
 
38
27
  def get_classes_as_list(classes, actual_type):
39
28
  if classes == "None":
@@ -66,14 +55,14 @@ if len(sys.argv) != 10:
66
55
  # 3. No of feature columns.
67
56
  # 4. No of class labels.
68
57
  # 5. Comma separated indices of partition columns.
69
- # 6. Comma separated types of the partition columns.
58
+ # 6. Comma separated types of all the data columns.
70
59
  # 7. Model file prefix to generated model file using partition columns.
71
60
  # 8. classes (separated by '--') - should be converted to list. "None" if no classes exists.
72
61
  # 9. type of elements in passed in classes. "None" if no classes exists.
73
62
  # 10. Flag to check the system type. True, means Lake, Enterprise otherwise
74
63
  sys.exit("10 arguments command line arguments should be passed: file to be run,"
75
64
  " function name, no of feature columns, no of class labels, comma separated indices"
76
- " and types of partition columns, model file prefix ,"
65
+ " of partition columns, comma separated types of all columns, model file prefix ,"
77
66
  " classes, type of elements in classes and flag to check lake or enterprise.")
78
67
 
79
68
  is_lake_system = eval(sys.argv[9])
@@ -82,12 +71,14 @@ if not is_lake_system:
82
71
  function_name = sys.argv[1]
83
72
  n_f_cols = int(sys.argv[2])
84
73
  n_c_labels = int(sys.argv[3])
85
- data_partition_column_types = splitter(sys.argv[5])
74
+ data_column_types = splitter(sys.argv[5], delim="--")
86
75
  data_partition_column_indices = splitter(sys.argv[4], convert_to="int") # indices are integers.
87
76
  model_file_prefix = sys.argv[6]
88
77
  class_type = sys.argv[8]
89
78
  classes = get_classes_as_list(sys.argv[7], class_type)
90
79
 
80
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
81
+
91
82
  model = None
92
83
 
93
84
  # Data Format (n_features, k_labels, one data_partition_column):
@@ -108,9 +99,7 @@ while 1:
108
99
  break
109
100
  else:
110
101
  values = line.split(DELIMITER)
111
- features.append(get_values_list(values[:n_f_cols]))
112
- if n_c_labels > 0:
113
- labels.append(get_values_list(values[n_f_cols:(n_f_cols+n_c_labels)]))
102
+
114
103
  if not data_partition_column_values:
115
104
  # Partition column values is same for all rows. Hence, only read once.
116
105
  for i, val in enumerate(data_partition_column_indices):
@@ -133,6 +122,13 @@ while 1:
133
122
  if model is None:
134
123
  sys.exit("Model file is not installed in Vantage.")
135
124
 
125
+ values = get_values_list(values, data_column_types, model)
126
+ values = values[:-len(data_partition_column_indices)] # Already processed partition columns.
127
+ features.append(values[:n_f_cols])
128
+ if n_c_labels > 0:
129
+ labels.append(values[n_f_cols:(n_f_cols+n_c_labels)])
130
+
131
+
136
132
  except EOFError: # Exit if reached EOF or CTRL-D
137
133
  break
138
134
 
@@ -5,33 +5,22 @@ import math
5
5
 
6
6
  DELIMITER = '\t'
7
7
 
8
- def get_value(value):
9
- ret_val = value
10
- try:
11
- ret_val = float(value.replace(' ', ''))
12
- except Exception as ex:
13
- # If the value can't be converted to float, then it is string.
14
- pass
15
- return ret_val
16
-
17
- def get_values_list(values, ignore_none=True):
8
+ def get_values_list(values, types):
18
9
  ret_vals = []
19
- for val in values:
20
- if val == "" and ignore_none:
21
- # Empty cell value in the database table.
22
- continue
23
- ret_vals.append(get_value(val))
24
-
10
+ for i, val in enumerate(values):
11
+ ret_vals.append(convert_to_type(val, types[i]))
25
12
  return ret_vals
26
13
 
27
14
  def convert_to_type(val, typee):
28
15
  if typee == 'int':
29
- return int(val)
16
+ return int(val) if val != "" else np.nan
30
17
  if typee == 'float':
31
- return float(val)
18
+ if isinstance(val, str):
19
+ val = val.replace(' ', '')
20
+ return float(val) if val != "" else np.nan
32
21
  if typee == 'bool':
33
- return bool(val)
34
- return str(val)
22
+ return eval(val) if val != "" else None
23
+ return str(val) if val != "" else None
35
24
 
36
25
  def splitter(strr, delim=",", convert_to="str"):
37
26
  """
@@ -48,13 +37,13 @@ if len(sys.argv) != 7:
48
37
  # 2. No of feature columns.
49
38
  # 3. No of class labels.
50
39
  # 4. Comma separated indices of partition columns.
51
- # 5. Comma separated types of the partition columns.
40
+ # 5. Comma separated types of all the data columns.
52
41
  # 6. Model file prefix to generated model file using partition columns.
53
42
  # 7. Flag to check the system type. True, means Lake, Enterprise otherwise.
54
43
  sys.exit("7 arguments should be passed to this file - file to be run, "\
55
- "no of feature columns, no of class labels, comma separated indices and types of "\
56
- "partition columns, model file prefix to generate model file using partition "\
57
- "columns and flag to check lake or enterprise.")
44
+ "no of feature columns, no of class labels, comma separated indices of partition "
45
+ "columns, comma separated types of all columns, model file prefix to generate model "
46
+ "file using partition columns and flag to check lake or enterprise.")
58
47
 
59
48
  is_lake_system = eval(sys.argv[6])
60
49
  if not is_lake_system:
@@ -62,9 +51,11 @@ if not is_lake_system:
62
51
  n_f_cols = int(sys.argv[1])
63
52
  n_c_labels = int(sys.argv[2])
64
53
  model_file_prefix = sys.argv[5]
65
- data_partition_column_types = splitter(sys.argv[4])
54
+ data_column_types = splitter(sys.argv[4], delim="--")
66
55
  data_partition_column_indices = splitter(sys.argv[3], convert_to="int") # indices are integers.
67
56
 
57
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
58
+
68
59
  model = None
69
60
 
70
61
  # Data Format (n_features, k_labels, one data_partition_columns):
@@ -85,9 +76,10 @@ while 1:
85
76
  break
86
77
  else:
87
78
  values = line.split(DELIMITER)
88
- features.append(get_values_list(values[:n_f_cols]))
79
+ values = get_values_list(values, data_column_types)
80
+ features.append(values[:n_f_cols])
89
81
  if n_c_labels > 0:
90
- labels.append(get_values_list(values[n_f_cols:(n_f_cols+n_c_labels)]))
82
+ labels.append(values[n_f_cols:(n_f_cols+n_c_labels)])
91
83
  if not data_partition_column_values:
92
84
  # Partition column values is same for all rows. Hence, only read once.
93
85
  for i, val in enumerate(data_partition_column_indices):
@@ -130,6 +122,6 @@ for i in range(len(predictions)):
130
122
  else:
131
123
  result_list = features[i] + [predictions[i]]
132
124
  print(*(data_partition_column_values +
133
- ['' if (val is None or math.isnan(val) or math.isinf(val))
125
+ ['' if (val is None or (not isinstance(val, str) and (math.isnan(val) or math.isinf(val))))
134
126
  else val for val in result_list]),
135
127
  sep= DELIMITER)
@@ -8,23 +8,16 @@ params = json.loads('<params>')
8
8
 
9
9
  DELIMITER = '\t'
10
10
 
11
- def get_value(value):
12
- ret_val = value
13
- try:
14
- ret_val = float(value.replace(' ', ''))
15
- except Exception as ex:
16
- # If the value can't be converted to float, then it is string.
17
- pass
18
- return ret_val
19
-
20
11
  def convert_to_type(val, typee):
21
12
  if typee == 'int':
22
- return int(val)
13
+ return int(val) if val != "" else np.nan
23
14
  if typee == 'float':
24
- return get_value(val)
15
+ if isinstance(val, str):
16
+ val = val.replace(' ', '')
17
+ return float(val) if val != "" else np.nan
25
18
  if typee == 'bool':
26
- return bool(val)
27
- return str(val)
19
+ return eval(val) if val != "" else None
20
+ return str(val) if val != "" else None
28
21
 
29
22
  def splitter(strr, delim=",", convert_to="str"):
30
23
  """
@@ -39,17 +32,19 @@ if len(sys.argv) != 4:
39
32
  # 4 arguments command line arguments should be passed to this file.
40
33
  # 1: file to be run
41
34
  # 2. Comma separated indices of partition columns.
42
- # 3. Comma separated types of the partition columns.
35
+ # 3. Comma separated types of all the data columns.
43
36
  # 4. Data columns information separted by "--" where each data column information is in the form
44
37
  # "<arg_name>-<comma separated data indices>-<comma separated data types>".
45
38
  sys.exit("4 arguments command line arguments should be passed: file to be run,"
46
- " comma separated indices and types of partition columns, data columns information"
47
- " separated by '--' where each data column information is in the form"
48
- " '<arg_name>-<comma separated data indices>-<comma separated data types>'.")
39
+ " comma separated indices of partition columns, comma separated types of all columns,"
40
+ " data columns information separated by '--' where each data column information is"
41
+ " in the form '<arg_name>-<comma separated data indices>-<comma separated data types>'.")
49
42
 
50
43
  db = sys.argv[0].split("/")[1]
51
44
  data_partition_column_indices = splitter(sys.argv[1], convert_to="int") # indices are integers.
52
- data_partition_column_types = splitter(sys.argv[2])
45
+ data_column_types = splitter(sys.argv[2], delim="--")
46
+
47
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
53
48
 
54
49
  # Data related arguments information of indices and types.
55
50
  data_args_indices_types = OrderedDict()
@@ -6,35 +6,22 @@ import base64
6
6
 
7
7
  DELIMITER = '\t'
8
8
 
9
-
10
- def get_value(value):
11
- ret_val = value
12
- try:
13
- ret_val = round(float("".join(value.split())), 2)
14
- except Exception as ex:
15
- # If the value can't be converted to float, then it is string.
16
- pass
17
- return ret_val
18
-
19
-
20
- def get_values_list(values, ignore_none=True):
9
+ def get_values_list(values, types):
21
10
  ret_vals = []
22
- for val in values:
23
- if val == "" and ignore_none:
24
- # Empty cell value in the database table.
25
- continue
26
- ret_vals.append(get_value(val))
27
-
11
+ for i, val in enumerate(values):
12
+ ret_vals.append(convert_to_type(val, types[i]))
28
13
  return ret_vals
29
14
 
30
15
  def convert_to_type(val, typee):
31
16
  if typee == 'int':
32
- return int(val)
17
+ return int(val) if val != "" else np.nan
33
18
  if typee == 'float':
34
- return float(val)
19
+ if isinstance(val, str):
20
+ val = val.replace(' ', '')
21
+ return float(val) if val != "" else np.nan
35
22
  if typee == 'bool':
36
- return eval(val)
37
- return str(val)
23
+ return eval(val) if val != "" else None
24
+ return str(val) if val != "" else None
38
25
 
39
26
  def splitter(strr, delim=",", convert_to="str"):
40
27
  """
@@ -54,13 +41,14 @@ if len(sys.argv) != 9:
54
41
  # 4. No of class labels.
55
42
  # 5. No of group columns.
56
43
  # 6. Comma separated indices of partition columns.
57
- # 7. Comma separated types of the partition columns.
44
+ # 7. Comma separated types of all the data columns.
58
45
  # 8. Model file prefix to generated model file using partition columns.
59
46
  # 9. Flag to check the system type. True, means Lake, Enterprise otherwise.
60
47
  sys.exit("9 arguments command line arguments should be passed: file to be run,"
61
48
  " function name, no of feature columns, no of class labels, no of group columns,"
62
- " comma separated indices and types of partition columns, model file prefix to"
63
- " generated model file using partition columns and flag to check lake or enterprise.")
49
+ " comma separated indices of partition columns, comma separated types of all columns,"
50
+ " model file prefix to generated model file using partition columns and flag to check"
51
+ " lake or enterprise.")
64
52
 
65
53
 
66
54
  is_lake_system = eval(sys.argv[8])
@@ -70,10 +58,11 @@ function_name = sys.argv[1]
70
58
  n_f_cols = int(sys.argv[2])
71
59
  n_c_labels = int(sys.argv[3])
72
60
  n_g_cols = int(sys.argv[4])
73
- data_partition_column_types = splitter(sys.argv[6])
61
+ data_column_types = splitter(sys.argv[6], delim="--")
74
62
  data_partition_column_indices = splitter(sys.argv[5], convert_to="int") # indices are integers.
75
63
  model_file_prefix = sys.argv[7]
76
64
 
65
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
77
66
 
78
67
  model = None
79
68
  data_partition_column_values = []
@@ -93,6 +82,7 @@ while 1:
93
82
  break
94
83
  else:
95
84
  values = line.split(DELIMITER)
85
+ values = get_values_list(values, data_column_types)
96
86
  if not data_partition_column_values:
97
87
  # Partition column values is same for all rows. Hence, only read once.
98
88
  for i, val in enumerate(data_partition_column_indices):
@@ -117,13 +107,13 @@ while 1:
117
107
 
118
108
  start = 0
119
109
  if n_f_cols > 0:
120
- features.append(get_values_list(values[:n_f_cols]))
110
+ features.append(values[:n_f_cols])
121
111
  start = start + n_f_cols
122
112
  if n_c_labels > 0:
123
- labels.append(get_values_list(values[start:(start+n_c_labels)]))
113
+ labels.append(values[start:(start+n_c_labels)])
124
114
  start = start + n_c_labels
125
115
  if n_g_cols > 0:
126
- groups.append(get_values_list(values[start:(start+n_g_cols)]))
116
+ groups.append(values[start:(start+n_g_cols)])
127
117
 
128
118
  except EOFError: # Exit if reached EOF or CTRL-D
129
119
  break
@@ -144,14 +134,14 @@ if function_name == "split":
144
134
  y_train, y_test = labels[train_idx], labels[test_idx]
145
135
  for X, y in zip(X_train, y_train):
146
136
  print(*(data_partition_column_values + [split_id, "train"] +
147
- ['' if (val is None or math.isnan(val) or math.isinf(val)) else val
137
+ ['' if (val is None or (not isinstance(val, str) and (math.isnan(val) or math.isinf(val)))) else val
148
138
  for val in X] + [y]
149
- ),sep=DELIMITER)
139
+ ), sep=DELIMITER)
150
140
  for X, y in zip(X_test, y_test):
151
141
  print(*(data_partition_column_values + [split_id, "test"] +
152
- ['' if (val is None or math.isnan(val) or math.isinf(val)) else val
142
+ ['' if (val is None or (not isinstance(val, str) and (math.isnan(val) or math.isinf(val)))) else val
153
143
  for val in X] + [y]
154
- ),sep=DELIMITER)
144
+ ), sep=DELIMITER)
155
145
  split_id += 1
156
146
  else:
157
147
  val = getattr(model, function_name)(features, labels, groups)
@@ -12,34 +12,22 @@ from scipy.sparse.csr import csr_matrix
12
12
  DELIMITER = '\t'
13
13
 
14
14
 
15
- def get_value(value):
16
- ret_val = value
17
- try:
18
- ret_val = float(value.replace(' ', ''))
19
- except Exception as ex:
20
- # If the value can't be converted to float, then it is string.
21
- pass
22
- return ret_val
23
-
24
-
25
- def get_values_list(values, ignore_none=True):
15
+ def get_values_list(values, types):
26
16
  ret_vals = []
27
- for val in values:
28
- if val == "" and ignore_none:
29
- # Empty cell value in the database table.
30
- continue
31
- ret_vals.append(get_value(val))
32
-
17
+ for i, val in enumerate(values):
18
+ ret_vals.append(convert_to_type(val, types[i]))
33
19
  return ret_vals
34
20
 
35
21
  def convert_to_type(val, typee):
36
22
  if typee == 'int':
37
- return int(val)
23
+ return int(val) if val != "" else np.nan
38
24
  if typee == 'float':
39
- return float(val)
25
+ if isinstance(val, str):
26
+ val = val.replace(' ', '')
27
+ return float(val) if val != "" else np.nan
40
28
  if typee == 'bool':
41
- return eval(val)
42
- return str(val)
29
+ return eval(val) if val != "" else None
30
+ return str(val) if val != "" else None
43
31
 
44
32
  def splitter(strr, delim=",", convert_to="str"):
45
33
  """
@@ -57,15 +45,15 @@ if len(sys.argv) < 7:
57
45
  # 2. function name.
58
46
  # 3. No of feature columns.
59
47
  # 4. Comma separated indices of partition columns.
60
- # 5. Comma separated types of the partition columns.
48
+ # 5. Comma separated types of all the data columns.
61
49
  # 6. Model file prefix to generate model file using partition columns.
62
50
  # 7. Flag to check the system type. True, means Lake, Enterprise otherwise.
63
51
  # 8. OPTIONAL - Arguments in string format like "return_distance True-bool",
64
52
  # "n_neighbors 3-int", "radius 3.4-float" etc.
65
53
  sys.exit("At least 7 arguments should be passed to this file - file to be run, function name, "\
66
- "no of feature columns, comma separated indices and types of partition columns, "\
67
- "model file prefix to generate model file using partition columns, flag to check "\
68
- "lake or enterprise and optional arguments in string format.")
54
+ "no of feature columns, comma separated indices of partition columns, comma "\
55
+ "separated types of all columns, model file prefix to generate model file using "\
56
+ "partition columns, flag to check lake or enterprise and optional arguments in string format.")
69
57
 
70
58
  convert_to_int = lambda x: int(x) if x != "None" else None
71
59
 
@@ -74,7 +62,7 @@ if not is_lake_system:
74
62
  db = sys.argv[0].split("/")[1]
75
63
  func_name = sys.argv[1]
76
64
  n_f_cols = convert_to_int(sys.argv[2])
77
- data_partition_column_types = splitter(sys.argv[4])
65
+ data_column_types = splitter(sys.argv[4], delim="--")
78
66
  data_partition_column_indices = splitter(sys.argv[3], convert_to="int") # indices are integers.
79
67
  model_file_prefix = sys.argv[5]
80
68
  # Extract arguments from string.
@@ -83,6 +71,8 @@ for i in range(7, len(sys.argv), 2):
83
71
  value = sys.argv[i + 1].split("-", 1)
84
72
  arguments[sys.argv[i]] = convert_to_type(value[0], value[1])
85
73
 
74
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
75
+
86
76
  model = None
87
77
  data_partition_column_values = []
88
78
 
@@ -101,6 +91,7 @@ while 1:
101
91
  break
102
92
  else:
103
93
  values = line.split(DELIMITER)
94
+ values = get_values_list(values, data_column_types)
104
95
  if not data_partition_column_values:
105
96
  # Partition column values is same for all rows. Hence, only read once.
106
97
  for i, val in enumerate(data_partition_column_indices):
@@ -123,7 +114,7 @@ while 1:
123
114
  if not model:
124
115
  sys.exit("Model file is not installed in Vantage.")
125
116
 
126
- f_ = get_values_list(values[:n_f_cols])
117
+ f_ = values[:n_f_cols]
127
118
  if f_:
128
119
  output = getattr(model, func_name)(np.array([f_]), **arguments)
129
120
  else:
@@ -6,34 +6,22 @@ import numpy as np
6
6
  DELIMITER = '\t'
7
7
 
8
8
 
9
- def get_value(value):
10
- ret_val = value
11
- try:
12
- ret_val = float("".join(value.split()))
13
- except Exception as ex:
14
- # If the value can't be converted to float, then it is string.
15
- pass
16
- return ret_val
17
-
18
-
19
- def get_values_list(values, ignore_none=True):
9
+ def get_values_list(values, types):
20
10
  ret_vals = []
21
- for val in values:
22
- if val == "" and ignore_none:
23
- # Empty cell value in the database table.
24
- continue
25
- ret_vals.append(get_value(val))
26
-
11
+ for i, val in enumerate(values):
12
+ ret_vals.append(convert_to_type(val, types[i]))
27
13
  return ret_vals
28
14
 
29
15
  def convert_to_type(val, typee):
30
16
  if typee == 'int':
31
- return int(val)
17
+ return int(val) if val != "" else np.nan
32
18
  if typee == 'float':
33
- return float(val)
19
+ if isinstance(val, str):
20
+ val = val.replace(' ', '')
21
+ return float(val) if val != "" else np.nan
34
22
  if typee == 'bool':
35
- return bool(val)
36
- return str(val)
23
+ return eval(val) if val != "" else None
24
+ return str(val) if val != "" else None
37
25
 
38
26
  def splitter(strr, delim=",", convert_to="str"):
39
27
  """
@@ -51,13 +39,13 @@ if len(sys.argv) != 8:
51
39
  # 3. No of feature columns.
52
40
  # 4. No of class labels.
53
41
  # 5. Comma separated indices of partition columns.
54
- # 6. Comma separated types of the partition columns.
42
+ # 6. Comma separated types of all the data columns.
55
43
  # 7. Model file prefix to generated model file using partition columns.
56
44
  # 8. Flag to check the system type. True, means Lake, Enterprise otherwise.
57
45
  sys.exit("8 arguments should be passed to this file - file to be run, function name, "\
58
- "no of feature columns, no of class labels, comma separated indices and types of "\
59
- "partition columns, model file prefix to generate model file using partition "\
60
- "columns and flag to check lake or enterprise.")
46
+ "no of feature columns, no of class labels, comma separated indices "
47
+ "of partition columns, comma separated types of all columns, model file prefix to "\
48
+ "generate model file using partition columns and flag to check lake or enterprise.")
61
49
 
62
50
  is_lake_system = eval(sys.argv[7])
63
51
  if not is_lake_system:
@@ -65,10 +53,12 @@ if not is_lake_system:
65
53
  func_name = sys.argv[1]
66
54
  n_f_cols = int(sys.argv[2])
67
55
  n_c_labels = int(sys.argv[3])
68
- data_partition_column_types = splitter(sys.argv[5])
56
+ data_column_types = splitter(sys.argv[5], delim="--")
69
57
  data_partition_column_indices = splitter(sys.argv[4], convert_to="int") # indices are integers.
70
58
  model_file_prefix = sys.argv[6]
71
59
 
60
+ data_partition_column_types = [data_column_types[idx] for idx in data_partition_column_indices]
61
+
72
62
  model = None
73
63
 
74
64
  # Data Format (n_features, k_labels, one data_partition_column):
@@ -87,9 +77,10 @@ while 1:
87
77
  break
88
78
  else:
89
79
  values = line.split(DELIMITER)
90
- features.append(get_values_list(values[:n_f_cols]))
80
+ values = get_values_list(values, data_column_types)
81
+ features.append(values[:n_f_cols])
91
82
  if n_c_labels > 0:
92
- labels.append(get_values_list(values[n_f_cols:(n_f_cols+n_c_labels)]))
83
+ labels.append(values[n_f_cols:(n_f_cols+n_c_labels)])
93
84
 
94
85
  if not data_partition_column_values:
95
86
  # Partition column values is same for all rows. Hence, only read once.
@@ -124,5 +115,5 @@ if labels:
124
115
  else:
125
116
  val = getattr(model, func_name)(np.array(features))
126
117
 
127
- result_val = ['' if (val is None or math.isnan(val) or math.isinf(val)) else val]
118
+ result_val = ['' if (val is None or (not isinstance(val, str) and (math.isnan(val) or math.isinf(val)))) else val]
128
119
  print(*(data_partition_column_values + result_val), sep=DELIMITER)