feat: allow loading table from dataframe with extra fields, #1812 #2165
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕
#1812
Overview
This pull request introduces a change to the behavior of the
dataframe_to_bq_schema
function ingoogle.cloud.bigquery._pandas_helpers
, allowing extra fields in thebq_schema
that are not present in the DataFrame. Instead of raising an error, a warning is issued, and the extra fields are included in the resulting schema. Additionally, a new test is added to validate this behavior.Changes to
dataframe_to_bq_schema
behavior:UserWarning
instead of raising aValueError
whenbq_schema
contains fields not found in the DataFrame. These extra fields are now appended to the resulting schema. (google/cloud/bigquery/_pandas_helpers.py
, google/cloud/bigquery/_pandas_helpers.pyL540-R551)bq_schema
. (google/cloud/bigquery/_pandas_helpers.py
, google/cloud/bigquery/_pandas_helpers.pyR487-R490)Testing updates:
test_dataframe_to_bq_schema_allows_extra_fields
, to verify that the function correctly handles extra fields inbq_schema
by issuing a warning and including the fields in the output schema. (tests/unit/test__pandas_helpers.py
, tests/unit/test__pandas_helpers.pyR1388-R1421)