Skip to content

Commit c0e4595

Browse files
committed
docstring and tests
1 parent f87b618 commit c0e4595

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

google/cloud/bigquery/schema.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class SchemaField(object):
197197
Only valid for top-level schema fields (not nested fields).
198198
If the type is FOREIGN, this field is required.
199199
200-
timestamp_precision: Union[enums.TimestampPrecision, int, None]
200+
timestamp_precision: Optional[enums.TimestampPrecision]
201201
Precision (maximum number of total digits in base 10) for seconds
202202
of TIMESTAMP type.
203203
@@ -391,9 +391,12 @@ def policy_tags(self):
391391
return PolicyTagList.from_api_repr(resource) if resource is not None else None
392392

393393
@property
394-
def timestamp_precision(self):
395-
"""Union[enums.TimestampPrecision, int, None]: Precision (maximum number
396-
of total digits in base 10) for seconds of TIMESTAMP type.
394+
def timestamp_precision(self) -> enums.TimestampPrecision:
395+
"""Precision (maximum number of total digits in base 10) for seconds of
396+
TIMESTAMP type.
397+
398+
Returns:
399+
enums.TimestampPrecision: value of TimestampPrecision.
397400
"""
398401
return enums.TimestampPrecision(self._properties.get("timestampPrecision"))
399402

tests/unit/test_schema.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def test_from_api_repr(self):
223223
"name": "foo",
224224
"type": "record",
225225
"roundingMode": "ROUNDING_MODE_UNSPECIFIED",
226-
"timestampPrecision": enums.TimestampPrecision.PICOSECOND,
226+
"timestampPrecision": 12,
227227
}
228228
)
229229
self.assertEqual(field.name, "foo")
@@ -237,7 +237,7 @@ def test_from_api_repr(self):
237237
self.assertEqual(field.range_element_type, None)
238238
self.assertEqual(field.rounding_mode, "ROUNDING_MODE_UNSPECIFIED")
239239
self.assertEqual(
240-
field._properties["timestampPrecision"],
240+
field.timestamp_precision,
241241
enums.TimestampPrecision.PICOSECOND,
242242
)
243243

@@ -356,7 +356,9 @@ def test_foreign_type_definition_property_str(self):
356356
def test_timestamp_precision_property(self):
357357
TIMESTAMP_PRECISION = enums.TimestampPrecision.PICOSECOND
358358
schema_field = self._make_one("test", "TIMESTAMP")
359-
schema_field._properties["timestampPrecision"] = TIMESTAMP_PRECISION
359+
schema_field._properties[
360+
"timestampPrecision"
361+
] = enums.TimestampPrecision.PICOSECOND.value
360362
self.assertEqual(schema_field.timestamp_precision, TIMESTAMP_PRECISION)
361363

362364
def test_to_standard_sql_simple_type(self):

0 commit comments

Comments
 (0)