|
2 | 2 | # Use of this source code is governed by a BSD-style
|
3 | 3 | # license that can be found in the LICENSE file.
|
4 | 4 |
|
| 5 | +from google.cloud import bigquery |
5 | 6 | import pyarrow
|
| 7 | +import pytest |
6 | 8 |
|
7 | 9 | from pandas_gbq.schema import pyarrow_to_bigquery
|
8 | 10 |
|
9 | 11 |
|
| 12 | +@pytest.mark.parametrize( |
| 13 | + ( |
| 14 | + "pyarrow_type", |
| 15 | + "bigquery_type", |
| 16 | + ), |
| 17 | + ( |
| 18 | + # All integer types should map to BigQuery INT64 (or INTEGER since |
| 19 | + # SchemaField uses the legacy SQL names). See: |
| 20 | + # https://github.com/googleapis/python-bigquery-pandas/issues/616 |
| 21 | + (pyarrow.int8(), "INTEGER"), |
| 22 | + (pyarrow.int16(), "INTEGER"), |
| 23 | + (pyarrow.int32(), "INTEGER"), |
| 24 | + (pyarrow.int64(), "INTEGER"), |
| 25 | + (pyarrow.uint8(), "INTEGER"), |
| 26 | + (pyarrow.uint16(), "INTEGER"), |
| 27 | + (pyarrow.uint32(), "INTEGER"), |
| 28 | + (pyarrow.uint64(), "INTEGER"), |
| 29 | + # If there is no associated timezone, assume a naive (timezone-less) |
| 30 | + # DATETIME. See: |
| 31 | + # https://github.com/googleapis/python-bigquery-pandas/issues/450 |
| 32 | + (pyarrow.timestamp("ns"), "DATETIME"), |
| 33 | + (pyarrow.timestamp("ns", tz="UTC"), "TIMESTAMP"), |
| 34 | + ), |
| 35 | +) |
| 36 | +def test_arrow_type_to_bigquery_field_scalar_types(pyarrow_type, bigquery_type): |
| 37 | + field: bigquery.SchemaField = pyarrow_to_bigquery.arrow_type_to_bigquery_field( |
| 38 | + "test_name", pyarrow_type |
| 39 | + ) |
| 40 | + assert field.name == "test_name" |
| 41 | + assert field.field_type == bigquery_type |
| 42 | + |
| 43 | + |
10 | 44 | def test_arrow_type_to_bigquery_field_unknown():
|
11 |
| - # Default types should be picked at a higher layer. |
12 | 45 | assert (
|
13 | 46 | pyarrow_to_bigquery.arrow_type_to_bigquery_field("test_name", pyarrow.null())
|
14 | 47 | is None
|
15 | 48 | )
|
16 | 49 |
|
17 | 50 |
|
18 | 51 | def test_arrow_type_to_bigquery_field_list_of_unknown():
|
19 |
| - # Default types should be picked at a higher layer. |
20 | 52 | assert (
|
21 | 53 | pyarrow_to_bigquery.arrow_type_to_bigquery_field(
|
22 | 54 | "test_name", pyarrow.list_(pyarrow.null())
|
|
0 commit comments