File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from google.cloud.aiplatform import initializer
4545
from google.cloud.aiplatform import utils
4646
from google.cloud.aiplatform.compat.types import encryption_spec as gca_encryption_spec
47+
from google.protobuf import json_format
4748

4849
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
4950

@@ -607,6 +608,10 @@ def _assert_gca_resource_is_available(self) -> None:
607608
def __repr__(self) -> str:
608609
return f"{object.__repr__(self)} \nresource name: {self.resource_name}"
609610

611+
def to_dict(self) -> Dict[str, Any]:
612+
"""Returns the resource proto as a dictionary."""
613+
return json_format.MessageToDict(self.gca_resource._pb)
614+
610615

611616
def optional_sync(
612617
construct_object_on_arg: Optional[str] = None,
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import proto
2525
from google.api_core import exceptions
2626
from google.auth import credentials as auth_credentials
27-
from google.protobuf import json_format
2827

2928
from google.cloud.aiplatform import base, initializer
3029
from google.cloud.aiplatform import utils
@@ -98,7 +97,7 @@ def __init__(
9897

9998
@property
10099
def metadata(self) -> Dict:
101-
return json_format.MessageToDict(self._gca_resource._pb)["metadata"]
100+
return self.to_dict()["metadata"]
102101

103102
@property
104103
def schema_title(self) -> str:
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import importlib
2222

2323
from google import auth as google_auth
24-
from google.protobuf import json_format
2524
from google.api_core import exceptions
2625
from google.api_core import client_options
2726

@@ -239,16 +238,15 @@ def test_create_tabular_dataset(self, dataset_gapic_client, shared_state):
239238
gcs_source=[_TEST_TABULAR_CLASSIFICATION_GCS_SOURCE],
240239
)
241240

242-
gapic_dataset = tabular_dataset._gca_resource
243241
shared_state["dataset_name"] = tabular_dataset.resource_name
244242

245-
gapic_metadata = json_format.MessageToDict(gapic_dataset._pb.metadata)
243+
gapic_metadata = tabular_dataset.to_dict()["metadata"]
246244
gcs_source_uris = gapic_metadata["inputConfig"]["gcsSource"]["uri"]
247245

248246
assert len(gcs_source_uris) == 1
249247
assert _TEST_TABULAR_CLASSIFICATION_GCS_SOURCE == gcs_source_uris[0]
250248
assert (
251-
gapic_dataset.metadata_schema_uri
249+
tabular_dataset.metadata_schema_uri
252250
== aiplatform.schema.dataset.metadata.tabular
253251
)
254252

0 commit comments

Comments
 (0)