Skip to content

Commit

Permalink
fix(aiplatform): Fix doc formatting (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaChavoshi committed May 3, 2021
1 parent ef4f6f8 commit 857f63d
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 163 deletions.
44 changes: 27 additions & 17 deletions google/cloud/aiplatform/base.py
Expand Up @@ -94,7 +94,6 @@ def log_create_complete(
resource (proto.Message):
AI Platform Resourc proto.Message
variable_name (str): Name of variable to use for code snippet
"""
self._logger.info(f"{cls.__name__} created. Resource name: {resource.name}")
self._logger.info(f"To use this {cls.__name__} in another session:")
Expand Down Expand Up @@ -181,7 +180,8 @@ def _raise_future_exception(self):
raise self._exception

def _complete_future(self, future: futures.Future):
"""Checks for exception of future and removes the pointer if it's still latest.
"""Checks for exception of future and removes the pointer if it's still
latest.
Args:
future (futures.Future): Required. A future to complete.
Expand Down Expand Up @@ -215,13 +215,14 @@ def wait(self):

@property
def _latest_future(self) -> Optional[futures.Future]:
"""Get the latest future if it exists"""
"""Get the latest future if it exists."""
with self.__latest_future_lock:
return self.__latest_future

@_latest_future.setter
def _latest_future(self, future: Optional[futures.Future]):
"""Optionally set the latest future and add a complete_future callback."""
"""Optionally set the latest future and add a complete_future
callback."""
with self.__latest_future_lock:
self.__latest_future = future
if future:
Expand Down Expand Up @@ -260,7 +261,8 @@ def wait_for_dependencies_and_invoke(
kwargs: Dict[str, Any],
internal_callbacks: Iterable[Callable[[Any], Any]],
) -> Any:
"""Wrapper method to wait on any dependencies before submitting method.
"""Wrapper method to wait on any dependencies before submitting
method.
Args:
deps (Sequence[futures.Future]):
Expand All @@ -272,7 +274,6 @@ def wait_for_dependencies_and_invoke(
Required. The keyword arguments to call the method with.
internal_callbacks: (Callable[[Any], Any]):
Callbacks that take the result of method.
"""

for future in set(deps):
Expand Down Expand Up @@ -342,12 +343,14 @@ def wait_for_dependencies_and_invoke(
@classmethod
@abc.abstractmethod
def _empty_constructor(cls) -> "FutureManager":
"""Should construct object with all non FutureManager attributes as None"""
"""Should construct object with all non FutureManager attributes as
None."""
pass

@abc.abstractmethod
def _sync_object_with_future_result(self, result: "FutureManager"):
"""Should sync the object from _empty_constructor with result of future."""
"""Should sync the object from _empty_constructor with result of
future."""

def __repr__(self) -> str:
if self._exception:
Expand Down Expand Up @@ -375,7 +378,8 @@ class AiPlatformResourceNoun(metaclass=abc.ABCMeta):
@classmethod
@abc.abstractmethod
def client_class(cls) -> Type[utils.AiPlatformServiceClientWithOverride]:
"""Client class required to interact with resource with optional overrides."""
"""Client class required to interact with resource with optional
overrides."""
pass

@property
Expand All @@ -388,7 +392,8 @@ def _is_client_prediction_client(cls) -> bool:
@property
@abc.abstractmethod
def _getter_method(cls) -> str:
"""Name of getter method of client class for retrieving the resource."""
"""Name of getter method of client class for retrieving the
resource."""
pass

@property
Expand All @@ -400,7 +405,7 @@ def _delete_method(cls) -> str:
@property
@abc.abstractmethod
def _resource_noun(cls) -> str:
"""Resource noun"""
"""Resource noun."""
pass

def __init__(
Expand Down Expand Up @@ -547,7 +552,8 @@ def optional_sync(
return_input_arg: Optional[str] = None,
bind_future_to_self: bool = True,
):
"""Decorator for AiPlatformResourceNounWithFutureManager with optional sync support.
"""Decorator for AiPlatformResourceNounWithFutureManager with optional sync
support.
Methods with this decorator should include a "sync" argument that defaults to
True. If called with sync=False this decorator will launch the method as a
Expand Down Expand Up @@ -681,7 +687,8 @@ def wrapper(*args, **kwargs):


class AiPlatformResourceNounWithFutureManager(AiPlatformResourceNoun, FutureManager):
"""Allows optional asynchronous calls to this AI Platform Resource Nouns."""
"""Allows optional asynchronous calls to this AI Platform Resource
Nouns."""

def __init__(
self,
Expand Down Expand Up @@ -816,7 +823,8 @@ def _list(
credentials: Optional[auth_credentials.Credentials] = None,
) -> List[AiPlatformResourceNoun]:
"""Private method to list all instances of this AI Platform Resource,
takes a `cls_filter` arg to filter to a particular SDK resource subclass.
takes a `cls_filter` arg to filter to a particular SDK resource
subclass.
Args:
cls_filter (Callable[[proto.Message], bool]):
Expand Down Expand Up @@ -884,8 +892,9 @@ def _list_with_local_order(
credentials: Optional[auth_credentials.Credentials] = None,
) -> List[AiPlatformResourceNoun]:
"""Private method to list all instances of this AI Platform Resource,
takes a `cls_filter` arg to filter to a particular SDK resource subclass.
Provides client-side sorting when a list API doesn't support `order_by`.
takes a `cls_filter` arg to filter to a particular SDK resource
subclass. Provides client-side sorting when a list API doesn't support
`order_by`.
Args:
cls_filter (Callable[[proto.Message], bool]):
Expand Down Expand Up @@ -986,7 +995,8 @@ def list(

@optional_sync()
def delete(self, sync: bool = True) -> None:
"""Deletes this AI Platform resource. WARNING: This deletion is permament.
"""Deletes this AI Platform resource. WARNING: This deletion is
permament.
Args:
sync (bool):
Expand Down
15 changes: 8 additions & 7 deletions google/cloud/aiplatform/datasets/_datasources.py
Expand Up @@ -26,7 +26,7 @@


class Datasource(abc.ABC):
"""An abstract class that sets dataset_metadata"""
"""An abstract class that sets dataset_metadata."""

@property
@abc.abstractmethod
Expand All @@ -36,7 +36,7 @@ def dataset_metadata(self):


class DatasourceImportable(abc.ABC):
"""An abstract class that sets import_data_config"""
"""An abstract class that sets import_data_config."""

@property
@abc.abstractmethod
Expand All @@ -46,14 +46,14 @@ def import_data_config(self):


class TabularDatasource(Datasource):
"""Datasource for creating a tabular dataset for AI Platform"""
"""Datasource for creating a tabular dataset for AI Platform."""

def __init__(
self,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
):
"""Creates a tabular datasource
"""Creates a tabular datasource.
Args:
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -99,23 +99,24 @@ def dataset_metadata(self) -> Optional[Dict]:


class NonTabularDatasource(Datasource):
"""Datasource for creating an empty non-tabular dataset for AI Platform"""
"""Datasource for creating an empty non-tabular dataset for AI Platform."""

@property
def dataset_metadata(self) -> Optional[Dict]:
return None


class NonTabularDatasourceImportable(NonTabularDatasource, DatasourceImportable):
"""Datasource for creating a non-tabular dataset for AI Platform and importing data to the dataset"""
"""Datasource for creating a non-tabular dataset for AI Platform and
importing data to the dataset."""

def __init__(
self,
gcs_source: Union[str, Sequence[str]],
import_schema_uri: str,
data_item_labels: Optional[Dict] = None,
):
"""Creates a non-tabular datasource
"""Creates a non-tabular datasource.
Args:
gcs_source (Union[str, Sequence[str]]):
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/aiplatform/datasets/dataset.py
Expand Up @@ -36,7 +36,7 @@


class _Dataset(base.AiPlatformResourceNounWithFutureManager):
"""Managed dataset resource for AI Platform"""
"""Managed dataset resource for AI Platform."""

client_class = utils.DatasetClientWithOverride
_is_client_prediction_client = False
Expand Down Expand Up @@ -70,7 +70,6 @@ def __init__(
credentials (auth_credentials.Credentials):
Custom credentials to use to upload this model. Overrides
credentials set in aiplatform.init.
"""

super().__init__(
Expand Down Expand Up @@ -195,7 +194,6 @@ def create(
Returns:
dataset (Dataset):
Instantiated representation of the managed dataset resource.
"""

utils.validate_display_name(display_name)
Expand Down
7 changes: 3 additions & 4 deletions google/cloud/aiplatform/datasets/image_dataset.py
Expand Up @@ -27,7 +27,7 @@


class ImageDataset(datasets._Dataset):
"""Managed image dataset resource for AI Platform"""
"""Managed image dataset resource for AI Platform."""

_supported_metadata_schema_uris: Optional[Tuple[str]] = (
schema.dataset.metadata.image,
Expand All @@ -47,8 +47,8 @@ def create(
encryption_spec_key_name: Optional[str] = None,
sync: bool = True,
) -> "ImageDataset":
"""Creates a new image dataset and optionally imports data into dataset when
source and import_schema_uri are passed.
"""Creates a new image dataset and optionally imports data into dataset
when source and import_schema_uri are passed.
Args:
display_name (str):
Expand Down Expand Up @@ -114,7 +114,6 @@ def create(
Returns:
image_dataset (ImageDataset):
Instantiated representation of the managed image dataset resource.
"""

utils.validate_display_name(display_name)
Expand Down
3 changes: 1 addition & 2 deletions google/cloud/aiplatform/datasets/tabular_dataset.py
Expand Up @@ -27,7 +27,7 @@


class TabularDataset(datasets._Dataset):
"""Managed tabular dataset resource for AI Platform"""
"""Managed tabular dataset resource for AI Platform."""

_supported_metadata_schema_uris: Optional[Tuple[str]] = (
schema.dataset.metadata.tabular,
Expand Down Expand Up @@ -95,7 +95,6 @@ def create(
Returns:
tabular_dataset (TabularDataset):
Instantiated representation of the managed tabular dataset resource.
"""

utils.validate_display_name(display_name)
Expand Down
7 changes: 3 additions & 4 deletions google/cloud/aiplatform/datasets/text_dataset.py
Expand Up @@ -27,7 +27,7 @@


class TextDataset(datasets._Dataset):
"""Managed text dataset resource for AI Platform"""
"""Managed text dataset resource for AI Platform."""

_supported_metadata_schema_uris: Optional[Tuple[str]] = (
schema.dataset.metadata.text,
Expand All @@ -47,8 +47,8 @@ def create(
encryption_spec_key_name: Optional[str] = None,
sync: bool = True,
) -> "TextDataset":
"""Creates a new text dataset and optionally imports data into dataset when
source and import_schema_uri are passed.
"""Creates a new text dataset and optionally imports data into dataset
when source and import_schema_uri are passed.
Example Usage:
ds = aiplatform.TextDataset.create(
Expand Down Expand Up @@ -121,7 +121,6 @@ def create(
Returns:
text_dataset (TextDataset):
Instantiated representation of the managed text dataset resource.
"""

utils.validate_display_name(display_name)
Expand Down
7 changes: 3 additions & 4 deletions google/cloud/aiplatform/datasets/video_dataset.py
Expand Up @@ -27,7 +27,7 @@


class VideoDataset(datasets._Dataset):
"""Managed video dataset resource for AI Platform"""
"""Managed video dataset resource for AI Platform."""

_supported_metadata_schema_uris: Optional[Tuple[str]] = (
schema.dataset.metadata.video,
Expand All @@ -47,8 +47,8 @@ def create(
encryption_spec_key_name: Optional[str] = None,
sync: bool = True,
) -> "VideoDataset":
"""Creates a new video dataset and optionally imports data into dataset when
source and import_schema_uri are passed.
"""Creates a new video dataset and optionally imports data into dataset
when source and import_schema_uri are passed.
Args:
display_name (str):
Expand Down Expand Up @@ -114,7 +114,6 @@ def create(
Returns:
video_dataset (VideoDataset):
Instantiated representation of the managed video dataset resource.
"""

utils.validate_display_name(display_name)
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/initializer.py
Expand Up @@ -107,8 +107,9 @@ def get_encryption_spec(
gca_encryption_spec_v1beta1.EncryptionSpec,
]
]:
"""Creates a gca_encryption_spec.EncryptionSpec instance from the given key name.
If the provided key name is None, it uses the default key name if provided.
"""Creates a gca_encryption_spec.EncryptionSpec instance from the given
key name. If the provided key name is None, it uses the default key
name if provided.
Args:
encryption_spec_key_name (Optional[str]): The default encryption key name to use when creating resources.
Expand Down Expand Up @@ -241,7 +242,8 @@ def create_client(
location_override: Optional[str] = None,
prediction_client: bool = False,
) -> utils.AiPlatformServiceClientWithOverride:
"""Instantiates a given AiPlatformServiceClient with optional overrides.
"""Instantiates a given AiPlatformServiceClient with optional
overrides.
Args:
client_class (utils.AiPlatformServiceClientWithOverride):
Expand Down

0 comments on commit 857f63d

Please sign in to comment.