4
4
5
5
import collections
6
6
import datetime
7
+ import decimal
7
8
import operator
8
9
9
10
from google .cloud .bigquery import schema
@@ -46,6 +47,29 @@ def test_dataframe_to_bigquery_fields_w_named_index(module_under_test):
46
47
),
47
48
],
48
49
),
50
+ # Need to fallback to Arrow to avoid data loss and disambiguate
51
+ # NUMERIC from BIGNUMERIC. We don't want to pick too small of a
52
+ # type and lose precision. See:
53
+ # https://github.com/googleapis/python-bigquery/issues/1650
54
+ #
55
+ (
56
+ "bignumeric_column" ,
57
+ [
58
+ # Start with a lower precision Decimal to make sure we
59
+ # aren't trying to determine the type from just one value.
60
+ decimal .Decimal ("1.25" ),
61
+ decimal .Decimal ("0.1234567891" ),
62
+ ],
63
+ ),
64
+ (
65
+ "numeric_column" ,
66
+ [
67
+ # Minimum value greater than 0 that can be handled: 1e-9
68
+ # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#numeric_types
69
+ decimal .Decimal ("0.000000001" ),
70
+ decimal .Decimal ("-0.000000001" ),
71
+ ],
72
+ ),
49
73
]
50
74
)
51
75
dataframe = pandas .DataFrame (df_data ).set_index ("str_index" , drop = True )
@@ -64,6 +88,8 @@ def test_dataframe_to_bigquery_fields_w_named_index(module_under_test):
64
88
schema .SchemaField ("boolean_column" , "BOOLEAN" , "NULLABLE" ),
65
89
schema .SchemaField ("datetime_column" , "DATETIME" , "NULLABLE" ),
66
90
schema .SchemaField ("timestamp_column" , "TIMESTAMP" , "NULLABLE" ),
91
+ schema .SchemaField ("bignumeric_column" , "BIGNUMERIC" , "NULLABLE" ),
92
+ schema .SchemaField ("numeric_column" , "NUMERIC" , "NULLABLE" ),
67
93
)
68
94
assert returned_schema == expected_schema
69
95
0 commit comments