Skip to content

Commit

Permalink
Configure doc generation for client (googleapis#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander authored and Lars Wander committed Jul 1, 2019
1 parent f7dd0ea commit 3709c09
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 33 deletions.
5 changes: 5 additions & 0 deletions automl/docs/gapic/v1beta1/helper.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Helper clients for Cloud AutoML API
===================================

.. automodule:: google.cloud.automl_v1beta1.helper.tables
:members:
1 change: 1 addition & 0 deletions automl/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Api Reference

gapic/v1beta1/api
gapic/v1beta1/types
gapic/v1beta1/helper


Changelog
Expand Down
206 changes: 173 additions & 33 deletions automl/google/cloud/automl_v1beta1/helper/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""A helper for the google.cloud.automl_v1beta1 AutoML Tables API"""

import google.cloud.automl_v1beta1.proto.data_types_pb2 as data_types
from google.cloud.automl_v1beta1.proto import data_types_pb2

class ClientHelper(object):
"""
Expand All @@ -31,9 +31,7 @@ def __init__(self, client=None, prediction_client=None, project=None,
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> from google_helper.cloud.automl import tables
>>>
>>> client = tables.ClientHelper(
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... prediction_client=automl_v1beta1.PredictionServiceClient(),
... project='my-project', region='us-central1')
Expand Down Expand Up @@ -139,9 +137,9 @@ def __column_spec_name_from_args(self, dataset=None, dataset_display_name=None,
## TODO(lwander): what other type codes are there?
## https://github.com/googleapis/google-cloud-python/blob/master/automl/google/cloud/automl_v1beta1/proto/data_types_pb2.py#L87-L92
def __type_code_to_value_type(self, type_code):
if type_code == data_types.FLOAT64:
if type_code == data_types_pb2.FLOAT64:
return 'number_value'
if type_code == data_types.CATEGORY:
if type_code == data_types_pb2.CATEGORY:
return 'string_value'
else:
raise ValueError('Unknown type_code: {}'.format(type_code))
Expand All @@ -152,9 +150,7 @@ def list_datasets(self, project=None, region=None):
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> from google_helper.cloud.automl import tables
>>>
>>> client = tables.ClientHelper(
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
Expand All @@ -175,9 +171,10 @@ def list_datasets(self, project=None, region=None):
will be used if this parameter is not supplied.
Returns:
An iterator over `Dataset
<https://googleapis.github.io/google-cloud-python/latest/automl/gapic/v1beta1/types.html#google.cloud.automl_v1beta1.types.Dataset>`_
instances.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.automl_v1beta1.types.Dataset` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand All @@ -197,9 +194,7 @@ def get_dataset(self, project=None, region=None,
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> from google_helper.cloud.automl import tables
>>>
>>> client = tables.ClientHelper(
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
Expand All @@ -226,9 +221,7 @@ def get_dataset(self, project=None, region=None,
must be provided.
Returns:
A `Dataset
<https://googleapis.github.io/google-cloud-python/latest/automl/gapic/v1beta1/types.html#google.cloud.automl_v1beta1.types.Dataset>`_
instance.
A :class:`~google.cloud.automl_v1beta1.types.Dataset` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand All @@ -255,9 +248,7 @@ def create_dataset(self, dataset_display_name, metadata={}, project=None,
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> from google_helper.cloud.automl import tables
>>>
>>> client = tables.ClientHelper(
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
Expand All @@ -276,10 +267,7 @@ def create_dataset(self, dataset_display_name, metadata={}, project=None,
A human-readable name to refer to this dataset by.
Returns:
A :class:`~google_helper.cloud.automl.types.Dataset` instance,
which acts as a delegate to the `Dataset
<https://googleapis.github.io/google-cloud-python/latest/automl/gapic/v1beta1/types.html#google.cloud.automl_v1beta1.types.Dataset>`_
class.
A :class:`~google.cloud.automl_v1beta1.types.Dataset` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand All @@ -288,7 +276,7 @@ def create_dataset(self, dataset_display_name, metadata={}, project=None,
to a retryable error and retry attempts failed.
ValueError: If required parameters are missing.
"""
return dataset=self.client.create_dataset(
return self.client.create_dataset(
self.__location_path(project, region),
{
'display_name': dataset_display_name,
Expand All @@ -298,6 +286,52 @@ def create_dataset(self, dataset_display_name, metadata={}, project=None,

def delete_dataset(self, dataset=None, dataset_display_name=None,
dataset_name=None, project=None, region=None):
"""Deletes a dataset. This does not delete any models trained on
this dataset.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
>>> op = client.delete_dataset(dataset_display_name='my_dataset')
>>>
>>> op.result() # blocks on delete request
Args:
project (Optional[string]):
If you have initialized the client with a value for `project` it
will be used if this parameter is not supplied. Keep in mind, the
service account this client was initialized with must have access
to this project.
region (Optional[string]):
If you have initialized the client with a value for `region` it
will be used if this parameter is not supplied.
dataset_display_name (Optional[string]):
The human-readable name given to the dataset you want to delete.
This must be supplied if `dataset` or `dataset_name` are not
supplied.
dataset_name (Optional[string]):
The AutoML-assigned name given to the dataset you want to
delete. This must be supplied if
`dataset_display_name` or `dataset` are not supplied.
dataset (Optional[Dataset]):
The `Dataset` instance you want to delete. This must
be supplied if `dataset_display_name` or `dataset_name` are not
supplied.
Returns:
A :class:`~google.cloud.automl_v1beta1.types._OperationFuture` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If required parameters are missing.
"""
dataset_name = self.__dataset_name_from_args(dataset=dataset,
dataset_name=dataset_name,
dataset_display_name=dataset_display_name,
Expand All @@ -315,9 +349,7 @@ def import_data(self, dataset=None, dataset_display_name=None,
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> from google_helper.cloud.automl import tables
>>>
>>> client = tables.ClientHelper(
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
Expand Down Expand Up @@ -361,8 +393,7 @@ def import_data(self, dataset=None, dataset_display_name=None,
import. This must be supplied if `gcs_input_uris` is not.
Returns:
An `OperationFuture`, which can either be used to register a
callback, or block until completion.
A :class:`~google.cloud.automl_v1beta1.types._OperationFuture` instance.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down Expand Up @@ -400,6 +431,55 @@ def import_data(self, dataset=None, dataset_display_name=None,

def list_table_specs(self, dataset=None, dataset_display_name=None,
dataset_name=None, project=None, region=None):
"""Lists table specs.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
>>> for s in client.list_table_specs(dataset_display_name='my_dataset')
... # process the spec
... pass
>>>
Args:
project (Optional[string]):
If you have initialized the client with a value for `project` it
will be used if this parameter is not supplied. Keep in mind, the
service account this client was initialized with must have access
to this project.
region (Optional[string]):
If you have initialized the client with a value for `region` it
will be used if this parameter is not supplied.
dataset_display_name (Optional[string]):
The human-readable name given to the dataset you want to read
specs from. This must be supplied if `dataset` or
`dataset_name` are not supplied.
dataset_name (Optional[string]):
The AutoML-assigned name given to the dataset you want to
read specs from. This must be supplied if
`dataset_display_name` or `dataset` are not supplied.
dataset (Optional[Dataset]):
The `Dataset` instance you want to read specs from. This must
be supplied if `dataset_display_name` or `dataset_name` are not
supplied.
Returns:
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.automl_v1beta1.types.TableSpec` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If required parameters are missing.
"""
dataset_name = self.__dataset_name_from_args(dataset=dataset,
dataset_name=dataset_name,
dataset_display_name=dataset_display_name,
Expand All @@ -408,11 +488,71 @@ def list_table_specs(self, dataset=None, dataset_display_name=None,

return self.client.list_table_specs(dataset_name)

# if no table_name is provided, the table_index in the table_specs
# is picked.
def list_column_specs(self, dataset=None, dataset_display_name=None,
dataset_name=None, table_spec_name=None, table_spec_index=0,
project=None, region=None):
"""Lists column specs.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
>>>
>>> for s in client.list_column_specs(dataset_display_name='my_dataset')
... # process the spec
... pass
>>>
Args:
project (Optional[string]):
If you have initialized the client with a value for `project` it
will be used if this parameter is not supplied. Keep in mind, the
service account this client was initialized with must have access
to this project.
region (Optional[string]):
If you have initialized the client with a value for `region` it
will be used if this parameter is not supplied.
table_spec_name (Optional[string]):
The name AutoML-assigned name for the table whose specs you
want to read. If not supplied, the client can determine this name
from a source `Dataset` object.
table_spec_index (Optional[int]):
If no `table_spec_name` was provided, we use this index to
determine which table to read column specs from.
dataset_display_name (Optional[string]):
The human-readable name given to the dataset you want to read
specs from. If no `table_spec_name` is supplied, this will
be used together with `table_spec_index` to infer the name of
table to read specs from. This must be supplied if `table_spec_name`,
`dataset` or `dataset_name` are not supplied.
dataset_name (Optional[string]):
The AutoML-assigned name given to the dataset you want to read
specs from. If no `table_spec_name` is supplied, this will
be used together with `table_spec_index` to infer the name of
table to read specs from. This must be supplied if `table_spec_name`,
`dataset` or `dataset_display_name` are not supplied.
dataset (Optional[Dataset]):
The `Dataset` instance you want to read
specs from. If no `table_spec_name` is supplied, this will
be used together with `table_spec_index` to infer the name of
table to read specs from. This must be supplied if `table_spec_name`,
`dataset_name` or `dataset_display_name` are not supplied.
Returns:
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.automl_v1beta1.types.ColumnSpec` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
failed for any reason.
google.api_core.exceptions.RetryError: If the request failed due
to a retryable error and retry attempts failed.
ValueError: If required parameters are missing.
"""
if table_spec_name is None:
table_specs = [t for t in self.list_table_specs(dataset=dataset,
dataset_display_name=dataset_display_name,
Expand Down

0 comments on commit 3709c09

Please sign in to comment.