Skip to content

Commit b599d81

Browse files
make robust to polars missing, change magics name
1 parent 1a0b111 commit b599d81

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

bigframes/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from bigframes.session import connect, Session
2424
from bigframes.version import __version__
2525

26-
_MAGIC_NAMES = ["bigframes"]
26+
_MAGIC_NAMES = ["bigquery_sql"]
2727

2828

2929
def load_ipython_extension(ipython):

bigframes/_magics.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ def _cell_magic(line, cell):
4040
args = magic_arguments.parse_argstring(_cell_magic, line)
4141
if not cell:
4242
print("Query is missing.")
43+
return
4344
pyformat_args = ipython.user_ns
4445
dataframe = bigframes.pandas._read_gbq_colab(
4546
cell, pyformat_args=pyformat_args, dry_run=args.dry_run
4647
)
4748
if args.destination_var:
4849
ipython.push({args.destination_var: dataframe})
4950
else:
50-
display(dataframe)
51-
return dataframe
51+
with bigframes.option_context(
52+
"display.repr_mode",
53+
"anywidget",
54+
):
55+
display(dataframe)
56+
return

bigframes/pandas/io/api.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import pyarrow as pa
5050

5151
import bigframes._config as config
52+
import bigframes._importing
5253
import bigframes.core.global_session as global_session
5354
import bigframes.core.indexes
5455
import bigframes.dataframe
@@ -356,8 +357,12 @@ def _read_gbq_colab(
356357
with warnings.catch_warnings():
357358
# Don't warning about Polars in SQL cell.
358359
# Related to b/437090788.
359-
warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning)
360-
config.options.bigquery.enable_polars_execution = True
360+
try:
361+
bigframes._importing.import_polars()
362+
warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning)
363+
config.options.bigquery.enable_polars_execution = True
364+
except TypeError:
365+
pass # don't fail if polars isn't available
361366

362367
return global_session.with_default_session(
363368
bigframes.session.Session._read_gbq_colab,

tests/system/small/test_magics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import bigframes
2121
import bigframes.pandas as bpd
2222

23-
MAGIC_NAME = "bigframes"
23+
MAGIC_NAME = "bigquery_sql"
2424

2525

2626
@pytest.fixture(scope="module")

0 commit comments

Comments
 (0)