Skip to content

Commit

Permalink
feat: Made display_name optional for most calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ark-kun committed Dec 3, 2021
1 parent 8cb4839 commit 2508d11
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 51 deletions.
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, List, Optional, Sequence, Tuple, Union

from google.api_core import operation
Expand Down Expand Up @@ -105,12 +106,12 @@ def _validate_metadata_schema_uri(self) -> None:
@classmethod
def create(
cls,
display_name: str,
metadata_schema_uri: str,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
display_name: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand All @@ -124,7 +125,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
metadata_schema_uri (str):
Expand Down Expand Up @@ -207,7 +208,8 @@ def create(
dataset (Dataset):
Instantiated representation of the managed dataset resource.
"""

if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
7 changes: 5 additions & 2 deletions google/cloud/aiplatform/datasets/image_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, Optional, Sequence, Tuple, Union

from google.auth import credentials as auth_credentials
Expand All @@ -36,7 +37,7 @@ class ImageDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -53,7 +54,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -126,6 +127,8 @@ def create(
image_dataset (ImageDataset):
Instantiated representation of the managed image dataset resource.
"""
if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")

utils.validate_display_name(display_name)
if labels:
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/datasets/tabular_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, Optional, Sequence, Tuple, Union

from google.auth import credentials as auth_credentials
Expand All @@ -36,7 +37,7 @@ class TabularDataset(datasets._ColumnNamesDataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
project: Optional[str] = None,
Expand All @@ -51,7 +52,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -107,7 +108,8 @@ def create(
tabular_dataset (TabularDataset):
Instantiated representation of the managed tabular dataset resource.
"""

if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/datasets/text_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, Optional, Sequence, Tuple, Union

from google.auth import credentials as auth_credentials
Expand All @@ -36,7 +37,7 @@ class TextDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -60,7 +61,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -133,7 +134,8 @@ def create(
text_dataset (TextDataset):
Instantiated representation of the managed text dataset resource.
"""

if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/datasets/time_series_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, Optional, Sequence, Tuple, Union

from google.auth import credentials as auth_credentials
Expand All @@ -36,7 +37,7 @@ class TimeSeriesDataset(datasets._ColumnNamesDataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
bq_source: Optional[str] = None,
project: Optional[str] = None,
Expand All @@ -51,7 +52,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -108,7 +109,8 @@ def create(
Instantiated representation of the managed time series dataset resource.
"""

if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
8 changes: 5 additions & 3 deletions google/cloud/aiplatform/datasets/video_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
#

import datetime
from typing import Dict, Optional, Sequence, Tuple, Union

from google.auth import credentials as auth_credentials
Expand All @@ -36,7 +37,7 @@ class VideoDataset(datasets._Dataset):
@classmethod
def create(
cls,
display_name: str,
display_name: Optional[str] = None,
gcs_source: Optional[Union[str, Sequence[str]]] = None,
import_schema_uri: Optional[str] = None,
data_item_labels: Optional[Dict] = None,
Expand All @@ -53,7 +54,7 @@ def create(
Args:
display_name (str):
Required. The user-defined name of the Dataset.
Optional. The user-defined name of the Dataset.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
gcs_source (Union[str, Sequence[str]]):
Expand Down Expand Up @@ -126,7 +127,8 @@ def create(
video_dataset (VideoDataset):
Instantiated representation of the managed video dataset resource.
"""

if not display_name:
display_name = cls.name + " " + datetime.datetime.now().isoformat(sep=" ")
utils.validate_display_name(display_name)
if labels:
utils.validate_labels(labels)
Expand Down
18 changes: 12 additions & 6 deletions google/cloud/aiplatform/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,9 @@ class CustomJob(_RunnableJob):

def __init__(
self,
display_name: str,
worker_pool_specs: Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]],
base_output_dir: Optional[str] = None,
display_name: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def __init__(
Args:
display_name (str):
Required. The user-defined name of the HyperparameterTuningJob.
Optional. The user-defined name of the HyperparameterTuningJob.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
worker_pool_specs (Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]]):
Expand Down Expand Up @@ -1070,6 +1070,9 @@ def __init__(
staging_bucket, "aiplatform-custom-job"
)

if not display_name:
display_name = self.__class__.name + " " + datetime.datetime.now().isoformat(sep=" ")

self._gca_resource = gca_custom_job_compat.CustomJob(
display_name=display_name,
job_spec=gca_custom_job_compat.CustomJobSpec(
Expand Down Expand Up @@ -1122,7 +1125,6 @@ def _log_web_access_uris(self):
@classmethod
def from_local_script(
cls,
display_name: str,
script_path: str,
container_uri: str,
args: Optional[Sequence[str]] = None,
Expand All @@ -1138,6 +1140,7 @@ def from_local_script(
reduction_server_machine_type: Optional[str] = None,
reduction_server_container_uri: Optional[str] = None,
base_output_dir: Optional[str] = None,
display_name: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1165,7 +1168,7 @@ def from_local_script(
Args:
display_name (str):
Required. The user-defined name of this CustomJob.
Optional. The user-defined name of this CustomJob.
script_path (str):
Required. Local path to training script.
container_uri (str):
Expand Down Expand Up @@ -1439,7 +1442,6 @@ class HyperparameterTuningJob(_RunnableJob):

def __init__(
self,
display_name: str,
custom_job: CustomJob,
metric_spec: Dict[str, str],
parameter_spec: Dict[str, hyperparameter_tuning._ParameterSpec],
Expand All @@ -1448,6 +1450,7 @@ def __init__(
max_failed_trial_count: int = 0,
search_algorithm: Optional[str] = None,
measurement_selection: Optional[str] = "best",
display_name: Optional[str] = None,
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
Expand Down Expand Up @@ -1513,7 +1516,7 @@ def __init__(
Args:
display_name (str):
Required. The user-defined name of the HyperparameterTuningJob.
Optional. The user-defined name of the HyperparameterTuningJob.
The name can be up to 128 characters long and can be consist
of any UTF-8 characters.
custom_job (aiplatform.CustomJob):
Expand Down Expand Up @@ -1635,6 +1638,9 @@ def __init__(
],
)

if not display_name:
display_name = self.__class__.name + " " + datetime.datetime.now().isoformat(sep=" ")

self._gca_resource = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob(
display_name=display_name,
study_spec=study_spec,
Expand Down
Loading

0 comments on commit 2508d11

Please sign in to comment.