Skip to content

Commit

Permalink
added two new func: set time, get table address (googleapis#23)
Browse files Browse the repository at this point in the history
* added two new func: set time, get table address

* changed indentation
  • Loading branch information
jonathan1920 authored and Lars Wander committed Jul 19, 2019
1 parent be43449 commit e19f141
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions automl/google/cloud/automl_v1beta1/tables/tables_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ def __dataset_name_from_args(self, dataset=None, dataset_display_name=None,
region=region
)
return dataset_name

def __table_spec_full_name_from_args(self, table_spec_index=0,
dataset=None, dataset_display_name=None,
dataset_name=None, project=None, region=None):

dataset_name = self.__dataset_name_from_args(dataset=dataset,
dataset_name=dataset_name,
dataset_display_name=dataset_display_name,
project=project,
region=region
)
table_specs = [t for t in self.list_table_specs(dataset_name=dataset_name)]
table_spec_full_id = table_specs[table_spec_index]
table_spec_full_id = table_specs[table_spec_index].name
return table_spec_full_id

def __model_name_from_args(self, model=None, model_display_name=None,
model_name=None, project=None, region=None):
Expand Down Expand Up @@ -950,6 +965,107 @@ def set_target_column(self, dataset=None, dataset_display_name=None,

return self.client.update_dataset(request)

def set_time_column(self, dataset=None, dataset_display_name=None,
dataset_name=None, table_spec_name=None, table_spec_index=0,
column_spec_name=None, column_spec_display_name=None,
project=None, region=None):
"""Sets the time column which designates which data
will be of type timestamp and will be used for the timeseries data.
. This column must be of type timestamp.
Example:
>>> from google.cloud import automl_v1beta1
>>>
>>> client = automl_v1beta1.tables.ClientHelper(
... client=automl_v1beta1.AutoMlClient(),
... project='my-project', region='us-central1')
...
>>> client.set_time_column(dataset_display_name='my_dataset',
... column_spec__name='Unix Time')
...
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.
column_spec_name (Optional[string]):
The name AutoML-assigned name for the column you want to set as
the time column.
column_spec_display_name (Optional[string]):
The human-readable name of the column you want to set as the
time column. If this is supplied in place of
`column_spec_name`, you also need to provide either a way to
lookup the source dataset (using one of the `dataset*` kwargs),
or the `table_spec_name` of the table this column belongs to.
table_spec_name (Optional[string]):
The AutoML-assigned name for the table whose time column
you want to set . If not supplied, the client can determine
this name from a source `Dataset` object.
table_spec_index (Optional[int]):
If no `table_spec_name` or `column_spec_name` was provided, we
use this index to determine which table to set the time
column on.
dataset_display_name (Optional[string]):
The human-readable name given to the dataset you want to update
the time column of. If no `table_spec_name` is supplied,
this will be used together with `table_spec_index` to infer the
name of table to update the time column of. 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
update the time column of. If no `table_spec_name` is
supplied, this will be used together with `table_spec_index` to
infer the name of table to update the time column of.
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 update the time column
of. If no `table_spec_name` is supplied, this will be used
together with `table_spec_index` to infer the name of table to
update the time column of. This must be supplied if
`table_spec_name`, `dataset_name` or `dataset_display_name` are
not supplied.
Returns:
A :class:`~google.cloud.automl_v1beta1.types.Dataset` 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.
"""
column_spec_name = self.__column_spec_name_from_args(
dataset=dataset,
dataset_display_name=dataset_display_name,
dataset_name=dataset_name,
table_spec_name=table_spec_name,
table_spec_index=table_spec_index,
column_spec_name=column_spec_name,
column_spec_display_name=column_spec_display_name,
project=project,
region=region
)
column_spec_id = column_spec_name.rsplit('/', 1)[-1]

dataset_name = self.__dataset_name_from_args(dataset=dataset,
dataset_name=dataset_name,
dataset_display_name=dataset_display_name,
project=project,
region=region)

table_spec_full_id = self.__table_spec_full_name_from_args(dataset_name=dataset_name)

my_table_spec = {
'name': table_spec_full_id,
'time_column_spec_id': column_spec_id
}

response = self.client.update_table_spec(my_table_spec)

def set_weight_column(self, dataset=None, dataset_display_name=None,
dataset_name=None, table_spec_name=None, table_spec_index=0,
column_spec_name=None, column_spec_display_name=None,
Expand Down

0 comments on commit e19f141

Please sign in to comment.