Skip to content

feat: remove D205 to enable PEP257 Docstring Conventions #2045

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
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pydocstylerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[pydocstyle]
inherit = false
ignore = D104,D107,D202,D203,D205,D212,D213,D214,D400,D401,D404,D406,D407,D411,D413,D414,D415,D417
ignore = D104,D107,D202,D203,D212,D213,D214,D400,D401,D404,D406,D407,D411,D413,D414,D415,D417
match = (?!record_pb2).*\.py
53 changes: 13 additions & 40 deletions src/sagemaker/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@


class AlgorithmEstimator(EstimatorBase):
"""A generic Estimator to train using any algorithm object (with an
``algorithm_arn``). The Algorithm can be your own, or any Algorithm from AWS
"""A generic Estimator to train using any algorithm object (with an ``algorithm_arn``).

The Algorithm can be your own, or any Algorithm from AWS
Marketplace that you have a valid subscription for. This class will perform
client-side validation on all the inputs.
"""
Expand Down Expand Up @@ -212,10 +213,7 @@ def validate_train_spec(self):
)

def set_hyperparameters(self, **kwargs):
"""
Args:
**kwargs:
"""
"""Placeholder docstring"""
for k, v in kwargs.items():
value = self._validate_and_cast_hyperparameter(k, v)
self.hyperparam_dict[k] = value
Expand Down Expand Up @@ -330,9 +328,9 @@ def transformer(
role=None,
volume_kms_key=None,
):
"""Return a ``Transformer`` that uses a SageMaker Model based on the
training job. It reuses the SageMaker Session and base job name used by
the Estimator.
"""Return a ``Transformer`` that uses a SageMaker Model based on the training job.

It reuses the SageMaker Session and base job name used by the Estimator.

Args:
instance_count (int): Number of EC2 instances to use.
Expand Down Expand Up @@ -413,32 +411,19 @@ def _prepare_for_training(self, job_name=None):
# Validate hyperparameters
# an explicit call to set_hyperparameters() will also validate the hyperparameters
# but it is possible that the user never called it.
"""
Args:
job_name:
"""
self._validate_and_set_default_hyperparameters()

super(AlgorithmEstimator, self)._prepare_for_training(job_name)

def fit(self, inputs=None, wait=True, logs=True, job_name=None):
"""
Args:
inputs:
wait:
logs:
job_name:
"""
"""Placeholder docstring"""
if inputs:
self._validate_input_channels(inputs)

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

def _validate_input_channels(self, channels):
"""
Args:
channels:
"""
"""Placeholder docstring"""
train_spec = self.algorithm_spec["TrainingSpecification"]
algorithm_name = self.algorithm_spec["AlgorithmName"]
training_channels = {c["Name"]: c for c in train_spec["TrainingChannels"]}
Expand All @@ -456,11 +441,7 @@ def _validate_input_channels(self, channels):
raise ValueError("Required input channel: %s Was not provided." % (name))

def _validate_and_cast_hyperparameter(self, name, v):
"""
Args:
name:
v:
"""
"""Placeholder docstring"""
algorithm_name = self.algorithm_spec["AlgorithmName"]

if name not in self.hyperparameter_definitions:
Expand Down Expand Up @@ -514,11 +495,7 @@ def _parse_hyperparameters(self):
return definitions

def _hyperparameter_range_and_class(self, parameter_type, hyperparameter):
"""
Args:
parameter_type:
hyperparameter:
"""
"""Placeholder docstring."""
if parameter_type in self._hyperpameters_with_range:
range_name = parameter_type + "ParameterRangeSpecification"

Expand Down Expand Up @@ -559,10 +536,7 @@ def _hyperparameter_range_and_class(self, parameter_type, hyperparameter):
return parameter_class, parameter_range

def _algorithm_training_input_modes(self, training_channels):
"""
Args:
training_channels:
"""
"""Placeholder docstring"""
current_input_modes = {"File", "Pipe"}
for channel in training_channels:
supported_input_modes = set(channel["SupportedInputModes"])
Expand All @@ -572,8 +546,7 @@ def _algorithm_training_input_modes(self, training_channels):

@classmethod
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):
"""Convert the job description to init params that can be handled by the
class constructor
"""Convert the job description to init params that can be handled by the class constructor.

Args:
job_details (dict): the returned job details from a DescribeTrainingJob
Expand Down
39 changes: 14 additions & 25 deletions src/sagemaker/amazon/amazon_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@


class AmazonAlgorithmEstimatorBase(EstimatorBase):
"""Base class for Amazon first-party Estimator implementations. This class
isn't intended to be instantiated directly.
"""Base class for Amazon first-party Estimator implementations.

This class isn't intended to be instantiated directly.
"""

feature_dim = hp("feature_dim", validation.gt(0), data_type=int)
Expand Down Expand Up @@ -110,10 +111,7 @@ def data_location(self):

@data_location.setter
def data_location(self, data_location):
"""
Args:
data_location:
"""
"""Placeholder docstring"""
if not data_location.startswith("s3://"):
raise ValueError(
'Expecting an S3 URL beginning with "s3://". Got "{}"'.format(data_location)
Expand All @@ -124,8 +122,7 @@ def data_location(self, data_location):

@classmethod
def _prepare_init_params_from_job_description(cls, job_details, model_channel_name=None):
"""Convert the job description to init params that can be handled by the
class constructor
"""Convert the job description to init params that can be handled by the class constructor.

Args:
job_details: the returned job details from a describe_training_job
Expand Down Expand Up @@ -245,8 +242,7 @@ def fit(
self.latest_training_job.wait(logs=logs)

def record_set(self, train, labels=None, channel="train", encrypt=False):
"""Build a :class:`~RecordSet` from a numpy :class:`~ndarray` matrix and
label vector.
"""Build a :class:`~RecordSet` from a numpy :class:`~ndarray` matrix and label vector.

For the 2D ``ndarray`` ``train``, each row is converted to a
:class:`~Record` object. The vector is stored in the "values" entry of
Expand Down Expand Up @@ -301,8 +297,7 @@ class RecordSet(object):
def __init__(
self, s3_data, num_records, feature_dim, s3_data_type="ManifestFile", channel="train"
):
"""A collection of Amazon :class:~`Record` objects serialized and stored
in S3.
"""A collection of Amazon :class:~`Record` objects serialized and stored in S3.

Args:
s3_data (str): The S3 location of the training data
Expand All @@ -328,9 +323,8 @@ def __repr__(self):
return str((RecordSet, self.__dict__))

def data_channel(self):
"""Return a dictionary to represent the training data in a channel for
use with ``fit()``
"""
"""Returns dictionary to represent the training data in a channel to use with ``fit()``."""

return {self.channel: self.records_s3_input()}

def records_s3_input(self):
Expand All @@ -341,9 +335,7 @@ def records_s3_input(self):


class FileSystemRecordSet(object):
"""Amazon SageMaker channel configuration for a file system data source
for Amazon algorithms.
"""
"""Amazon SageMaker channel configuration for file system data source for Amazon algorithms."""

def __init__(
self,
Expand Down Expand Up @@ -390,11 +382,7 @@ def data_channel(self):


def _build_shards(num_shards, array):
"""
Args:
num_shards:
array:
"""
"""Placeholder docstring"""
if num_shards < 1:
raise ValueError("num_shards must be >= 1")
shard_size = int(array.shape[0] / num_shards)
Expand All @@ -408,8 +396,9 @@ def _build_shards(num_shards, array):
def upload_numpy_to_s3_shards(
num_shards, s3, bucket, key_prefix, array, labels=None, encrypt=False
):
"""Upload the training ``array`` and ``labels`` arrays to ``num_shards`` S3
objects, stored in "s3:// ``bucket`` / ``key_prefix`` /". Optionally
"""Upload the training ``array`` and ``labels`` arrays to ``num_shards``.

S3 objects, stored in "s3:// ``bucket`` / ``key_prefix`` /". Optionally
``encrypt`` the S3 objects using AES-256.

Args:
Expand Down
38 changes: 6 additions & 32 deletions src/sagemaker/amazon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ def deserialize(self, data, content_type):


def _write_feature_tensor(resolved_type, record, vector):
"""
Args:
resolved_type:
record:
vector:
"""
"""Placeholder Docstring"""
if resolved_type == "Int32":
record.features["values"].int32_tensor.values.extend(vector)
elif resolved_type == "Float64":
Expand All @@ -107,12 +102,7 @@ def _write_feature_tensor(resolved_type, record, vector):


def _write_label_tensor(resolved_type, record, scalar):
"""
Args:
resolved_type:
record:
scalar:
"""
"""Placeholder Docstring"""
if resolved_type == "Int32":
record.label["values"].int32_tensor.values.extend([scalar])
elif resolved_type == "Float64":
Expand All @@ -122,12 +112,7 @@ def _write_label_tensor(resolved_type, record, scalar):


def _write_keys_tensor(resolved_type, record, vector):
"""
Args:
resolved_type:
record:
vector:
"""
"""Placeholder Docstring"""
if resolved_type == "Int32":
record.features["values"].int32_tensor.keys.extend(vector)
elif resolved_type == "Float64":
Expand All @@ -137,12 +122,7 @@ def _write_keys_tensor(resolved_type, record, vector):


def _write_shape(resolved_type, record, scalar):
"""
Args:
resolved_type:
record:
scalar:
"""
"""Placeholder Docstring"""
if resolved_type == "Int32":
record.features["values"].int32_tensor.shape.extend([scalar])
elif resolved_type == "Float64":
Expand Down Expand Up @@ -285,10 +265,7 @@ def _write_recordio(f, data):


def read_recordio(f):
"""
Args:
f:
"""
"""Placeholder Docstring"""
while True:
try:
(read_kmagic,) = struct.unpack("I", f.read(4))
Expand All @@ -303,10 +280,7 @@ def read_recordio(f):


def _resolve_type(dtype):
"""
Args:
dtype:
"""
"""Placeholder Docstring"""
if dtype == np.dtype(int):
return "Int32"
if dtype == np.dtype(float):
Expand Down
16 changes: 10 additions & 6 deletions src/sagemaker/amazon/factorization_machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ def __init__(
factors_init_value=None,
**kwargs
):
"""Factorization Machines is :class:`Estimator` for general-purpose
supervised learning.
"""Factorization Machines is :class:`Estimator` for general-purpose supervised learning.

Amazon SageMaker Factorization Machines is a general-purpose
supervised learning algorithm that you can use for both classification
Expand Down Expand Up @@ -247,8 +246,9 @@ def __init__(
self.factors_init_value = factors_init_value

def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):
"""Return a :class:`~sagemaker.amazon.FactorizationMachinesModel`
referencing the latest s3 model data produced by this Estimator.
"""Return a :class:`~sagemaker.amazon.FactorizationMachinesModel`.

It references the latest s3 model data produced by this Estimator.

Args:
vpc_config_override (dict[str, list[str]]): Optional override for VpcConfig set on
Expand All @@ -267,8 +267,7 @@ def create_model(self, vpc_config_override=VPC_CONFIG_DEFAULT, **kwargs):


class FactorizationMachinesPredictor(Predictor):
"""Performs binary-classification or regression prediction from input
vectors.
"""Performs binary-classification or regression prediction from input vectors.

The implementation of
:meth:`~sagemaker.predictor.Predictor.predict` in this
Expand All @@ -292,6 +291,8 @@ def __init__(
deserializer=RecordDeserializer(),
):
"""
Initialization for FactorizationMachinesPredictor class.

Args:
endpoint_name (str): Name of the Amazon SageMaker endpoint to which
requests are sent.
Expand All @@ -314,12 +315,15 @@ def __init__(

class FactorizationMachinesModel(Model):
"""Reference S3 model data created by FactorizationMachines estimator.

Calling :meth:`~sagemaker.model.Model.deploy` creates an Endpoint and
returns :class:`FactorizationMachinesPredictor`.
"""

def __init__(self, model_data, role, sagemaker_session=None, **kwargs):
"""
Initialization for FactorizationMachinesModel class.

Args:
model_data (str): The S3 location of a SageMaker model data
``.tar.gz`` file.
Expand Down
Loading