Skip to content

Commit 5352870

Browse files
xyloidLinchin
andauthored
fix: set pyarrow field nullable to False for a BigQuery field in REPEATED mode (#1999)
Co-authored-by: Lingqing Gan <[email protected]>
1 parent edcb79c commit 5352870

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

google/cloud/bigquery/_pandas_helpers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def bq_to_arrow_field(bq_field, array_type=None):
200200
# local NULL values. Arrow will gladly interpret these NULL values
201201
# as non-NULL and give you an arbitrary value. See:
202202
# https://github.com/googleapis/python-bigquery/issues/1692
203-
nullable=True,
203+
nullable=False if bq_field.mode.upper() == "REPEATED" else True,
204204
metadata=metadata,
205205
)
206206

tests/unit/test__pandas_helpers.py

+17
Original file line numberDiff line numberDiff line change
@@ -2002,6 +2002,23 @@ def test_bq_to_arrow_field_type_override(module_under_test):
20022002
)
20032003

20042004

2005+
@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`")
2006+
def test_bq_to_arrow_field_set_repeated_nullable_false(module_under_test):
2007+
assert (
2008+
module_under_test.bq_to_arrow_field(
2009+
schema.SchemaField("name", "STRING", mode="REPEATED")
2010+
).nullable
2011+
is False
2012+
)
2013+
2014+
assert (
2015+
module_under_test.bq_to_arrow_field(
2016+
schema.SchemaField("name", "STRING", mode="NULLABLE")
2017+
).nullable
2018+
is True
2019+
)
2020+
2021+
20052022
@pytest.mark.parametrize(
20062023
"field_type, metadata",
20072024
[

0 commit comments

Comments
 (0)