ashb commented on code in PR #28837:
URL: https://github.com/apache/airflow/pull/28837#discussion_r1066886052
##########
airflow/providers/amazon/aws/operators/sagemaker.py:
##########
@@ -1049,3 +1050,54 @@ def execute(self, context: Context) -> dict | None:
self.check_interval,
)
return best
+
+
+class SageMakerCreateExperimentOperator(SageMakerBaseOperator):
+ """
+ Creates a SageMaker experiment, to be then associated to jobs etc.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:SageMakerCreateExperimentOperator`
+
+ :param name: name of the experiment, must be unique within the AWS account
+ :param description: description of the experiment, optional
+ :param tags: tags to attach to the experiment, optional
+
+ :returns: the ARN of the experiment created, though experiments are
referred to by name
+ """
+
+ template_fields: Sequence[str] = (
+ "name",
+ "description",
+ "tags",
+ )
+
+ def __init__(
+ self,
+ *,
+ name: str,
+ description: str | None = None,
+ tags: dict | None = None,
+ aws_conn_id: str = DEFAULT_CONN_ID,
+ **kwargs,
+ ):
+ super().__init__(config={}, aws_conn_id=aws_conn_id, **kwargs)
+ self.name = name
+ self.description = description
+ if tags:
+ self.tags_set = [{"Key": kvp[0], "Value": kvp[1]} for kvp in
tags.items()]
+ else:
+ self.tags_set = []
Review Comment:
Yup, this'll need fixing (and in your other PR too) to do the "formatting"
in execute() instead.
##########
tests/providers/amazon/aws/operators/test_sagemaker_base.py:
##########
@@ -40,3 +45,19 @@ def test_default_integer_fields(self):
self.sagemaker.preprocess_config()
assert self.sagemaker.integer_fields == EXPECTED_INTEGER_FIELDS
+
+
+class TestSageMakerExperimentOperator:
+ @patch("airflow.providers.amazon.aws.hooks.sagemaker.SageMakerHook.conn",
new_callable=mock.PropertyMock)
+ def test_create_experiment(self, conn_mock):
+ conn_mock().create_experiment.return_value = {"ExperimentArn":
"abcdef"}
+
+ op = SageMakerCreateExperimentOperator(
+ name="the name", description="the desc", tags={"the": "tags"},
task_id="whatever"
Review Comment:
```suggestion
name="the name", description="the desc", tags={"the": "{{
task.task_id }}"}, task_id="whatever"
```
##########
tests/providers/amazon/aws/operators/test_sagemaker_base.py:
##########
@@ -40,3 +45,19 @@ def test_default_integer_fields(self):
self.sagemaker.preprocess_config()
assert self.sagemaker.integer_fields == EXPECTED_INTEGER_FIELDS
+
+
+class TestSageMakerExperimentOperator:
+ @patch("airflow.providers.amazon.aws.hooks.sagemaker.SageMakerHook.conn",
new_callable=mock.PropertyMock)
+ def test_create_experiment(self, conn_mock):
+ conn_mock().create_experiment.return_value = {"ExperimentArn":
"abcdef"}
+
+ op = SageMakerCreateExperimentOperator(
+ name="the name", description="the desc", tags={"the": "tags"},
task_id="whatever"
+ )
+ ret = op.execute(None)
+
+ assert ret == "abcdef"
+ conn_mock().create_experiment.assert_called_once_with(
+ ExperimentName="the name", Description="the desc", Tags=[{"Key":
"the", "Value": "tags"}]
Review Comment:
```suggestion
ExperimentName="the name", Description="the desc", Tags=[{"Key":
"the", "Value": "the name"}]
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]