Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for unrecognized model types #401

Merged
merged 3 commits into from Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions google/cloud/bigquery/model.py
Expand Up @@ -305,9 +305,15 @@ def from_api_repr(cls, resource):
start_time = datetime_helpers.from_microseconds(1e3 * float(start_time))
training_run["startTime"] = datetime_helpers.to_rfc3339(start_time)

this._proto = json_format.ParseDict(
resource, types.Model()._pb, ignore_unknown_fields=True
)
try:
this._proto = json_format.ParseDict(
resource, types.Model()._pb, ignore_unknown_fields=True
)
except json_format.ParseError:
resource["modelType"] = "MODEL_TYPE_UNSPECIFIED"
this._proto = json_format.ParseDict(
resource, types.Model()._pb, ignore_unknown_fields=True
)
return this

def _build_resource(self, filter_fields):
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/model/test_model.py
Expand Up @@ -186,6 +186,23 @@ def test_from_api_repr_w_unknown_fields(target_class):
assert got._properties is resource


def test_from_api_repr_w_unknown_type(target_class):
from google.cloud.bigquery import ModelReference

resource = {
"modelReference": {
"projectId": "my-project",
"datasetId": "my_dataset",
"modelId": "my_model",
},
"modelType": "BE_A_GOOD_ROLE_MODEL",
}
got = target_class.from_api_repr(resource)
assert got.reference == ModelReference.from_string("my-project.my_dataset.my_model")
assert got.model_type == 0
assert got._properties is resource


@pytest.mark.parametrize(
"resource,filter_fields,expected",
[
Expand Down