-
Notifications
You must be signed in to change notification settings - Fork 125
ENH: Allow partial table schema in to_gbq() table_schema (#218) #257
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
Changes from all commits
a62b190
1d98d2b
34de9e5
ef46a83
5a797a0
6856d05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -939,9 +939,11 @@ def to_gbq( | |
'STRING'},...]``. | ||
If schema is not provided, it will be | ||
generated according to dtypes of DataFrame columns. | ||
If schema is provided, it must contain all DataFrame columns. | ||
pandas_gbq.gbq._generate_bq_schema() may be used to create an initial | ||
schema, though it doesn't preserve column order. | ||
If schema is provided, it may contain all or a subset of DataFrame | ||
columns. If a subset is provided, the rest will be inferred from | ||
the DataFrame dtypes. | ||
pandas_gbq.gbq._generate_bq_schema() may be used to create an | ||
initial schema, though it doesn't preserve column order. | ||
See BigQuery API documentation on available names of a field. | ||
|
||
.. versionadded:: 0.3.1 | ||
|
@@ -1023,10 +1025,13 @@ def to_gbq( | |
credentials=connector.credentials, | ||
) | ||
|
||
default_schema = _generate_bq_schema(dataframe) | ||
if not table_schema: | ||
table_schema = _generate_bq_schema(dataframe) | ||
table_schema = default_schema | ||
else: | ||
table_schema = dict(fields=table_schema) | ||
table_schema = _update_bq_schema( | ||
default_schema, dict(fields=table_schema) | ||
) | ||
|
||
# If table exists, check if_exists parameter | ||
if table.exists(table_id): | ||
|
@@ -1091,6 +1096,12 @@ def _generate_bq_schema(df, default_type="STRING"): | |
return schema.generate_bq_schema(df, default_type=default_type) | ||
|
||
|
||
def _update_bq_schema(schema_old, schema_new): | ||
from pandas_gbq import schema | ||
|
||
return schema.update_schema(schema_old, schema_new) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this function? Should we import from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just following the pattern used for the only other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll defer to Chesterton's fence; we can clean up later if @tswast knows There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've sent #259 to clean this up (and also improve the docs for this feature). |
||
|
||
|
||
class _Table(GbqConnector): | ||
def __init__( | ||
self, | ||
|
Uh oh!
There was an error while loading. Please reload this page.