GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: added 'Rases' section, changed Assertion to raise Exception, add… · googleapis/python-aiplatform@c9a415d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google/cloud/aiplatform/datasets
    • datasets.py
    • tabular_datasets.py
  • tests/unit/aiplatform
    • test_tabular_datasets.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google/cloud/aiplatform/datasets/datasets.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform/datasets/datasets.py
+13-6Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ def create(
178178
# If this is tabular enrich the dataset metadata with source
179179
dataset_metadata = {}
180180
if is_tabular_dataset_metadata:
181+
if gcs_source and bq_source:
182+
raise Exception(
183+
"'gcs_source' and 'bq_source' should not be set the same time."
184+
)
185+
if not gcs_source and not bq_source:
186+
raise Exception("Either 'gcs_source' or 'bq_source' should be set.")
181187
if gcs_source:
182188
dataset_metadata = {"input_config": {"gcs_source": {"uri": gcs_source}}}
183189
elif bq_source:
@@ -205,12 +211,13 @@ def create(
205211
credentials=credentials,
206212
)
207213

208-
if gcs_source and not is_tabular_dataset_metadata:
209-
return dataset_obj.import_data(
210-
gcs_source=gcs_source,
211-
import_schema_uri=import_schema_uri,
212-
data_items_labels=data_items_labels,
213-
)
214+
if not is_tabular_dataset_metadata:
215+
if gcs_source and import_schema_uri:
216+
return dataset_obj.import_data(
217+
gcs_source=gcs_source,
218+
import_schema_uri=import_schema_uri,
219+
data_items_labels=data_items_labels,
220+
)
214221
else:
215222
return dataset_obj
216223

Collapse file

‎google/cloud/aiplatform/datasets/tabular_datasets.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform/datasets/tabular_datasets.py
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
class TabularDataset(datasets.Dataset):
2828
"""Managed tabular dataset resource for AI Platform"""
2929

30+
_types = [
31+
schema.dataset.metadata.tabular,
32+
]
33+
3034
def __init__(
3135
self,
3236
dataset_name: str,
@@ -50,6 +54,9 @@ def __init__(
5054
credentials: Optional[auth_credentials.Credentials]=None,
5155
Custom credentials to use to upload this model. Overrides
5256
credentials set in aiplatform.init.
57+
Raises:
58+
Exception if the retrieved dataset type is not supported by
59+
'TabularDataset' class.
5360
"""
5461

5562
super().__init__(
@@ -59,9 +66,11 @@ def __init__(
5966
credentials=credentials,
6067
)
6168

62-
assert self.metadata_schema_uri == schema.dataset.metadata.tabular, (
63-
"%s is not a tabular dataset resource" % self.resource_name
64-
)
69+
if self.metadata_schema_uri not in self._types:
70+
raise Exception(
71+
f"{self.resource_name} can not be retrieved using "
72+
f"'TabularDataset' class, check the dataset type"
73+
)
6574

6675
@classmethod
6776
def create(
Collapse file

‎tests/unit/aiplatform/test_tabular_datasets.py‎

Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_tabular_datasets.py
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def create_dataset_mock(self):
9393
create_dataset_mock.return_value = create_dataset_lro_mock
9494
yield create_dataset_mock
9595

96-
@pytest.mark.usefixtures("get_tabular_dataset_mock")
9796
def test_init_tabular_dataset(self, get_tabular_dataset_mock):
9897
aiplatform.init(project=_TEST_PROJECT)
9998
TabularDataset(dataset_name=_TEST_NAME)
@@ -102,7 +101,7 @@ def test_init_tabular_dataset(self, get_tabular_dataset_mock):
102101
@pytest.mark.usefixtures("get_nontabular_dataset_mock")
103102
def test_init_nontabular_dataset(self):
104103
aiplatform.init(project=_TEST_PROJECT)
105-
with pytest.raises(AssertionError):
104+
with pytest.raises(Exception):
106105
TabularDataset(dataset_name=_TEST_NAME)
107106

108107
@pytest.mark.usefixtures("get_tabular_dataset_mock")
@@ -126,10 +125,23 @@ def test_create_dataset_tabular(self, create_dataset_mock):
126125
parent=_TEST_PARENT, dataset=expected_dataset
127126
)
128127

128+
def test_create_tabular_dataset_with_both_source(self):
129+
aiplatform.init(project=_TEST_PROJECT)
130+
with pytest.raises(Exception):
131+
TabularDataset.create(
132+
display_name=_TEST_DISPLAY_NAME,
133+
gcs_source=_TEST_SOURCE_URI_GCS,
134+
bq_source=_TEST_SOURCE_URI_BQ,
135+
)
136+
137+
def test_create_tabular_dataset_with_no_source(self):
138+
aiplatform.init(project=_TEST_PROJECT)
139+
with pytest.raises(Exception):
140+
TabularDataset.create(display_name=_TEST_DISPLAY_NAME,)
141+
129142
@pytest.mark.usefixtures("get_tabular_dataset_mock")
130143
def test_no_import_data_method(self):
131144
aiplatform.init(project=_TEST_PROJECT)
132145
my_dataset = TabularDataset(dataset_name=_TEST_NAME)
133-
with pytest.raises(AttributeError):
146+
with pytest.raises(Exception):
134147
my_dataset.import_data
135-

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.