feat!: automatically register the BigQuery magics when bigframes is imported#1231
feat!: automatically register the BigQuery magics when bigframes is imported#1231
Conversation
…mported BREAKING-CHANGE: notebooks that mix the %%bigquery / %%bqsql magics and the bigframes module will use bigframes for DataFrame output by default
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
| if bigquery_magics.context.credentials is not None: | ||
| # The %%bigquery magics must have been run before BigQuery DataFrames | ||
| # was imported. In this case, we don't want to break any existing | ||
| # notebooks, so don't make any BigQuery DataFrames changes to the | ||
| # magics. | ||
| return | ||
|
|
||
| bigquery_magics.context = Context() |
There was a problem hiding this comment.
Actually, just delete this last part. Set the engine and default variable if we make it this far (e.g. the magics haven't been used yet)
| """Called by IPython when this module is loaded as an IPython extension.""" | ||
| bigquery_magics.load_ipython_extension(ipython) | ||
|
|
||
| if bigquery_magics.context.credentials is not None: |
There was a problem hiding this comment.
pandas-gbq sets the default credentials in-memory after the first run, but it doesn't look like the magics have any such feature yet.
TODO: bigquery-magics to cache the credentials and/or client objects after the first.
|
|
||
| def load_ipython_extension(ipython): | ||
| """Called by IPython when this module is loaded as an IPython extension.""" | ||
| bigquery_magics.load_ipython_extension(ipython) |
There was a problem hiding this comment.
Alternatively, check if it is registered already before calling this and break early.
| from bigframes.version import __version__ | ||
|
|
||
|
|
||
| def load_ipython_extension(ipython): |
There was a problem hiding this comment.
Consider adding an unload function that undoes any bigframes-specific configuration of %%bigquery
See: unload_ipython_extension in https://ipython.readthedocs.io/en/stable/config/extensions/#writing-extensions
|
Decided against this to:
|
BREAKING-CHANGE: notebooks that mix the %%bigquery / %%bqsql magics and the bigframes module will use bigframes for DataFrame output by default
Release-As: 1.30.0
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 internal issue 384564457 🦕