Skip to content

Commit fd640ab

Browse files
committed
Added doc and renamed args
1 parent c433576 commit fd640ab

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/stepfunctions/steps/sagemaker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,6 @@ class ProcessingStep(Task):
478478

479479
"""
480480
Creates a Task State to execute a SageMaker Processing Job.
481-
482-
The following properties can be passed down as kwargs to the sagemaker.processing.Processor to be used dynamically
483-
in the processing job (compatible with Placeholders): role, image_uri, instance_count, instance_type,
484-
volume_size_in_gb, volume_kms_key, output_kms_key
485481
"""
486482

487483
def __init__(self, state_id, processor, job_name, inputs=None, outputs=None, experiment_config=None,
@@ -507,7 +503,10 @@ def __init__(self, state_id, processor, job_name, inputs=None, outputs=None, exp
507503
The KmsKeyId is applied to all outputs.
508504
wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait for the processing job to complete before proceeding to the next step in the workflow. Set to `False` if the Task state should submit the processing job and proceed to the next step. (default: True)
509505
tags (list[dict] or Placeholder, optional): `List to tags <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_ to associate with the resource.
510-
parameters(dict, optional): The value of this field becomes the effective input for the state.
506+
parameters(dict, optional): The value of this field becomes the request for the
507+
`CreateProcessingJob<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateProcessingJob.html>`_ created by the processing step.
508+
All parameters fields are compatible with `Placeholders<https://aws-step-functions-data-science-sdk.readthedocs.io/en/stable/placeholders.html?highlight=placeholder#stepfunctions.inputs.Placeholder>`_.
509+
Any value defined in the parameters argument will overwrite the ones defined in the other arguments, including properties that were previously defined in the processor.
511510
"""
512511
if wait_for_completion:
513512
"""

src/stepfunctions/steps/utils.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,28 @@ def get_aws_partition():
4848
return cur_partition
4949

5050

51-
def merge_dicts(first, second, first_name, second_name):
51+
def merge_dicts(target, source, target_name, source_name):
5252
"""
53-
Merges first and second dictionaries into the first one.
54-
Values in the first dict are updated with the values of the second one.
53+
Merges source dictionary into the target dictionary.
54+
Values in the target dict are updated with the values of the source dict.
55+
Args:
56+
target (dict): Base dictionary into which source is merged
57+
source (dict): Dictionary used to update target. If the same key is present in both dictionaries, source's value
58+
will overwrite target's value for the corresponding key
59+
target_name (str): Name of target dictionary used for logging purposes
60+
source_name (str): Name of source dictionary used for logging purposes
5561
"""
56-
if all(isinstance(d, dict) for d in [first, second]):
57-
for key, value in second.items():
58-
if key in first:
59-
if isinstance(first[key], dict) and isinstance(second[key], dict):
60-
merge_dicts(first[key], second[key], first_name, second_name)
61-
elif first[key] == value:
62+
if isinstance(target, dict) and isinstance(source, dict):
63+
for key, value in source.items():
64+
if key in target:
65+
if isinstance(target[key], dict) and isinstance(source[key], dict):
66+
merge_dicts(target[key], source[key], target_name, source_name)
67+
elif target[key] == value:
6268
pass
6369
else:
6470
logger.info(
65-
f"{first_name} property: <{key}> with value: <{first[key]}>"
66-
f" will be overwritten with value provided in {second_name} : <{value}>")
67-
first[key] = second[key]
71+
f"{target_name} property: <{key}> with value: <{target[key]}>"
72+
f" will be overwritten with value provided in {source_name} : <{value}>")
73+
target[key] = source[key]
6874
else:
69-
first[key] = second[key]
75+
target[key] = source[key]

tests/unit/test_steps_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Test if boto3 session can fetch correct aws partition info from test environment
1515

16-
from stepfunctions.steps.utils import get_aws_partition
16+
from stepfunctions.steps.utils import get_aws_partition, merge_dicts
1717
from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn
1818
import boto3
1919
from unittest.mock import patch
@@ -51,3 +51,10 @@ def test_arn_builder_sagemaker_wait_completion():
5151
IntegrationPattern.WaitForCompletion)
5252
assert arn == "arn:aws:states:::sagemaker:createTrainingJob.sync"
5353

54+
55+
def test_merge_dicts():
56+
d1 = {'a': {'aa': 1, 'bb': 2, 'cc': 3}, 'b': 1}
57+
d2 = {'a': {'bb': {'aaa': 1, 'bbb': 2}}, 'b': 2, 'c': 3}
58+
59+
merge_dicts(d1, d2, 'd1', 'd2')
60+
assert d1 == {'a': {'aa': 1, 'bb': {'aaa': 1, 'bbb': 2}, 'cc': 3}, 'b': 2, 'c': 3}

0 commit comments

Comments
 (0)