Skip to content

Commit 263594a

Browse files
Balaji SankarRuban Hussain
authored andcommitted
fix: Added additional test cases for config helper methods. Also made minor documentation updates.
1 parent 1ec0563 commit 263594a

File tree

2 files changed

+78
-11
lines changed

2 files changed

+78
-11
lines changed

src/sagemaker/config/config.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,20 @@
5252

5353

5454
class SageMakerConfig(object):
55-
"""SageMakerConfig class encapsulates the Config for SageMaker Python SDK.
55+
"""A class that encapsulates the configuration for the SageMaker Python SDK.
5656
57-
Usages:
58-
This class will be integrated with sagemaker.session.Session. Users of SageMaker Python SDK
59-
will have the ability to pass a SageMakerConfig object to sagemaker.session.Session. If
60-
SageMakerConfig object is not provided by the user, then sagemaker.session.Session will
61-
create its own SageMakerConfig object.
57+
This class is used to define default values provided by the user.
6258
63-
Note: Once sagemaker.session.Session is initialized, it will operate with the configuration
64-
values at that instant. If the users wish to alter config files/file paths after
65-
sagemaker.session.Session is initialized, then that will not be reflected in
66-
sagemaker.session.Session. They would have to re-initialize sagemaker.session.Session to
67-
pick the latest changes.
59+
This class is integrated with sagemaker.session.Session. Users of the SageMaker Python SDK
60+
have the ability to pass a SageMakerConfig object to sagemaker.session.Session. If a
61+
SageMakerConfig object is not provided by the user, then sagemaker.session.Session
62+
creates its own SageMakerConfig object.
6863
64+
Note: After sagemaker.session.Session is initialized, it operates with the configuration
65+
values defined at that instant. If you modify the configuration files or file paths after
66+
sagemaker.session.Session is initialized, those changes are not reflected in
67+
sagemaker.session.Session. To incorporate the changes in the configuration files,
68+
initialize sagemaker.session.Session again.
6969
"""
7070

7171
def __init__(self, additional_config_paths: List[str] = None, s3_resource=_DEFAULT_S3_RESOURCE):

tests/unit/test_utils.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,73 @@ def test_update_list_of_dicts_with_values_from_config():
226226
{"a": 1, "b": 2, "c": 3},
227227
{"a": 5, "c": 6, "d": 8},
228228
]
229+
# Same happy case with different order of items in union_key_paths
230+
input_list = [{"a": 1, "b": 2}, {"a": 5, "c": 6}]
231+
input_config_list = [
232+
{
233+
"a": 4, # This should not be used. Use values from Input.
234+
"c": 3,
235+
},
236+
{
237+
"a": 7, # This should not be used. Use values from Input.
238+
"d": 8,
239+
},
240+
]
241+
ss.sagemaker_config.config = {"DUMMY": {"CONFIG": {"PATH": input_config_list}}}
242+
update_list_of_dicts_with_values_from_config(
243+
input_list, config_path, union_key_paths=[["d", "e"], ["c", "e"]], sagemaker_session=ss
244+
)
245+
assert input_list == [
246+
{"a": 1, "b": 2, "c": 3},
247+
{"a": 5, "c": 6, "d": 8},
248+
]
249+
# Testing the combination of union parameter and required parameter. i.e. A parameter is both
250+
# required and part of Union.
251+
input_list = [{"a": 1, "b": 2}, {"a": 5, "c": 6}]
252+
input_config_list = [
253+
{
254+
"a": 4, # This should not be used. Use values from Input.
255+
"c": 3,
256+
},
257+
{
258+
"a": 7, # This should not be used. Use values from Input.
259+
"d": 8,
260+
},
261+
]
262+
ss.sagemaker_config.config = {"DUMMY": {"CONFIG": {"PATH": input_config_list}}}
263+
update_list_of_dicts_with_values_from_config(
264+
input_list,
265+
config_path,
266+
required_key_paths=["e"],
267+
union_key_paths=[["d", "e"], ["c", "e"]],
268+
sagemaker_session=ss,
269+
)
270+
# No merge should happen since 'e' is not present, even though union is obeyed.
271+
assert input_list == [{"a": 1, "b": 2}, {"a": 5, "c": 6}]
272+
# Same test but the required parameter is present.
273+
input_list = [{"a": 1, "e": 2}, {"a": 5, "e": 6}]
274+
input_config_list = [
275+
{
276+
"a": 4, # This should not be used. Use values from Input.
277+
"f": 3,
278+
},
279+
{
280+
"a": 7, # This should not be used. Use values from Input.
281+
"g": 8,
282+
},
283+
]
284+
ss.sagemaker_config.config = {"DUMMY": {"CONFIG": {"PATH": input_config_list}}}
285+
update_list_of_dicts_with_values_from_config(
286+
input_list,
287+
config_path,
288+
required_key_paths=["e"],
289+
union_key_paths=[["d", "e"], ["c", "e"]],
290+
sagemaker_session=ss,
291+
)
292+
assert input_list == [
293+
{"a": 1, "e": 2, "f": 3},
294+
{"a": 5, "e": 6, "g": 8},
295+
]
229296

230297

231298
def test_set_nested_value():

0 commit comments

Comments
 (0)