-
Notifications
You must be signed in to change notification settings - Fork 69
feat!: automatically register the BigQuery magics when bigframes is imported #1231
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # Copyright 2024 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import bigquery_magics # type: ignore | ||
| import bigquery_magics.config # type: ignore | ||
|
|
||
|
|
||
| def load_ipython_extension(ipython): | ||
| """Called by IPython when this module is loaded as an IPython extension.""" | ||
| bigquery_magics.load_ipython_extension(ipython) | ||
|
Contributor
Author
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. Alternatively, check if it is registered already before calling this and break early. |
||
|
|
||
| if bigquery_magics.context.credentials is not None: | ||
|
Contributor
Author
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. 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. |
||
| # 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() | ||
|
Comment on lines
+23
to
+30
Contributor
Author
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. DELETE ME
Contributor
Author
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. 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) |
||
|
|
||
|
|
||
| class Context(bigquery_magics.config.Context): | ||
| """A provider for bigquery-magics configuration, derived from bigframes | ||
| global options and global default session. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| pass | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # IMPORTANT: When Python 3.10 support is dropped, update these to | ||
| # match the minimums in setup.py. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # IMPORTANT: When Python 3.11 support is dropped, update these to | ||
| # match the minimums in setup.py. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # IMPORTANT: When Python 3.12 support is dropped, update these to | ||
| # match the minimums in setup.py. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an unload function that undoes any bigframes-specific configuration of
%%bigquerySee:
unload_ipython_extensionin https://ipython.readthedocs.io/en/stable/config/extensions/#writing-extensions