@@ -221,7 +221,7 @@ def __init__(
221221 range_element_type : Union [FieldElementType , str , None ] = None ,
222222 rounding_mode : Union [enums .RoundingMode , str , None ] = None ,
223223 foreign_type_definition : Optional [str ] = None ,
224- timestamp_precision : Union [enums .TimestampPrecision , int , None ] = None ,
224+ timestamp_precision : Optional [enums .TimestampPrecision ] = None ,
225225 ):
226226 self ._properties : Dict [str , Any ] = {
227227 "name" : name ,
@@ -246,8 +246,13 @@ def __init__(
246246 if isinstance (policy_tags , PolicyTagList )
247247 else None
248248 )
249- if timestamp_precision is not None :
250- self ._properties ["timestampPrecision" ] = timestamp_precision
249+ if isinstance (timestamp_precision , enums .TimestampPrecision ):
250+ self ._properties ["timestampPrecision" ] = timestamp_precision .value
251+ elif timestamp_precision is not None :
252+ raise ValueError (
253+ "timestamp_precision must be class enums.TimestampPrecision "
254+ f"or None, got { type (timestamp_precision )} instead."
255+ )
251256 if isinstance (range_element_type , str ):
252257 self ._properties ["rangeElementType" ] = {"type" : range_element_type }
253258 if isinstance (range_element_type , FieldElementType ):
@@ -390,7 +395,7 @@ def timestamp_precision(self):
390395 """Union[enums.TimestampPrecision, int, None]: Precision (maximum number
391396 of total digits in base 10) for seconds of TIMESTAMP type.
392397 """
393- return _helpers . _int_or_none (self ._properties .get ("timestampPrecision" ))
398+ return enums . TimestampPrecision (self ._properties .get ("timestampPrecision" ))
394399
395400 def to_api_repr (self ) -> dict :
396401 """Return a dictionary representing this schema field.
@@ -426,6 +431,8 @@ def _key(self):
426431 None if self .policy_tags is None else tuple (sorted (self .policy_tags .names ))
427432 )
428433
434+ timestamp_precision = self ._properties .get ("timestampPrecision" )
435+
429436 return (
430437 self .name ,
431438 field_type ,
@@ -435,7 +442,7 @@ def _key(self):
435442 self .description ,
436443 self .fields ,
437444 policy_tags ,
438- self . timestamp_precision ,
445+ timestamp_precision ,
439446 )
440447
441448 def to_standard_sql (self ) -> standard_sql .StandardSqlField :
@@ -548,9 +555,11 @@ def _to_schema_fields(schema):
548555 if isinstance (schema , Sequence ):
549556 # Input is a Sequence (e.g. a list): Process and return a list of SchemaFields
550557 return [
551- field
552- if isinstance (field , SchemaField )
553- else SchemaField .from_api_repr (field )
558+ (
559+ field
560+ if isinstance (field , SchemaField )
561+ else SchemaField .from_api_repr (field )
562+ )
554563 for field in schema
555564 ]
556565
0 commit comments