Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set pyarrow field nullable to False for a bq field in repeated mode #1999

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/bigquery/_pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def bq_to_arrow_field(bq_field, array_type=None):
# local NULL values. Arrow will gladly interpret these NULL values
# as non-NULL and give you an arbitrary value. See:
# https://github.com/googleapis/python-bigquery/issues/1692
nullable=True,
nullable=False if bq_field.mode.upper() == "REPEATED" else True,
metadata=metadata,
)

Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test__pandas_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,23 @@ def test_bq_to_arrow_field_type_override(module_under_test):
)


@pytest.mark.skipif(isinstance(pyarrow, mock.Mock), reason="Requires `pyarrow`")
def test_bq_to_arrow_field_set_repeated_nullable_false(module_under_test):
assert (
module_under_test.bq_to_arrow_field(
schema.SchemaField("name", "STRING", mode="REPEATED")
).nullable
is False
)

assert (
module_under_test.bq_to_arrow_field(
schema.SchemaField("name", "STRING", mode="NULLABLE")
).nullable
is True
)


@pytest.mark.parametrize(
"field_type, metadata",
[
Expand Down