Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb401bd

Browse files
feat: add to_api_repr method to Model (#326)
1 parent3be78b7 commitfb401bd

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

‎google/cloud/bigquery/model.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,14 @@ def _build_resource(self, filter_fields):
317317
def__repr__(self):
318318
return"Model(reference={})".format(repr(self.reference))
319319

320+
defto_api_repr(self):
321+
"""Construct the API resource representation of this model.
322+
323+
Returns:
324+
Dict[str, object]: Model reference represented as an API resource
325+
"""
326+
returnjson_format.MessageToDict(self._proto)
327+
320328

321329
classModelReference(object):
322330
"""ModelReferences are pointers to models.

‎tests/unit/model/test_model.py‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,47 @@ def test_repr(target_class):
318318
"Model(reference=ModelReference("
319319
"project_id='my-proj', dataset_id='my_dset', model_id='my_model'))"
320320
)
321+
322+
323+
deftest_to_api_repr(target_class):
324+
fromgoogle.protobufimportjson_format
325+
326+
model=target_class("my-proj.my_dset.my_model")
327+
resource= {
328+
"etag":"abcdefg",
329+
"modelReference": {
330+
"projectId":"my-project",
331+
"datasetId":"my_dataset",
332+
"modelId":"my_model",
333+
},
334+
"creationTime":"1274284800000",
335+
"lastModifiedTime":"1317484800000",
336+
"modelType":"LOGISTIC_REGRESSION",
337+
"trainingRuns": [
338+
{
339+
"trainingOptions": {"initialLearnRate":1.0},
340+
"startTime":"2010-05-19T16:00:00Z",
341+
},
342+
{
343+
"trainingOptions": {"initialLearnRate":0.5},
344+
"startTime":"2011-10-01T16:00:00Z",
345+
},
346+
{
347+
"trainingOptions": {"initialLearnRate":0.25},
348+
"startTime":"2012-12-21T16:00:00Z",
349+
},
350+
],
351+
"description":"A friendly description.",
352+
"location":"US",
353+
"friendlyName":"A friendly name.",
354+
"labels": {"greeting":"こんにちは"},
355+
"expirationTime":"1356105600000",
356+
"encryptionConfiguration": {
357+
"kmsKeyName":"projects/1/locations/us/keyRings/1/cryptoKeys/1"
358+
},
359+
}
360+
model._proto=json_format.ParseDict(
361+
resource,types.Model()._pb,ignore_unknown_fields=True
362+
)
363+
got=model.to_api_repr()
364+
assertgot==resource

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp