Skip to content

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

Merged
merged 6 commits into from
Mar 12, 2019

Conversation

JohnPaton
Copy link
Contributor

This PR:

  • Adds a function to pandas_gbq.schema, update_schema which takes and old schema and a new one, updating any existing fields and adding any new ones
  • Generates the default schema using schema.generate_bq_schema for every DataFrame passed to to_gbq, and if a table_schema is passed, this schema is used to update the generated schema. This way custom provided fields in table_schema are added, and missing fields fall back to the generated defaults.

This is the functionality requested in #218

Copy link
Contributor

@max-sixty max-sixty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I think enabling schema 'overrides' is a good feature.

I left one question about the code, but the tests look great, so assuming they pass 👍

def _update_bq_schema(schema_old, schema_new):
from pandas_gbq import schema

return schema.update_schema(schema_old, schema_new)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this function? Should we import from schema directly? Or there's a circular import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just following the pattern used for the only other schema function, which is imported the same way in gbq._generate_bq_schema. As far as I'm concerned it's fine to get rid of it. Let me know and I'll make the change.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_generate_bq_schema is only in gbq.py for backwards compatibility. We should use the update_schema method from the schema module directly.

I've sent #259 to clean this up (and also improve the docs for this feature).

@max-sixty
Copy link
Contributor

Great!

Any thoughts @tswast ?

@max-sixty
Copy link
Contributor

@JohnPaton Want to add a Whatsnew? Feel free to add you GH handle

@JohnPaton
Copy link
Contributor Author

@max-sixty Done! I didn't see any other handles in the Changelog so if that's not what you meant just let me know 😆

@max-sixty max-sixty merged commit 547812e into googleapis:master Mar 12, 2019
@max-sixty
Copy link
Contributor

Many thanks @JohnPaton !

@tswast
Copy link
Collaborator

tswast commented Mar 15, 2019

Thanks a bunch for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants