Skip to content

fix: set logs to False if wait is False #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 17, 2020
16 changes: 9 additions & 7 deletions src/sagemaker/automl/automl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""A class for SageMaker AutoML Jobs."""
from __future__ import absolute_import

import logging
from six import string_types

from sagemaker import Model, PipelineModel
Expand All @@ -21,6 +22,8 @@
from sagemaker.session import Session
from sagemaker.utils import name_from_base

logger = logging.getLogger("sagemaker")


class AutoML(object):
"""A class for creating and interacting with SageMaker AutoML jobs
Expand Down Expand Up @@ -78,16 +81,15 @@ def fit(self, inputs=None, wait=True, logs=True, job_name=None):
is stored. Or an AutoMLInput object. If a local path is provided, the dataset will
be uploaded to an S3 location.
wait (bool): Whether the call should wait until the job completes (default: True).
logs (bool): Whether to show the logs produced by the job.
Only meaningful when wait is True (default: True).
logs (bool): Whether to show the logs produced by the job. Only meaningful when wait
is True (default: True). if ``wait`` is False, ``logs`` will be set to False as
well.
job_name (str): Training job name. If not specified, the estimator generates
a default job name, based on the training image name and current timestamp.
"""
if logs and not wait:
raise ValueError(
"""Logs can only be shown if wait is set to True.
Please either set wait to True or set logs to False."""
)
if not wait and logs:
logs = False
logger.warning("Setting logs to False. logs is only meaningful when wait is True.")

# upload data for users if provided local path
# validations are done in _Job._format_inputs_to_input_config
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/sagemaker/automl/test_auto_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ def test_auto_ml_only_one_of_problem_type_and_job_objective_provided(sagemaker_s
)


@patch("sagemaker.automl.automl.AutoMLJob.start_new")
def test_auto_ml_fit_set_logs_to_false(start_new, sagemaker_session, caplog):
auto_ml = AutoML(
role=ROLE, target_attribute_name=TARGET_ATTRIBUTE_NAME, sagemaker_session=sagemaker_session
)
inputs = DEFAULT_S3_INPUT_DATA
auto_ml.fit(inputs, job_name=JOB_NAME, wait=False, logs=True)
start_new.wait.assert_not_called()
assert "Setting logs to False. logs is only meaningful when wait is True." in caplog.text


def test_auto_ml_additional_optional_params(sagemaker_session):
auto_ml = AutoML(
role=ROLE,
Expand Down