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