|
24 | 24 | import google.api_core.retry
|
25 | 25 | import pkg_resources
|
26 | 26 | import pytest
|
| 27 | +import numpy |
27 | 28 |
|
28 | 29 | from google.cloud import bigquery
|
29 | 30 | from . import helpers
|
@@ -84,6 +85,81 @@ def test_load_table_from_dataframe_w_automatic_schema(bigquery_client, dataset_i
|
84 | 85 | ("uint8_col", pandas.Series([0, 1, 2], dtype="uint8")),
|
85 | 86 | ("uint16_col", pandas.Series([3, 4, 5], dtype="uint16")),
|
86 | 87 | ("uint32_col", pandas.Series([6, 7, 8], dtype="uint32")),
|
| 88 | + ("array_bool_col", pandas.Series([[True], [False], [True]])), |
| 89 | + ( |
| 90 | + "array_ts_col", |
| 91 | + pandas.Series( |
| 92 | + [ |
| 93 | + [ |
| 94 | + datetime.datetime( |
| 95 | + 2010, 1, 2, 3, 44, 50, tzinfo=datetime.timezone.utc |
| 96 | + ), |
| 97 | + ], |
| 98 | + [ |
| 99 | + datetime.datetime( |
| 100 | + 2011, 2, 3, 14, 50, 59, tzinfo=datetime.timezone.utc |
| 101 | + ), |
| 102 | + ], |
| 103 | + [ |
| 104 | + datetime.datetime( |
| 105 | + 2012, 3, 14, 15, 16, tzinfo=datetime.timezone.utc |
| 106 | + ), |
| 107 | + ], |
| 108 | + ], |
| 109 | + ), |
| 110 | + ), |
| 111 | + ( |
| 112 | + "array_dt_col", |
| 113 | + pandas.Series( |
| 114 | + [ |
| 115 | + [datetime.datetime(2010, 1, 2, 3, 44, 50)], |
| 116 | + [datetime.datetime(2011, 2, 3, 14, 50, 59)], |
| 117 | + [datetime.datetime(2012, 3, 14, 15, 16)], |
| 118 | + ], |
| 119 | + ), |
| 120 | + ), |
| 121 | + ( |
| 122 | + "array_float32_col", |
| 123 | + pandas.Series( |
| 124 | + [numpy.array([_], dtype="float32") for _ in [1.0, 2.0, 3.0]] |
| 125 | + ), |
| 126 | + ), |
| 127 | + ( |
| 128 | + "array_float64_col", |
| 129 | + pandas.Series( |
| 130 | + [numpy.array([_], dtype="float64") for _ in [4.0, 5.0, 6.0]] |
| 131 | + ), |
| 132 | + ), |
| 133 | + ( |
| 134 | + "array_int8_col", |
| 135 | + pandas.Series( |
| 136 | + [numpy.array([_], dtype="int8") for _ in [-12, -11, -10]] |
| 137 | + ), |
| 138 | + ), |
| 139 | + ( |
| 140 | + "array_int16_col", |
| 141 | + pandas.Series([numpy.array([_], dtype="int16") for _ in [-9, -8, -7]]), |
| 142 | + ), |
| 143 | + ( |
| 144 | + "array_int32_col", |
| 145 | + pandas.Series([numpy.array([_], dtype="int32") for _ in [-6, -5, -4]]), |
| 146 | + ), |
| 147 | + ( |
| 148 | + "array_int64_col", |
| 149 | + pandas.Series([numpy.array([_], dtype="int64") for _ in [-3, -2, -1]]), |
| 150 | + ), |
| 151 | + ( |
| 152 | + "array_uint8_col", |
| 153 | + pandas.Series([numpy.array([_], dtype="uint8") for _ in [0, 1, 2]]), |
| 154 | + ), |
| 155 | + ( |
| 156 | + "array_uint16_col", |
| 157 | + pandas.Series([numpy.array([_], dtype="uint16") for _ in [3, 4, 5]]), |
| 158 | + ), |
| 159 | + ( |
| 160 | + "array_uint32_col", |
| 161 | + pandas.Series([numpy.array([_], dtype="uint32") for _ in [6, 7, 8]]), |
| 162 | + ), |
87 | 163 | ]
|
88 | 164 | )
|
89 | 165 | dataframe = pandas.DataFrame(df_data, columns=df_data.keys())
|
@@ -112,6 +188,21 @@ def test_load_table_from_dataframe_w_automatic_schema(bigquery_client, dataset_i
|
112 | 188 | bigquery.SchemaField("uint8_col", "INTEGER"),
|
113 | 189 | bigquery.SchemaField("uint16_col", "INTEGER"),
|
114 | 190 | bigquery.SchemaField("uint32_col", "INTEGER"),
|
| 191 | + bigquery.SchemaField("array_bool_col", "BOOLEAN", mode="REPEATED"), |
| 192 | + bigquery.SchemaField("array_ts_col", "TIMESTAMP", mode="REPEATED"), |
| 193 | + # BigQuery does not support uploading DATETIME values from |
| 194 | + # Parquet files. See: |
| 195 | + # https://github.com/googleapis/google-cloud-python/issues/9996 |
| 196 | + bigquery.SchemaField("array_dt_col", "TIMESTAMP", mode="REPEATED"), |
| 197 | + bigquery.SchemaField("array_float32_col", "FLOAT", mode="REPEATED"), |
| 198 | + bigquery.SchemaField("array_float64_col", "FLOAT", mode="REPEATED"), |
| 199 | + bigquery.SchemaField("array_int8_col", "INTEGER", mode="REPEATED"), |
| 200 | + bigquery.SchemaField("array_int16_col", "INTEGER", mode="REPEATED"), |
| 201 | + bigquery.SchemaField("array_int32_col", "INTEGER", mode="REPEATED"), |
| 202 | + bigquery.SchemaField("array_int64_col", "INTEGER", mode="REPEATED"), |
| 203 | + bigquery.SchemaField("array_uint8_col", "INTEGER", mode="REPEATED"), |
| 204 | + bigquery.SchemaField("array_uint16_col", "INTEGER", mode="REPEATED"), |
| 205 | + bigquery.SchemaField("array_uint32_col", "INTEGER", mode="REPEATED"), |
115 | 206 | )
|
116 | 207 | assert table.num_rows == 3
|
117 | 208 |
|
|
0 commit comments