Skip to content

Commit e5d764d

Browse files
authored
Merge branch 'master' into v2-doc-typo
2 parents 141c1fd + e442ac8 commit e5d764d

File tree

20 files changed

+180
-103
lines changed

20 files changed

+180
-103
lines changed

.pydocstylerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pydocstyle]
2+
inherit = false
3+
ignore = D104,D107,D202,D203,D205,D209,D212,D213,D214,D400,D401,D404,D406,D407,D411,D413,D414,D415,D417
4+
match = (?!record_pb2).*\.py

src/sagemaker/amazon/randomcutforest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def __init__(
5757
eval_metrics=None,
5858
**kwargs
5959
):
60-
"""RandomCutForest is :class:`Estimator` used for anomaly detection.
60+
"""An `Estimator` class implementing a Random Cut Forest.
6161
62-
This Estimator may be fit via calls to
62+
Typically used for anomaly detection, this Estimator may be fit via calls to
6363
:meth:`~sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase.fit`.
6464
It requires Amazon :class:`~sagemaker.amazon.record_pb2.Record` protobuf
6565
serialized data to be stored in S3. There is an utility

src/sagemaker/analytics.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def name(self):
108108
return self._tuning_job_name
109109

110110
def __repr__(self):
111+
"""Human-readable representation override."""
111112
return "<sagemaker.HyperparameterTuningJobAnalytics for %s>" % self.name
112113

113114
def clear_cache(self):
@@ -117,9 +118,10 @@ def clear_cache(self):
117118
self._training_job_summaries = None
118119

119120
def _fetch_dataframe(self):
120-
"""Return a pandas dataframe with all the training jobs, along with
121-
their hyperparameters, results, and metadata. This also includes a
122-
column to indicate if a training job was the best seen so far.
121+
"""Return a pandas dataframe with all the training jobs.
122+
123+
This includes their hyperparameters, results, and metadata, as well as
124+
a column to indicate if a training job was the best seen so far.
123125
"""
124126

125127
def reshape(training_summary):
@@ -320,20 +322,27 @@ def name(self):
320322
return self._training_job_name
321323

322324
def __repr__(self):
325+
"""The human-readable representation override."""
323326
return "<sagemaker.TrainingJobAnalytics for %s>" % self.name
324327

325328
def clear_cache(self):
326-
"""Clear the object of all local caches of API methods, so that the next
327-
time any properties are accessed they will be refreshed from the
328-
service.
329+
"""Clear the object of all local caches of API methods.
330+
331+
This is so that the next time any properties are accessed they will be
332+
refreshed from the service.
329333
"""
330334
super(TrainingJobAnalytics, self).clear_cache()
331335
self._data = defaultdict(list)
332336
self._time_interval = self._determine_timeinterval()
333337

334338
def _determine_timeinterval(self):
335-
"""Return a dictionary with two datetime objects, start_time and
336-
end_time, covering the interval of the training job
339+
"""Return a dict with two datetime objects.
340+
341+
The dict includes the `start_time` and `end_time`, covering the interval
342+
of the training job.
343+
344+
Returns:
345+
a dict with the `start_time` and `end_time`.
337346
"""
338347
description = self._sage_client.describe_training_job(TrainingJobName=self.name)
339348
start_time = self._start_time or description[u"TrainingStartTime"] # datetime object
@@ -359,7 +368,7 @@ def _fetch_metric(self, metric_name):
359368
"""Fetch all the values of a named metric, and add them to _data
360369
361370
Args:
362-
metric_name:
371+
metric_name: The metric name to fetch.
363372
"""
364373
request = {
365374
"Namespace": self.CLOUDWATCH_NAMESPACE,
@@ -389,13 +398,14 @@ def _fetch_metric(self, metric_name):
389398
self._add_single_metric(elapsed_seconds, metric_name, value)
390399

391400
def _add_single_metric(self, timestamp, metric_name, value):
392-
"""Store a single metric in the _data dict which can be converted to a
393-
dataframe.
401+
"""Store a single metric in the _data dict.
402+
403+
This can be converted to a dataframe.
394404
395405
Args:
396-
timestamp:
397-
metric_name:
398-
value:
406+
timestamp: The timestamp of the metric.
407+
metric_name: The name of the metric.
408+
value: The value of the metric.
399409
"""
400410
# note that this method is built this way to make it possible to
401411
# support live-refreshing charts in Bokeh at some point in the future.
@@ -480,6 +490,7 @@ def name(self):
480490
return self._experiment_name
481491

482492
def __repr__(self):
493+
"""The human-readable representation override."""
483494
return "<sagemaker.ExperimentAnalytics for %s>" % self.name
484495

485496
def clear_cache(self):

src/sagemaker/automl/automl.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def best_candidate(self, job_name=None):
183183
Args:
184184
job_name (str): The name of the AutoML job. If None, will use object's
185185
_current_auto_ml_job_name.
186+
186187
Returns:
187188
dict: a dictionary with information of the best candidate
188189
"""
@@ -226,6 +227,7 @@ def list_candidates(
226227
Default to None.
227228
max_results (int): The number of candidates will be listed in results,
228229
between 1 to 100. Default to None. If None, will return all the candidates.
230+
229231
Returns:
230232
list: A list of dictionaries with candidates information
231233
"""
@@ -288,7 +290,6 @@ def create_model(
288290
289291
Returns:
290292
PipelineModel object
291-
292293
"""
293294
sagemaker_session = sagemaker_session or self.sagemaker_session
294295

@@ -434,7 +435,6 @@ def _check_problem_type_and_job_objective(self, problem_type, job_objective):
434435
435436
Raises (ValueError): raises ValueError if one of problem_type and job_objective is provided
436437
while the other is None.
437-
438438
"""
439439
if not (problem_type and job_objective) and (problem_type or job_objective):
440440
raise ValueError(
@@ -500,7 +500,6 @@ def _check_inference_keys(cls, inference_response_keys, containers):
500500
Raises:
501501
ValueError, if one or more keys in inference_response_keys are not supported
502502
the inference pipeline.
503-
504503
"""
505504
if not inference_response_keys:
506505
return
@@ -537,7 +536,6 @@ def validate_and_update_inference_response(cls, inference_containers, inference_
537536
538537
Raises:
539538
ValueError: if one or more of inference_response_keys are unsupported by the model
540-
541539
"""
542540
if not inference_response_keys:
543541
return
@@ -704,12 +702,11 @@ def _format_inputs_to_input_config(
704702
Args:
705703
inputs (str, list[str]): local path(s) or S3 uri(s) of input datasets.
706704
validate_uri (bool): indicates whether it is needed to validate S3 uri.
707-
compression (str):
705+
compression (str): Compression type of the input data.
708706
target_attribute_name (str): the target attribute name for classification
709707
or regression.
710708
711709
Returns (dict): a dict of AutoML InputDataConfig
712-
713710
"""
714711
if inputs is None:
715712
return None
@@ -758,7 +755,6 @@ def _prepare_auto_ml_stop_condition(
758755
total_job_runtime_in_seconds (int): the total wait time of an AutoML job.
759756
760757
Returns (dict): an AutoML CompletionCriteria.
761-
762758
"""
763759
stopping_condition = {"MaxCandidates": max_candidates}
764760

@@ -777,6 +773,7 @@ def describe(self):
777773

778774
def wait(self, logs=True):
779775
"""Wait for the AutoML job to finish.
776+
780777
Args:
781778
logs (bool): indicate whether to output logs.
782779
"""

src/sagemaker/cli/compatibility/v2/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def _update_code_from_cell(self, cell):
164164
return self._code_str_to_source_list(updated_code)
165165

166166
def _code_str_to_source_list(self, code):
167-
"""Converts a string of code into a list for a Jupyter notebook code cell.
167+
r"""Converts a string of code into a list for a Jupyter notebook code cell.
168168
169169
Args:
170170
code (str): Code to be converted.

src/sagemaker/cli/compatibility/v2/modifiers/training_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def modify_node(self, node):
6060

6161

6262
def _rename_namespace(node, name):
63-
"""Rename namespace ``session`` to ``inputs`` """
63+
"""Rename namespace ``session`` to ``inputs``."""
6464
if isinstance(node.func.value, ast.Attribute) and node.func.value.attr == name:
6565
node.func.value.attr = "inputs"
6666
elif isinstance(node.func.value, ast.Name) and node.func.value.id == name:

src/sagemaker/debugger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ def __init__(self, name, parameters=None):
365365
self.parameters = parameters
366366

367367
def __eq__(self, other):
368+
"""Equals method override.
369+
370+
Args:
371+
other: Object to test equality against.
372+
"""
368373
if not isinstance(other, CollectionConfig):
369374
raise TypeError(
370375
"CollectionConfig is only comparable with other CollectionConfig objects."
@@ -373,6 +378,11 @@ def __eq__(self, other):
373378
return self.name == other.name and self.parameters == other.parameters
374379

375380
def __ne__(self, other):
381+
"""Not-equals method override.
382+
383+
Args:
384+
other: Object to test equality against.
385+
"""
376386
if not isinstance(other, CollectionConfig):
377387
raise TypeError(
378388
"CollectionConfig is only comparable with other CollectionConfig objects."
@@ -381,6 +391,7 @@ def __ne__(self, other):
381391
return self.name != other.name or self.parameters != other.parameters
382392

383393
def __hash__(self):
394+
"""Hash method override."""
384395
return hash((self.name, tuple(sorted((self.parameters or {}).items()))))
385396

386397
def _to_request_dict(self):

src/sagemaker/estimator.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,8 +1489,9 @@ def __init__(
14891489
enable_sagemaker_metrics=None,
14901490
**kwargs
14911491
):
1492-
"""Base class initializer. Subclasses which override ``__init__`` should
1493-
invoke ``super()``
1492+
"""Base class initializer.
1493+
1494+
Subclasses which override ``__init__`` should invoke ``super()``.
14941495
14951496
Args:
14961497
entry_point (str): Path (absolute or relative) to the local Python
@@ -1499,8 +1500,8 @@ def __init__(
14991500
must point to a file located at the root of ``source_dir``.
15001501
If 'git_config' is provided, 'entry_point' should be
15011502
a relative location to the Python source file in the Git repo.
1502-
Example:
15031503
1504+
Example:
15041505
With the following GitHub repo directory structure:
15051506
15061507
>>> |----- README.md
@@ -1729,9 +1730,7 @@ def _prepare_for_training(self, job_name=None):
17291730
self._validate_and_set_debugger_configs()
17301731

17311732
def _validate_and_set_debugger_configs(self):
1732-
"""
1733-
Set defaults for debugging
1734-
"""
1733+
"""Set defaults for debugging."""
17351734
if self.debugger_hook_config is None and _region_supports_debugger(
17361735
self.sagemaker_session.boto_region_name
17371736
):

src/sagemaker/git_utils.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222

2323

2424
def git_clone_repo(git_config, entry_point, source_dir=None, dependencies=None):
25-
"""Git clone repo containing the training code and serving code. This method
26-
also validate ``git_config``, and set ``entry_point``, ``source_dir`` and
27-
``dependencies`` to the right file or directory in the repo cloned.
25+
"""Git clone repo containing the training code and serving code.
26+
27+
This method also validate ``git_config``, and set ``entry_point``,
28+
``source_dir`` and ``dependencies`` to the right file or directory in the
29+
repo cloned.
2830
2931
Args:
3032
git_config (dict[str, str]): Git configurations used for cloning files,
@@ -118,9 +120,13 @@ def git_clone_repo(git_config, entry_point, source_dir=None, dependencies=None):
118120

119121

120122
def _validate_git_config(git_config):
121-
"""
123+
"""Validates the git configuration.
124+
125+
Checks all configuration values except 2FA_enabled are string types. The
126+
2FA_enabled configuration should be a boolean.
127+
122128
Args:
123-
git_config:
129+
git_config: The configuration to validate.
124130
"""
125131
if "repo" not in git_config:
126132
raise ValueError("Please provide a repo for git_config.")
@@ -133,8 +139,9 @@ def _validate_git_config(git_config):
133139

134140

135141
def _generate_and_run_clone_command(git_config, dest_dir):
136-
"""check if a git_config param is valid, if it is, create the command to git
137-
clone the repo, and run it.
142+
"""Check if a git_config param is valid.
143+
144+
If it is valid, create the command to git, clone the repo, and run it.
138145
139146
Args:
140147
git_config ((dict[str, str]): Git configurations used for cloning files,
@@ -153,8 +160,9 @@ def _generate_and_run_clone_command(git_config, dest_dir):
153160

154161

155162
def _clone_command_for_github_like(git_config, dest_dir):
156-
"""check if a git_config param representing a GitHub (or like) repo is
157-
valid, if it is, create the command to git clone the repo, and run it.
163+
"""Check if a git_config param representing a GitHub (or like) repo is valid.
164+
165+
If it is valid, create the command to git clone the repo, and run it.
158166
159167
Args:
160168
git_config ((dict[str, str]): Git configurations used for cloning files,
@@ -223,8 +231,9 @@ def _clone_command_for_github_like_https_2fa_enabled(git_config, dest_dir):
223231

224232

225233
def _clone_command_for_codecommit(git_config, dest_dir):
226-
"""check if a git_config param representing a CodeCommit repo is valid, if
227-
it is, create the command to git clone the repo, and run it.
234+
"""Check if a git_config param representing a CodeCommit repo is valid.
235+
236+
If it is, create the command to git clone the repo, and run it.
228237
229238
Args:
230239
git_config ((dict[str, str]): Git configurations used for cloning files,
@@ -250,10 +259,11 @@ def _clone_command_for_codecommit(git_config, dest_dir):
250259

251260

252261
def _clone_command_for_codecommit_https(git_config, dest_dir):
253-
"""
262+
"""Invoke the clone command for codecommit.
263+
254264
Args:
255-
git_config:
256-
dest_dir:
265+
git_config: The git configuration.
266+
dest_dir: The destination directory for the clone.
257267
"""
258268
updated_url = git_config["repo"]
259269
if "username" in git_config and "password" in git_config:

src/sagemaker/local/data.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def split(self, filename):
237237
filename (str): path to the file to split
238238
239239
Returns: generator for the individual records that were split from
240-
the file
240+
the file
241241
"""
242242
with open(filename, "rb") as f:
243243
buf = f.read()
@@ -246,15 +246,15 @@ def split(self, filename):
246246
yield buf
247247

248248
def _is_binary(self, buf):
249-
"""binary check.
250-
Check whether `buf` contains binary data.
251-
Returns true if `buf` contains any non-utf-8 characters.
249+
"""Check whether `buf` contains binary data.
250+
251+
Returns True if `buf` contains any non-utf-8 characters.
252252
253253
Args:
254-
buf (bytes): data to inspect
254+
buf (bytes): data to inspect
255255
256256
Returns:
257-
True if data is binary, otherwise False
257+
True if data is binary, otherwise False
258258
"""
259259
return bool(buf.translate(None, self._textchars))
260260

@@ -398,8 +398,9 @@ def _payload_size_within_limit(payload, size):
398398

399399

400400
def _validate_payload_size(payload, size):
401-
"""Check if a payload is within the size in MB threshold. Raise an exception
402-
otherwise.
401+
"""Check if a payload is within the size in MB threshold.
402+
403+
Raise an exception if the payload is beyond the size in MB threshold.
403404
404405
Args:
405406
payload: data that will be checked

0 commit comments

Comments
 (0)