Skip to content

Commit c49aafe

Browse files
committed
doc: modified docstrings to comply with PEP257 standards
1 parent 2fa95f5 commit c49aafe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+680
-1027
lines changed

.pydocstylerc

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

src/sagemaker/algorithm.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626

2727
class AlgorithmEstimator(EstimatorBase):
28-
"""A generic Estimator to train using any algorithm object (with an
29-
``algorithm_arn``). The Algorithm can be your own, or any Algorithm from AWS
28+
"""A generic Estimator to train using any algorithm object (with an ``algorithm_arn``).
29+
30+
The Algorithm can be your own, or any Algorithm from AWS
3031
Marketplace that you have a valid subscription for. This class will perform
3132
client-side validation on all the inputs.
3233
"""
@@ -212,10 +213,7 @@ def validate_train_spec(self):
212213
)
213214

214215
def set_hyperparameters(self, **kwargs):
215-
"""
216-
Args:
217-
**kwargs:
218-
"""
216+
"""Placeholder docstring"""
219217
for k, v in kwargs.items():
220218
value = self._validate_and_cast_hyperparameter(k, v)
221219
self.hyperparam_dict[k] = value
@@ -330,9 +328,9 @@ def transformer(
330328
role=None,
331329
volume_kms_key=None,
332330
):
333-
"""Return a ``Transformer`` that uses a SageMaker Model based on the
334-
training job. It reuses the SageMaker Session and base job name used by
335-
the Estimator.
331+
"""Return a ``Transformer`` that uses a SageMaker Model based on the training job.
332+
333+
It reuses the SageMaker Session and base job name used by the Estimator.
336334
337335
Args:
338336
instance_count (int): Number of EC2 instances to use.
@@ -413,32 +411,18 @@ def _prepare_for_training(self, job_name=None):
413411
# Validate hyperparameters
414412
# an explicit call to set_hyperparameters() will also validate the hyperparameters
415413
# but it is possible that the user never called it.
416-
"""
417-
Args:
418-
job_name:
419-
"""
420414
self._validate_and_set_default_hyperparameters()
421415

422416
super(AlgorithmEstimator, self)._prepare_for_training(job_name)
423417

424418
def fit(self, inputs=None, wait=True, logs=True, job_name=None):
425-
"""
426-
Args:
427-
inputs:
428-
wait:
429-
logs:
430-
job_name:
431-
"""
419+
"""Placeholder docstring"""
432420
if inputs:
433421
self._validate_input_channels(inputs)
434422

435423
super(AlgorithmEstimator, self).fit(inputs, wait, logs, job_name)
436424

437425
def _validate_input_channels(self, channels):
438-
"""
439-
Args:
440-
channels:
441-
"""
442426
train_spec = self.algorithm_spec["TrainingSpecification"]
443427
algorithm_name = self.algorithm_spec["AlgorithmName"]
444428
training_channels = {c["Name"]: c for c in train_spec["TrainingChannels"]}
@@ -456,11 +440,6 @@ def _validate_input_channels(self, channels):
456440
raise ValueError("Required input channel: %s Was not provided." % (name))
457441

458442
def _validate_and_cast_hyperparameter(self, name, v):
459-
"""
460-
Args:
461-
name:
462-
v:
463-
"""
464443
algorithm_name = self.algorithm_spec["AlgorithmName"]
465444

466445
if name not in self.hyperparameter_definitions:
@@ -514,11 +493,6 @@ def _parse_hyperparameters(self):
514493
return definitions
515494

516495
def _hyperparameter_range_and_class(self, parameter_type, hyperparameter):
517-
"""
518-
Args:
519-
parameter_type:
520-
hyperparameter:
521-
"""
522496
if parameter_type in self._hyperpameters_with_range:
523497
range_name = parameter_type + "ParameterRangeSpecification"
524498

@@ -559,10 +533,6 @@ def _hyperparameter_range_and_class(self, parameter_type, hyperparameter):
559533
return parameter_class, parameter_range
560534

561535
def _algorithm_training_input_modes(self, training_channels):
562-
"""
563-
Args:
564-
training_channels:
565-
"""
566536
current_input_modes = {"File", "Pipe"}
567537
for channel in training_channels:
568538
supported_input_modes = set(channel["SupportedInputModes"])
@@ -572,8 +542,7 @@ def _algorithm_training_input_modes(self, training_channels):
572542

573543
@classmethod
574544
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):
575-
"""Convert the job description to init params that can be handled by the
576-
class constructor
545+
"""Convert the job description to init params that can be handled by the class constructor.
577546
578547
Args:
579548
job_details (dict): the returned job details from a DescribeTrainingJob

src/sagemaker/amazon/common.py

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ def deserialize(self, data, content_type):
9292

9393

9494
def _write_feature_tensor(resolved_type, record, vector):
95-
"""
96-
Args:
97-
resolved_type:
98-
record:
99-
vector:
100-
"""
95+
"""Placeholder Docstring"""
10196
if resolved_type == "Int32":
10297
record.features["values"].int32_tensor.values.extend(vector)
10398
elif resolved_type == "Float64":
@@ -107,12 +102,7 @@ def _write_feature_tensor(resolved_type, record, vector):
107102

108103

109104
def _write_label_tensor(resolved_type, record, scalar):
110-
"""
111-
Args:
112-
resolved_type:
113-
record:
114-
scalar:
115-
"""
105+
"""Placeholder Docstring"""
116106
if resolved_type == "Int32":
117107
record.label["values"].int32_tensor.values.extend([scalar])
118108
elif resolved_type == "Float64":
@@ -122,12 +112,7 @@ def _write_label_tensor(resolved_type, record, scalar):
122112

123113

124114
def _write_keys_tensor(resolved_type, record, vector):
125-
"""
126-
Args:
127-
resolved_type:
128-
record:
129-
vector:
130-
"""
115+
"""Placeholder Docstring"""
131116
if resolved_type == "Int32":
132117
record.features["values"].int32_tensor.keys.extend(vector)
133118
elif resolved_type == "Float64":
@@ -137,12 +122,7 @@ def _write_keys_tensor(resolved_type, record, vector):
137122

138123

139124
def _write_shape(resolved_type, record, scalar):
140-
"""
141-
Args:
142-
resolved_type:
143-
record:
144-
scalar:
145-
"""
125+
"""Placeholder Docstring"""
146126
if resolved_type == "Int32":
147127
record.features["values"].int32_tensor.shape.extend([scalar])
148128
elif resolved_type == "Float64":
@@ -285,10 +265,7 @@ def _write_recordio(f, data):
285265

286266

287267
def read_recordio(f):
288-
"""
289-
Args:
290-
f:
291-
"""
268+
"""Placeholder Docstring"""
292269
while True:
293270
try:
294271
(read_kmagic,) = struct.unpack("I", f.read(4))
@@ -303,10 +280,7 @@ def read_recordio(f):
303280

304281

305282
def _resolve_type(dtype):
306-
"""
307-
Args:
308-
dtype:
309-
"""
283+
"""Placeholder Docstring"""
310284
if dtype == np.dtype(int):
311285
return "Int32"
312286
if dtype == np.dtype(float):

src/sagemaker/amazon/factorization_machines.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ def __init__(
112112
factors_init_value=None,
113113
**kwargs
114114
):
115-
"""Factorization Machines is :class:`Estimator` for general-purpose
116-
supervised learning.
115+
"""Factorization Machines is :class:`Estimator` for general-purpose supervised learning.
117116
118117
Amazon SageMaker Factorization Machines is a general-purpose
119118
supervised learning algorithm that you can use for both classification
@@ -247,8 +246,9 @@ def __init__(
247246
self.factors_init_value = factors_init_value
248247

249248
def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):
250-
"""Return a :class:`~sagemaker.amazon.FactorizationMachinesModel`
251-
referencing the latest s3 model data produced by this Estimator.
249+
"""Return a :class:`~sagemaker.amazon.FactorizationMachinesModel`.
250+
251+
It references the latest s3 model data produced by this Estimator.
252252
253253
Args:
254254
vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on
@@ -267,8 +267,7 @@ def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):
267267

268268

269269
class FactorizationMachinesPredictor(Predictor):
270-
"""Performs binary-classification or regression prediction from input
271-
vectors.
270+
"""Performs binary-classification or regression prediction from input vectors.
272271
273272
The implementation of
274273
:meth:`~sagemaker.predictor.Predictor.predict` in this
@@ -292,6 +291,8 @@ def __init__(
292291
deserializer=RecordDeserializer(),
293292
):
294293
"""
294+
Initialization for FactorizationMachinesPredictor class.
295+
295296
Args:
296297
endpoint_name (str): Name of the Amazon SageMaker endpoint to which
297298
requests are sent.
@@ -314,12 +315,15 @@ def __init__(
314315

315316
class FactorizationMachinesModel(Model):
316317
"""Reference S3 model data created by FactorizationMachines estimator.
318+
317319
Calling :meth:`~sagemaker.model.Model.deploy` creates an Endpoint and
318320
returns :class:`FactorizationMachinesPredictor`.
319321
"""
320322

321323
def __init__(self, model_data, role, sagemaker_session=None, **kwargs):
322324
"""
325+
Initialization for FactorizationMachinesModel class.
326+
323327
Args:
324328
model_data (str): The S3 location of a SageMaker model data
325329
``.tar.gz`` file.

src/sagemaker/amazon/hyperparameter.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class Hyperparameter(object):
2323
"""
2424

2525
def __init__(self, name, validate=lambda _: True, validation_message="", data_type=str):
26-
"""Args: name (str): The name of this hyperparameter validate
26+
"""Args:
27+
28+
name (str): The name of this hyperparameter validate
2729
(callable[object]->[bool]): A validation function or list of validation
2830
functions.
2931
@@ -49,10 +51,7 @@ def __init__(self, name, validate=lambda _: True, validation_message="", data_ty
4951
self.validation = [self.validation]
5052

5153
def validate(self, value):
52-
"""
53-
Args:
54-
value:
55-
"""
54+
"""Placeholder docstring"""
5655
if value is None: # We allow assignment from None, but Nones are not sent to training.
5756
return
5857

@@ -64,11 +63,7 @@ def validate(self, value):
6463
raise ValueError(error_message)
6564

6665
def __get__(self, obj, objtype):
67-
"""
68-
Args:
69-
obj:
70-
objtype:
71-
"""
66+
"""Placeholder docstring"""
7267
if "_hyperparameters" not in dir(obj) or self.name not in obj._hyperparameters:
7368
raise AttributeError()
7469
return obj._hyperparameters[self.name]
@@ -96,8 +91,7 @@ def __delete__(self, obj):
9691

9792
@staticmethod
9893
def serialize_all(obj):
99-
"""Return all non-None ``hyperparameter`` values on ``obj`` as a
100-
``dict[str,str].``
94+
"""Return all non-None ``hyperparameter`` values on ``obj`` as a ``dict[str,str].``
10195
10296
Args:
10397
obj:

src/sagemaker/amazon/ipinsights.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ def __init__(
7373
weight_decay=None,
7474
**kwargs
7575
):
76-
"""This estimator is for IP Insights, an unsupervised algorithm that
77-
learns usage patterns of IP addresses.
76+
"""This estimator is for IP Insights.
77+
78+
An unsupervised algorithm that learns usage patterns of IP addresses.
7879
7980
This Estimator may be fit via calls to
8081
:meth:`~sagemaker.amazon.amazon_estimator.AmazonAlgorithmEstimatorBase.fit`.
@@ -167,12 +168,7 @@ def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):
167168
)
168169

169170
def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
170-
"""
171-
Args:
172-
records:
173-
mini_batch_size:
174-
job_name:
175-
"""
171+
"""Placeholder docstring"""
176172
if mini_batch_size is not None and (mini_batch_size < 1 or mini_batch_size > 500000):
177173
raise ValueError("mini_batch_size must be in [1, 500000]")
178174
super(IPInsights, self)._prepare_for_training(
@@ -181,8 +177,7 @@ def _prepare_for_training(self, records, mini_batch_size=None, job_name=None):
181177

182178

183179
class IPInsightsPredictor(Predictor):
184-
"""Returns dot product of entity and IP address embeddings as a score for
185-
compatibility.
180+
"""Returns dot product of entity and IP address embeddings as a score for compatibility.
186181
187182
The implementation of
188183
:meth:`~sagemaker.predictor.Predictor.predict` in this
@@ -200,6 +195,7 @@ def __init__(
200195
):
201196
"""
202197
Args:
198+
203199
endpoint_name (str): Name of the Amazon SageMaker endpoint to which
204200
requests are sent.
205201
sagemaker_session (sagemaker.session.Session): A SageMaker Session
@@ -220,14 +216,16 @@ def __init__(
220216

221217

222218
class IPInsightsModel(Model):
223-
"""Reference IPInsights s3 model data. Calling
224-
:meth:`~sagemaker.model.Model.deploy` creates an Endpoint and returns a
219+
"""Reference IPInsights s3 model data.
220+
221+
Calling :meth:`~sagemaker.model.Model.deploy` creates an Endpoint and returns a
225222
Predictor that calculates anomaly scores for data points.
226223
"""
227224

228225
def __init__(self, model_data, role, sagemaker_session=None, **kwargs):
229226
"""
230227
Args:
228+
231229
model_data (str): The S3 location of a SageMaker model data
232230
``.tar.gz`` file.
233231
role (str): An AWS IAM role (either name or full ARN). The Amazon

0 commit comments

Comments
 (0)