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.

Files changed (151) hide show
  1. teradataml/LICENSE-3RD-PARTY.pdf +0 -0
  2. teradataml/README.md +193 -1
  3. teradataml/__init__.py +2 -1
  4. teradataml/_version.py +2 -2
  5. teradataml/analytics/analytic_function_executor.py +25 -18
  6. teradataml/analytics/byom/__init__.py +1 -1
  7. teradataml/analytics/json_parser/analytic_functions_argument.py +4 -0
  8. teradataml/analytics/sqle/__init__.py +20 -2
  9. teradataml/analytics/utils.py +15 -1
  10. teradataml/analytics/valib.py +18 -4
  11. teradataml/automl/__init__.py +341 -112
  12. teradataml/automl/autodataprep/__init__.py +471 -0
  13. teradataml/automl/data_preparation.py +84 -42
  14. teradataml/automl/data_transformation.py +69 -33
  15. teradataml/automl/feature_engineering.py +76 -9
  16. teradataml/automl/feature_exploration.py +639 -25
  17. teradataml/automl/model_training.py +35 -14
  18. teradataml/clients/auth_client.py +2 -2
  19. teradataml/common/__init__.py +1 -2
  20. teradataml/common/constants.py +122 -63
  21. teradataml/common/messagecodes.py +14 -3
  22. teradataml/common/messages.py +8 -4
  23. teradataml/common/sqlbundle.py +40 -10
  24. teradataml/common/utils.py +366 -74
  25. teradataml/common/warnings.py +11 -0
  26. teradataml/context/context.py +348 -86
  27. teradataml/data/amazon_reviews_25.csv +26 -0
  28. teradataml/data/apriori_example.json +22 -0
  29. teradataml/data/byom_example.json +11 -0
  30. teradataml/data/docs/byom/docs/DataRobotPredict.py +2 -2
  31. teradataml/data/docs/byom/docs/DataikuPredict.py +40 -1
  32. teradataml/data/docs/byom/docs/H2OPredict.py +2 -2
  33. teradataml/data/docs/byom/docs/ONNXEmbeddings.py +242 -0
  34. teradataml/data/docs/byom/docs/ONNXPredict.py +2 -2
  35. teradataml/data/docs/byom/docs/PMMLPredict.py +2 -2
  36. teradataml/data/docs/sqle/docs_17_20/Apriori.py +138 -0
  37. teradataml/data/docs/sqle/docs_17_20/NERExtractor.py +121 -0
  38. teradataml/data/docs/sqle/docs_17_20/NGramSplitter.py +3 -3
  39. teradataml/data/docs/sqle/docs_17_20/SMOTE.py +212 -0
  40. teradataml/data/docs/sqle/docs_17_20/Shap.py +28 -6
  41. teradataml/data/docs/sqle/docs_17_20/TextMorph.py +119 -0
  42. teradataml/data/docs/sqle/docs_17_20/TextParser.py +54 -3
  43. teradataml/data/docs/uaf/docs_17_20/ACF.py +1 -1
  44. teradataml/data/docs/uaf/docs_17_20/ArimaEstimate.py +2 -2
  45. teradataml/data/docs/uaf/docs_17_20/ArimaXEstimate.py +2 -2
  46. teradataml/data/docs/uaf/docs_17_20/DFFT.py +1 -1
  47. teradataml/data/docs/uaf/docs_17_20/DFFT2.py +1 -1
  48. teradataml/data/docs/uaf/docs_17_20/DFFT2Conv.py +1 -1
  49. teradataml/data/docs/uaf/docs_17_20/DFFTConv.py +1 -1
  50. teradataml/data/docs/uaf/docs_17_20/DWT2D.py +4 -1
  51. teradataml/data/docs/uaf/docs_17_20/FilterFactory1d.py +4 -4
  52. teradataml/data/docs/uaf/docs_17_20/GenseriesSinusoids.py +2 -2
  53. teradataml/data/docs/uaf/docs_17_20/GoldfeldQuandt.py +2 -2
  54. teradataml/data/docs/uaf/docs_17_20/HoltWintersForecaster.py +6 -6
  55. teradataml/data/docs/uaf/docs_17_20/LineSpec.py +1 -1
  56. teradataml/data/docs/uaf/docs_17_20/LinearRegr.py +1 -1
  57. teradataml/data/docs/uaf/docs_17_20/Matrix2Image.py +4 -4
  58. teradataml/data/docs/uaf/docs_17_20/MultivarRegr.py +1 -1
  59. teradataml/data/docs/uaf/docs_17_20/PACF.py +1 -1
  60. teradataml/data/docs/uaf/docs_17_20/PowerSpec.py +2 -2
  61. teradataml/data/docs/uaf/docs_17_20/PowerTransform.py +3 -3
  62. teradataml/data/docs/uaf/docs_17_20/Resample.py +5 -5
  63. teradataml/data/docs/uaf/docs_17_20/SAX.py +3 -3
  64. teradataml/data/docs/uaf/docs_17_20/SignifPeriodicities.py +1 -1
  65. teradataml/data/docs/uaf/docs_17_20/SimpleExp.py +1 -1
  66. teradataml/data/docs/uaf/docs_17_20/Smoothma.py +3 -3
  67. teradataml/data/docs/uaf/docs_17_20/UNDIFF.py +1 -1
  68. teradataml/data/hnsw_alter_data.csv +5 -0
  69. teradataml/data/hnsw_data.csv +10 -0
  70. teradataml/data/jsons/byom/h2opredict.json +1 -1
  71. teradataml/data/jsons/byom/onnxembeddings.json +266 -0
  72. teradataml/data/jsons/sqle/17.20/NGramSplitter.json +6 -6
  73. teradataml/data/jsons/sqle/17.20/TD_Apriori.json +181 -0
  74. teradataml/data/jsons/sqle/17.20/TD_NERExtractor.json +145 -0
  75. teradataml/data/jsons/sqle/17.20/TD_SMOTE.json +267 -0
  76. teradataml/data/jsons/sqle/17.20/TD_Shap.json +0 -1
  77. teradataml/data/jsons/sqle/17.20/TD_TextMorph.json +134 -0
  78. teradataml/data/jsons/sqle/17.20/TD_TextParser.json +114 -9
  79. teradataml/data/jsons/sqle/20.00/AI_AnalyzeSentiment.json +328 -0
  80. teradataml/data/jsons/sqle/20.00/AI_AskLLM.json +420 -0
  81. teradataml/data/jsons/sqle/20.00/AI_DetectLanguage.json +343 -0
  82. teradataml/data/jsons/sqle/20.00/AI_ExtractKeyPhrases.json +328 -0
  83. teradataml/data/jsons/sqle/20.00/AI_MaskPII.json +328 -0
  84. teradataml/data/jsons/sqle/20.00/AI_RecognizeEntities.json +328 -0
  85. teradataml/data/jsons/sqle/20.00/AI_RecognizePIIEntities.json +328 -0
  86. teradataml/data/jsons/sqle/20.00/AI_TextClassifier.json +359 -0
  87. teradataml/data/jsons/sqle/20.00/AI_TextEmbeddings.json +360 -0
  88. teradataml/data/jsons/sqle/20.00/AI_TextSummarize.json +343 -0
  89. teradataml/data/jsons/sqle/20.00/AI_TextTranslate.json +343 -0
  90. teradataml/data/jsons/sqle/20.00/TD_HNSW.json +296 -0
  91. teradataml/data/jsons/sqle/20.00/TD_HNSWPredict.json +206 -0
  92. teradataml/data/jsons/sqle/20.00/TD_HNSWSummary.json +32 -0
  93. teradataml/data/jsons/sqle/20.00/TD_KMeans.json +2 -2
  94. teradataml/data/jsons/sqle/20.00/TD_SMOTE.json +3 -3
  95. teradataml/data/jsons/sqle/20.00/TD_VectorDistance.json +6 -6
  96. teradataml/data/ner_dict.csv +8 -0
  97. teradataml/data/ner_input_eng.csv +7 -0
  98. teradataml/data/ner_rule.csv +5 -0
  99. teradataml/data/pos_input.csv +40 -0
  100. teradataml/data/tdnerextractor_example.json +14 -0
  101. teradataml/data/teradataml_example.json +21 -0
  102. teradataml/data/textmorph_example.json +5 -0
  103. teradataml/data/to_num_data.csv +4 -0
  104. teradataml/data/tochar_data.csv +5 -0
  105. teradataml/data/trans_dense.csv +16 -0
  106. teradataml/data/trans_sparse.csv +55 -0
  107. teradataml/data/vectordistance_example.json +1 -1
  108. teradataml/dataframe/copy_to.py +45 -29
  109. teradataml/dataframe/data_transfer.py +72 -46
  110. teradataml/dataframe/dataframe.py +642 -166
  111. teradataml/dataframe/dataframe_utils.py +167 -22
  112. teradataml/dataframe/functions.py +135 -20
  113. teradataml/dataframe/setop.py +11 -6
  114. teradataml/dataframe/sql.py +330 -78
  115. teradataml/dbutils/dbutils.py +556 -140
  116. teradataml/dbutils/filemgr.py +14 -10
  117. teradataml/hyperparameter_tuner/optimizer.py +12 -1
  118. teradataml/lib/aed_0_1.dll +0 -0
  119. teradataml/opensource/{sklearn/_sklearn_wrapper.py → _base.py} +168 -1013
  120. teradataml/opensource/_class.py +141 -17
  121. teradataml/opensource/{constants.py → _constants.py} +7 -3
  122. teradataml/opensource/_lightgbm.py +52 -53
  123. teradataml/opensource/_sklearn.py +1008 -0
  124. teradataml/opensource/_wrapper_utils.py +5 -5
  125. teradataml/options/__init__.py +47 -15
  126. teradataml/options/configure.py +103 -26
  127. teradataml/options/display.py +13 -2
  128. teradataml/plot/axis.py +47 -8
  129. teradataml/plot/figure.py +33 -0
  130. teradataml/plot/plot.py +63 -13
  131. teradataml/scriptmgmt/UserEnv.py +307 -40
  132. teradataml/scriptmgmt/lls_utils.py +428 -145
  133. teradataml/store/__init__.py +2 -3
  134. teradataml/store/feature_store/feature_store.py +102 -7
  135. teradataml/table_operators/Apply.py +48 -19
  136. teradataml/table_operators/Script.py +23 -2
  137. teradataml/table_operators/TableOperator.py +3 -1
  138. teradataml/table_operators/table_operator_util.py +58 -9
  139. teradataml/utils/dtypes.py +49 -1
  140. teradataml/utils/internal_buffer.py +38 -0
  141. teradataml/utils/validators.py +377 -62
  142. {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/METADATA +200 -4
  143. {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/RECORD +146 -112
  144. teradataml/data/SQL_Fundamentals.pdf +0 -0
  145. teradataml/libaed_0_1.dylib +0 -0
  146. teradataml/libaed_0_1.so +0 -0
  147. teradataml/opensource/sklearn/__init__.py +0 -0
  148. teradataml/store/vector_store/__init__.py +0 -1586
  149. {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/WHEEL +0 -0
  150. {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/top_level.txt +0 -0
  151. {teradataml-20.0.0.3.dist-info → teradataml-20.0.0.5.dist-info}/zip-safe +0 -0
@@ -14,25 +14,28 @@
14
14
  import functools
15
15
  import inspect
16
16
  import json
17
+ import os
18
+ import tempfile
19
+ import time
20
+ from concurrent.futures import ThreadPoolExecutor, wait
17
21
  from json.decoder import JSONDecodeError
18
- import os, time
22
+ from urllib.parse import urlparse
19
23
  import pandas as pd
20
24
  import requests
21
- import tempfile
25
+
22
26
  from teradataml import configure
23
- from teradataml.utils.internal_buffer import _InternalBuffer
24
- from concurrent.futures import ThreadPoolExecutor, wait
25
- from teradataml.clients.pkce_client import _DAWorkflow
26
27
  from teradataml.clients.auth_client import _AuthWorkflow
27
- from teradataml.context.context import _get_user
28
- from teradataml.common.constants import HTTPRequest, CloudProvider
28
+ from teradataml.clients.pkce_client import _DAWorkflow
29
+ from teradataml.common.constants import (AsyncOpStatus, CloudProvider,
30
+ HTTPRequest)
29
31
  from teradataml.common.exceptions import TeradataMlException
30
- from teradataml.common.messages import Messages
31
32
  from teradataml.common.messagecodes import MessageCodes
33
+ from teradataml.common.messages import Messages
32
34
  from teradataml.common.utils import UtilFuncs
33
- from teradataml.utils.validators import _Validators
34
- from urllib.parse import urlparse
35
+ from teradataml.context.context import _get_user
35
36
  from teradataml.telemetry_utils.queryband import collect_queryband
37
+ from teradataml.utils.internal_buffer import _InternalBuffer
38
+ from teradataml.utils.validators import _Validators
36
39
 
37
40
 
38
41
  def _get_ues_url(env_type="users", **kwargs):
@@ -86,8 +89,8 @@ def _get_ues_url(env_type="users", **kwargs):
86
89
  raise TeradataMlException(error_msg, MessageCodes.FUNC_EXECUTION_FAILED)
87
90
 
88
91
  if configure.ues_url is None:
89
- error_msg = Messages.get_message(MessageCodes.DEPENDENT_ARGUMENT,
90
- api_name, 'configure.ues_url')
92
+ error_msg = Messages.get_message(MessageCodes.SET_REQUIRED_PARAMS,
93
+ 'Authentication Token', api_name, 'set_auth_token')
91
94
  raise RuntimeError(error_msg)
92
95
 
93
96
  ues_url = "{}/{}".format(configure.ues_url, env_type)
@@ -205,7 +208,8 @@ def _process_ues_response(api_name, response, success_status_code=None):
205
208
  def _get_auth_token():
206
209
  """
207
210
  DESCRIPTION:
208
- Internal function to get Authentication token for all CCP enabled REST calls
211
+ Internal function to get authentication token required to access services
212
+ running on Teradata Vantage.
209
213
 
210
214
  PARAMETERS:
211
215
  None
@@ -237,14 +241,43 @@ def _get_auth_token():
237
241
  configure._auth_token_expiry_time = time.time() + token_data["expires_in"] - 15
238
242
 
239
243
  # Store the jwt token in internal class attribute.
240
- _InternalBuffer.add(auth_token=_AuthToken(token=token_data["access_token"]))
241
- if _InternalBuffer.get("auth_token"):
242
- return {"Authorization": "Bearer {}".format(_InternalBuffer.get("auth_token").value)}
244
+ _InternalBuffer.add(auth_token=_AuthToken(token=token_data["access_token"],
245
+ auth_type='bearer'))
246
+
247
+ auth_token = _InternalBuffer.get("auth_token")
248
+ if auth_token:
249
+ return auth_token.get_header()
250
+
251
+
252
+ def _get_ccp_url(base_url):
253
+ """
254
+ DESCRIPTION:
255
+ Internal function to get ccp URL from base_url.
256
+
257
+ PARAMETERS:
258
+ base_url:
259
+ Required Argument.
260
+ Specifies the base url.
261
+ Types: str
262
+
263
+ RETURNS:
264
+ str
265
+
266
+ RAISES:
267
+ None
268
+
269
+ EXAMPLES:
270
+ >>> base_url = 'https://<part_1>.<part_2>.<part_3>.com/<part_4>/<part_5>/<part_6>'
271
+ >>> _get_ccp_url(base_url)
272
+ 'https://<part_1>.<part_2>.<part_3>.com'
273
+ """
274
+ parsed_url = urlparse(base_url)
275
+ return f"{parsed_url.scheme}://{parsed_url.netloc}"
243
276
 
244
277
 
245
278
  class UserEnv:
246
279
 
247
- def __init__(self, env_name, base_env, desc=None):
280
+ def __init__(self, env_name, base_env, desc=None, conda_env=False):
248
281
  """
249
282
  DESCRIPTION:
250
283
  Represents remote user environment from Vantage Languages Ecosystem.
@@ -267,6 +300,13 @@ class UserEnv:
267
300
  Optional Argument.
268
301
  Specifies description associated with the remote user environment.
269
302
  Types: str
303
+
304
+ conda_env:
305
+ Optional Argument.
306
+ Specifies whether the environment to be created is a conda environment or not.
307
+ When set to True, conda environment is created. Otherwise, non conda environment is created.
308
+ Default value: False
309
+ Types: bool
270
310
 
271
311
  RETURNS:
272
312
  Instance of the class UserEnv.
@@ -293,6 +333,10 @@ class UserEnv:
293
333
  self.base_env = base_env
294
334
  self.desc = desc
295
335
 
336
+ self.conda_env = conda_env
337
+ # Initialize variable for R environment.
338
+ self._r_env = True if self.base_env.lower().startswith("r_") else False
339
+
296
340
  # Initialize variables to store files, libraries and models from
297
341
  # the remote user environment.
298
342
  self.__files = None
@@ -434,7 +478,7 @@ class UserEnv:
434
478
 
435
479
  # Create conda environment.
436
480
  >>> testenv_conda = create_env('testenv_conda', 'python_3.8', 'Test conda environment', conda_env=True)
437
- Conda environment creation initiated
481
+ Conda environment creation initiated.
438
482
  User environment 'testenv_conda' created.
439
483
 
440
484
  # Example 1: Install the file mapper.py in the 'testenv' environment.
@@ -1336,7 +1380,10 @@ class UserEnv:
1336
1380
  if self.base_env.lower().startswith('python_'):
1337
1381
  _Validators._validate_file_extension(libs_file_path, ['txt'])
1338
1382
  elif self.base_env.lower().startswith('r_'):
1339
- _Validators._validate_file_extension(libs_file_path, ['txt', 'json'])
1383
+ if self.conda_env:
1384
+ _Validators._validate_file_extension(libs_file_path, ['txt'])
1385
+ else:
1386
+ _Validators._validate_file_extension(libs_file_path, ['txt', 'json'])
1340
1387
 
1341
1388
  _Validators._check_empty_file(libs_file_path)
1342
1389
 
@@ -1446,7 +1493,8 @@ class UserEnv:
1446
1493
  Returns:
1447
1494
  None
1448
1495
  """
1449
- if self.base_env.lower().startswith("python"):
1496
+ # Check if the env is python or conda env
1497
+ if not self._r_env or self.conda_env:
1450
1498
  if isinstance(libs, list):
1451
1499
  return '\n'.join(libs)
1452
1500
  return libs
@@ -1475,6 +1523,11 @@ class UserEnv:
1475
1523
  the environment. Use "update_lib" API only to upgrade or downgrade installed
1476
1524
  packages and do not use it for fresh package installation when multiple
1477
1525
  packages have the same dependency as it messes pip's package resolution ability.
1526
+ * For Conda R environment:
1527
+ * The library version cannot be specified. Conda only install packages to the
1528
+ latest compatible version and cannot install to a specific version.
1529
+ * The libraries should have "r-" prefix in the library name.
1530
+
1478
1531
 
1479
1532
  PARAMETERS:
1480
1533
  libs:
@@ -1498,6 +1551,7 @@ class UserEnv:
1498
1551
  * Either "libs" or "libs_file_path" argument must be specified.
1499
1552
  * The file must have ".txt" extension for Python environment
1500
1553
  and ".txt"/".json" extension for R environment.
1554
+ * The file must have ".txt" extension for conda environment.
1501
1555
  * The file format should adhere to the specifications of the
1502
1556
  requirements file used by underlying language's package
1503
1557
  manager to install libraries.
@@ -2063,11 +2117,97 @@ class UserEnv:
2063
2117
  39 zoo 1.8-12
2064
2118
  >>>
2065
2119
 
2120
+ # Create remote user conda R environment.
2121
+ >>> env = create_env('testenv', base_env='r_4.3', desc='Test environment', conda_env=True)
2122
+ Conda environment creation initiated.
2123
+ User environment 'testenv' created.
2124
+
2125
+ # Example 1: Install single R library asynchronously.
2126
+ >>> env.install_lib('r-glm2', asynchronous=True)
2127
+ Request to install libraries initiated successfully in the remote user environment testenv.
2128
+ Check the status using status() with the claim id 'cccc29fe-ca45-49a6-9565-3d50bf310c92'.
2129
+
2130
+ # Check the status.
2131
+ >>> env.status('cccc29fe-ca45-49a6-9565-3d50bf310c92')
2132
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2133
+ cccc29fe-ca45-49a6-9565-3d50bf310c92 r-glm2 install_lib Started 2024-12-27T08:42:10Z
2134
+ cccc29fe-ca45-49a6-9565-3d50bf310c92 r-glm2 install_lib Finished 2024-12-27T08:42:20Z
2135
+
2136
+ # Verify if libraries are installed.
2137
+ >>> env.libs[env.libs['name'].isin(['r-glm2'])]
2138
+ name version
2139
+ 91 r-glm2 1.2.1
2140
+
2141
+ # Example 2: Install libraries asynchronously by passing them as list of library names.
2142
+ >>> env.install_lib(['r-ggplot2', 'r-dplyr'], asynchronous=True)
2143
+ Request to install libraries initiated successfully in the remote user environment testenv.
2144
+ Check the status using status() with the claim id '1125fa9e-b0f4-49cb-9c9f-d4931a22222d'.
2145
+
2146
+ # Check the status.
2147
+ >>> env.status('1125fa9e-b0f4-49cb-9c9f-d4931a22222d')
2148
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2149
+ 1125fa9e-b0f4-49cb-9c9f-d4931a22222d r-ggplot2, r-dplyr install_lib Started 2024-12-27T08:42:10Z
2150
+ 1125fa9e-b0f4-49cb-9c9f-d4931a22222d r-ggplot2, r-dplyr install_lib Finished 2024-12-27T08:42:20Z
2151
+
2152
+ # Verify if libraries are installed or not.
2153
+ >>> env.libs[env.libs['name'].isin(['r-ggplot2', 'r-dplyr'])]
2154
+ name version
2155
+ 79 r-dplyr 1.1.3
2156
+ 90 r-ggplot2 3.4.4
2157
+
2158
+ # Example 3: Install libraries synchronously by passing them as list of library names.
2159
+ >>> env.install_lib(["r-lubridate", "r-zoo"])
2160
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2161
+ 7a026a0d-6616-4398-bd89-9f8d0e06a54f r-lubridate, r-zoo install_lib Started 2024-12-27T08:46:55Z
2162
+ 7a026a0d-6616-4398-bd89-9f8d0e06a54f r-lubridate, r-zoo install_lib Finished 2024-12-27T08:47:06Z
2163
+
2164
+ # Verify if libraries are installed.
2165
+ >>> env.libs[env.libs['name'].isin(['r-lubridate', 'r-zoo'])]
2166
+ name version
2167
+ 108 r-lubridate 1.9.3
2168
+ 157 r-zoo 1.8_12
2169
+
2170
+ # Example 4: Install libraries synchronously by passing them as list of library names within a
2171
+ # specific timeout of 1 seconds.
2172
+ >>> env.install_lib(["r-stringi", "r-glm2"], timeout=1)
2173
+ Request to install libraries initiated successfully in the remote user environment 'testenv' but Timed out status check.
2174
+ Check the status using status() with the claim id '440eff39-c6d7-4efc-b797-1201a5906065'.
2175
+
2176
+ # Check the status.
2177
+ >>> env.status('440eff39-c6d7-4efc-b797-1201a5906065')
2178
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2179
+ 440eff39-c6d7-4efc-b797-1201a5906065 r-stringi, r-glm2 install_lib Started 2024-12-27T08:49:17Z
2180
+ 440eff39-c6d7-4efc-b797-1201a5906065 r-stringi, r-glm2 install_lib Finished 2024-12-27T08:49:27Z
2181
+
2182
+ # Verify if libraries are installed.
2183
+ >>> env.libs[env.libs['name'].isin(['r-stringi', 'r-glm2'])]
2184
+ name version
2185
+ 91 r-glm2 1.2.1
2186
+ 140 r-stringi 1.7.12
2187
+
2188
+ # Example 5: Install libraries synchronously by creating requirement.txt file.
2189
+ # Create a requirement.txt file with below contents.
2190
+ -----------------------------------------------------------
2191
+ r-caret
2192
+ r-forecast
2193
+ -----------------------------------------------------------
2194
+
2195
+ # Install libraries specified in the file.
2196
+ >>> env.install_lib(libs_file_path="requirement.txt")
2197
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2198
+ f3963a46-2225-412d-a470-17f26c759b42 requirement.txt install_lib Started 2024-12-27T08:52:28Z
2199
+ f3963a46-2225-412d-a470-17f26c759b42 requirement.txt install_lib Finished 2024-12-27T08:53:32Z
2200
+
2201
+ # Verify if libraries are installed.
2202
+ >>> env.libs[env.libs['name'].isin(['r-caret', 'r-forecast'])]
2203
+ name version
2204
+ 68 r-caret 6.0_94
2205
+ 85 r-forecast 8.21.1
2066
2206
  """
2067
2207
  asynchronous = kwargs.get("asynchronous", False)
2068
2208
  timeout = kwargs.get("timeout")
2069
- claim_id = self.__manage_libraries(libs, libs_file_path, "INSTALL", asynchronous, timeout)
2070
- return (claim_id)
2209
+ async_task_info = self.__manage_libraries(libs, libs_file_path, "INSTALL", asynchronous, timeout)
2210
+ return async_task_info
2071
2211
 
2072
2212
  @collect_queryband(queryband="UninstlLbs")
2073
2213
  def uninstall_lib(self, libs=None, libs_file_path=None, **kwargs):
@@ -2075,6 +2215,8 @@ class UserEnv:
2075
2215
  DESCRIPTION:
2076
2216
  Function uninstalls libraries from corresponding Python or R
2077
2217
  remote user environment.
2218
+ Note:
2219
+ * For Conda R environment, the libraries should have "r-" prefix in the library name.
2078
2220
 
2079
2221
  PARAMETERS:
2080
2222
  libs:
@@ -2094,6 +2236,7 @@ class UserEnv:
2094
2236
  * Either "libs" or "libs_file_path" argument must be specified.
2095
2237
  * The file must have ".txt" extension for Python environment
2096
2238
  and ".txt"/".json" extension for R environment.
2239
+ * The file must have ".txt" extension for conda environment.
2097
2240
  * The file format should adhere to the specifications of the
2098
2241
  requirements file used by underlying language's package
2099
2242
  manager for uninstalling libraries.
@@ -2504,11 +2647,65 @@ class UserEnv:
2504
2647
  65 waldo 0.5.1
2505
2648
  66 withr 2.5.0
2506
2649
  >>>
2650
+
2651
+ # Examples for conda R environment.
2652
+ # Create remote conda R user environment.
2653
+ >>> conda_r_env = create_env('test_conda_r_env', 'r_4.3', 'Test conda R environment', conda_env=True)
2654
+ Conda environment creation initiated.
2655
+ User environment 'test_conda_r_env' created.
2656
+
2657
+ # Install R libraries in conda environment.
2658
+ >>> conda_r_env.install_lib(['r-caret', 'r-forecast', 'r-glm2', 'r-anytime'])
2659
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
2660
+ ec6c087e-aee5-42fd-8677-a5f2a8bc5050 r-caret, r-forecast, r-glm2, r-anytime install_lib Started 2024-12-27T10:23:34Z
2661
+ ec6c087e-aee5-42fd-8677-a5f2a8bc5050 r-caret, r-forecast, r-glm2, r-anytime install_lib Finished 2024-12-27T10:28:15Z
2662
+
2663
+ # Verify installed libraries.
2664
+ >>> conda_r_env.libs[conda_r_env.libs['name'].isin(['r-caret', 'r-forecast', 'r-glm2', 'r-anytime'])]
2665
+ name version
2666
+ 67 r-anytime 0.3.9
2667
+ 70 r-caret 6.0_94
2668
+ 87 r-forecast 8.21.1
2669
+ 93 r-glm2 1.2.1
2670
+
2671
+ # Uninstall single R library asynchronously.
2672
+ >>> conda_r_env.uninstall_lib('r-caret', asynchronous=True)
2673
+ Request to uninstall libraries initiated successfully in the remote user environment testenv.
2674
+ Check the status using status() with the claim id '77db7baf-1c4f-4de0-8019-d0f72718b90f'.
2675
+
2676
+ # Check the status.
2677
+ >>> conda_r_env.status('77db7baf-1c4f-4de0-8019-d0f72718b90f')
2678
+ Claim Id File/Libs Method Name Stage Timestamp Additional Details
2679
+ 77db7baf-1c4f-4de0-8019-d0f72718b90f r-caret uninstall_lib Started 2024-12-27T08:49:17Z
2680
+ 77db7baf-1c4f-4de0-8019-d0f72718b90f r-caret uninstall_lib Finished 2024-12-27T08:49:19Z
2681
+
2682
+
2683
+ # Verify if library is uninstalled.
2684
+ >>> conda_r_env.libs[conda_r_env.libs['name'].isin(['r-caret'])]
2685
+ name version
2686
+
2687
+ # Example 5: Uninstall libraries synchronously by creating requirement.txt file.
2688
+ # Create a requirement.txt file with below contents.
2689
+ -----------------------------------------------------------
2690
+ r-glm2
2691
+ r-anytime
2692
+ -----------------------------------------------------------
2693
+
2694
+ # Uninstall libraries specified in the file.
2695
+ >>> conda_r_env.uninstall_lib(libs_file_path="requirement.txt")
2696
+ Claim Id File/Libs Method Name Stage Timestamp Additional Details
2697
+ 0f3963a46-2225-412d-a470-17f26c759b42 requirement.txt install_lib Started 2024-12-27T08:52:28Z
2698
+ 0f3963a46-2225-412d-a470-17f26c759b42 requirement.txt install_lib Finished 2024-12-27T08:52:32Z
2699
+
2700
+ # Verify if libraries are uninstalled.
2701
+ >>> conda_r_env.libs[conda_r_env.libs['name'].isin(['r-glm2', 'r-anytime'])]
2702
+ name version
2703
+
2507
2704
  """
2508
2705
  asynchronous = kwargs.get("asynchronous", False)
2509
2706
  timeout = kwargs.get("timeout")
2510
- claim_id = self.__manage_libraries(libs, libs_file_path, "UNINSTALL", asynchronous, timeout)
2511
- return (claim_id)
2707
+ async_task_info = self.__manage_libraries(libs, libs_file_path, "UNINSTALL", asynchronous, timeout)
2708
+ return async_task_info
2512
2709
 
2513
2710
  @collect_queryband(queryband="UpdtLbs")
2514
2711
  def update_lib(self, libs=None, libs_file_path=None, **kwargs):
@@ -2523,7 +2720,10 @@ class UserEnv:
2523
2720
  packages have the same dependency as it messes pip's package resolution ability.
2524
2721
  * Use "update_lib" to update packages one at a time to prevent dependency resolution
2525
2722
  issues.
2526
-
2723
+ * For Conda R environment:
2724
+ * The library version cannot be specified. Conda only updates the installed packages to the
2725
+ latest compatible version and cannot update to a specific version.
2726
+ * The libraries should have "r-" prefix in the library name.
2527
2727
 
2528
2728
  PARAMETERS:
2529
2729
  libs:
@@ -2577,10 +2777,14 @@ class UserEnv:
2577
2777
  }]
2578
2778
  }
2579
2779
  * For conda environment:
2580
- The file should only contain the package names.
2581
- Library version cannot be specified. Conda only updates the
2582
- installed packages to the latest compatible version and
2583
- cannot update to a specific version.
2780
+ * The file should only contain the package names.
2781
+ Library version cannot be specified. Conda only updates the
2782
+ installed packages to the latest compatible version and
2783
+ cannot update to a specific version.
2784
+ * The file should have ".txt" extension for R environment.
2785
+ Sample text file content for R conda environment:
2786
+ r-glm2
2787
+ r-anytime
2584
2788
  Types: str
2585
2789
 
2586
2790
  **kwargs:
@@ -2881,12 +3085,55 @@ class UserEnv:
2881
3085
  45 stringi 1.1.5
2882
3086
  .. ... ...
2883
3087
  50 withr 2.5.0
2884
- >>>
3088
+
3089
+ # Example 9: Update Conda R libraries.
3090
+ # Create remote R conda user environment.
3091
+ >>> r_env = create_env('test_r_env', 'r_4.3', 'Test R environment', conda_env=True)
3092
+ Conda environment creation initiated
3093
+ User environment 'test_r_env' created.
3094
+
3095
+ # Install R libraries in environment.
3096
+ # Create a requirement.txt file with below contents.
3097
+ -----------------------------------------------------------
3098
+ r-glm2
3099
+ r-anytime
3100
+ r-ggplot2
3101
+ -----------------------------------------------------------
3102
+
3103
+ >>> r_env.install_lib(libs_file_path="requirement.txt")
3104
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
3105
+ 0 10afb2ae-8517-4858-8cf9-82bc54abd7ed requirement.txt install_lib Started 2024-12-17T07:17:26Z
3106
+ 1 10afb2ae-8517-4858-8cf9-82bc54abd7ed requirement.txt install_lib Finished 2024-12-17T07:21:06Z
3107
+
3108
+ # update the libraries in the environment through libs
3109
+ >>> r_env.update_lib(libs=["r-glm2", "r-anytime"])
3110
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
3111
+ 0 7106cb78-2dcf-4638-ab91-500fe8144787 libs.txt update_lib Started 2024-12-17T07:23:57Z
3112
+ 1 7106cb78-2dcf-4638-ab91-500fe8144787 libs.txt update_lib Finished 2024-12-17T07:24:11Z
3113
+
3114
+ # update the libraries in the environment through libs_file_path
3115
+ >>> r_env.update_lib(libs_file_path="requirement.txt")
3116
+ Claim Id File/Libs/Model Method Name Stage Timestamp Additional Details
3117
+ 0 6d6a3b3d-7b9d-4b0b-8f7f-1d1c7b4b3b5a requirement.txt update_lib Started 2024-12-17T07:25:35Z
3118
+ 1 6d6a3b3d-7b9d-4b0b-8f7f-1d1c7b4b3b5a requirement.txt update_lib Finished 2024-12-17T07:25:49Z
3119
+
3120
+ # Verify if libraries are updated.
3121
+ >>> r_env.libs
3122
+ name version
3123
+ 0 _libgcc_mutex 0.1
3124
+ 1 _openmp_mutex 5.1
3125
+ 2 _r-mutex 1.0.0
3126
+ ... ... ...
3127
+ 103 tzdata 2024b
3128
+ 104 wheel 0.44.0
3129
+ 105 xz 5.4.6
3130
+ 106 zlib 1.2.13
3131
+ 107 zstd 1.5.6
2885
3132
  """
2886
3133
  asynchronous = kwargs.get("asynchronous", False)
2887
3134
  timeout = kwargs.get("timeout")
2888
- claim_id = self.__manage_libraries(libs, libs_file_path, "UPDATE", asynchronous, timeout)
2889
- return (claim_id)
3135
+ async_task_info = self.__manage_libraries(libs, libs_file_path, "UPDATE", asynchronous, timeout)
3136
+ return async_task_info
2890
3137
 
2891
3138
  @collect_queryband(queryband="EnvRfrsh")
2892
3139
  def refresh(self):
@@ -3373,7 +3620,11 @@ class UserEnv:
3373
3620
  "File/Libs/Model": self.__claim_ids.get(claim_id, {}).get("value", "Unknown")}
3374
3621
 
3375
3622
  try:
3376
- response = UtilFuncs._http_request(_get_ues_url(env_type="fm", claim_id=claim_id, api_name="status"),
3623
+ # TODO: _get_status() from teradataml.scriptmgmt.lls_utils does similar job.
3624
+ # _get_status() can be reused.
3625
+ response = UtilFuncs._http_request(_get_ues_url(env_type="fm",
3626
+ claim_id=claim_id,
3627
+ api_name="status"),
3377
3628
  headers=_get_auth_token())
3378
3629
  data = _process_ues_response(api_name="status", response=response).json()
3379
3630
  # if claim_id is for install_file - 'data' looks as below:
@@ -3407,7 +3658,7 @@ class UserEnv:
3407
3658
 
3408
3659
  except Exception as e:
3409
3660
  # For any errors, construct a row with error reason in 'additional_details' column.
3410
- record = {"Additional Details": str(e), "Timestamp": None, "Stage": "Errored"}
3661
+ record = {"Additional Details": str(e), "Timestamp": None, "Stage": AsyncOpStatus.ERRED.value}
3411
3662
  record.update(claim_id_details)
3412
3663
  return [record]
3413
3664
 
@@ -3503,11 +3754,11 @@ class UserEnv:
3503
3754
  action = self.__claim_ids.get(claim_id, {}).get("action")
3504
3755
  if action in ["install_file", "install_model"]:
3505
3756
  for record in records:
3506
- if record["Stage"] in ["File Installed", "Errored"]:
3507
- if record["Stage"] == "File Installed":
3757
+ if record["Stage"] in [AsyncOpStatus.FILE_INSTALLED.value, AsyncOpStatus.ERRED.value]:
3758
+ if record["Stage"] == AsyncOpStatus.FILE_INSTALLED.value:
3508
3759
  print("Request for {} is {}.".format(action, "completed successfully"))
3509
- elif record["Stage"] == "errored":
3510
- print("Request for {} is {}.".format(action, "errored"))
3760
+ elif record["Stage"] == AsyncOpStatus.ERRED.value:
3761
+ print("Request for {} is {}.".format(action, AsyncOpStatus.ERRED.value))
3511
3762
  print("Check the status using status() with the claim id '{}'".format(claim_id))
3512
3763
  return records
3513
3764
  return False
@@ -3785,11 +4036,27 @@ class UserEnv:
3785
4036
 
3786
4037
  class _AuthToken:
3787
4038
  """
3788
- Internal class for storing details of Authentication Token.
4039
+ Internal class for storing details of authentication data to be used in headers.
3789
4040
  """
3790
- def __init__(self, token=None):
4041
+ def __init__(self, token, auth_type):
3791
4042
  self.__value = token
4043
+ self.__auth_type = auth_type
3792
4044
 
3793
4045
  @property
3794
4046
  def value(self):
3795
4047
  return self.__value
4048
+
4049
+ @property
4050
+ def auth_type(self):
4051
+ return self.__auth_type
4052
+
4053
+ def get_header(self):
4054
+ """
4055
+ Method for generating header using authentication data and type.
4056
+ """
4057
+ if self.auth_type.lower() == "basic":
4058
+ # Form the Authorization header value by prepending 'Basic ' to the encoded credentials string.
4059
+ return {"Authorization": "Basic {}".format(self.value)}
4060
+ elif self.auth_type.lower() == "bearer":
4061
+ # Form the Authorization header value by prepending 'Bearer ' to the JWT token.
4062
+ return {"Authorization": "Bearer {}".format(self.value)}