Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit e0d185a

Browse filesBrowse files
authored
fix: suppress JSONDtypeWarning in Anywidget mode and clean up progress output (#2441)
This PR improves the user experience when using the interactive anywidget display mode (bpd.options.display.repr_mode = "anywidget") by reducing console noise. Verified at: vs code notebook: screen/ACCJRLwyThciMk8 colab notebook: screen/BhNxzpvckYg9Wp8 Fixes #<482120359> 🦕
1 parent 2017cc2 commit e0d185a
Copy full SHA for e0d185a

5 files changed

+56-28Lines changed: 56 additions & 28 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bigframes/__init__.py‎

Copy file name to clipboardExpand all lines: bigframes/__init__.py
+20-7Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@
1414

1515
"""BigQuery DataFrames provides a DataFrame API scaled by the BigQuery engine."""
1616

17-
from bigframes._config import option_context, options
18-
from bigframes._config.bigquery_options import BigQueryOptions
19-
from bigframes.core.global_session import close_session, get_global_session
20-
import bigframes.enums as enums
21-
import bigframes.exceptions as exceptions
22-
from bigframes.session import connect, Session
23-
from bigframes.version import __version__
17+
import warnings
18+
19+
# Suppress Python version support warnings from google-cloud libraries.
20+
# These are particularly noisy in Colab which still uses Python 3.10.
21+
warnings.filterwarnings(
22+
"ignore",
23+
category=FutureWarning,
24+
message=".*Google will stop supporting.*Python.*",
25+
)
26+
27+
from bigframes._config import option_context, options # noqa: E402
28+
from bigframes._config.bigquery_options import BigQueryOptions # noqa: E402
29+
from bigframes.core.global_session import ( # noqa: E402
30+
close_session,
31+
get_global_session,
32+
)
33+
import bigframes.enums as enums # noqa: E402
34+
import bigframes.exceptions as exceptions # noqa: E402
35+
from bigframes.session import connect, Session # noqa: E402
36+
from bigframes.version import __version__ # noqa: E402
2437

2538
_MAGIC_NAMES = ["bqsql"]
2639

Collapse file

‎bigframes/dataframe.py‎

Copy file name to clipboardExpand all lines: bigframes/dataframe.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def dtypes(self) -> pandas.Series:
332332

333333
@property
334334
def columns(self) -> pandas.Index:
335-
return self.dtypes.index
335+
return self._block.column_labels
336336

337337
@columns.setter
338338
def columns(self, labels: pandas.Index):
Collapse file

‎bigframes/display/anywidget.py‎

Copy file name to clipboardExpand all lines: bigframes/display/anywidget.py
+20-10Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import threading
2424
from typing import Any, Iterator, Optional
2525
import uuid
26+
import warnings
2627

2728
import pandas as pd
2829

@@ -111,23 +112,32 @@ def __init__(self, dataframe: bigframes.dataframe.DataFrame):
111112
self.page_size = initial_page_size
112113
self.max_columns = initial_max_columns
113114

114-
# TODO(b/469861913): Nested columns from structs (e.g., 'struct_col.name') are not currently sortable.
115-
# TODO(b/463754889): Support non-string column labels for sorting.
116-
if all(isinstance(col, str) for col in dataframe.columns):
117-
self.orderable_columns = [
118-
str(col_name)
119-
for col_name, dtype in dataframe.dtypes.items()
120-
if dtypes.is_orderable(dtype)
121-
]
122-
else:
123-
self.orderable_columns = []
115+
self.orderable_columns = self._get_orderable_columns(dataframe)
124116

125117
self._initial_load()
126118

127119
# Signals to the frontend that the initial data load is complete.
128120
# Also used as a guard to prevent observers from firing during initialization.
129121
self._initial_load_complete = True
130122

123+
def _get_orderable_columns(
124+
self, dataframe: bigframes.dataframe.DataFrame
125+
) -> list[str]:
126+
"""Determine which columns can be used for client-side sorting."""
127+
# TODO(b/469861913): Nested columns from structs (e.g., 'struct_col.name') are not currently sortable.
128+
# TODO(b/463754889): Support non-string column labels for sorting.
129+
if not all(isinstance(col, str) for col in dataframe.columns):
130+
return []
131+
132+
with warnings.catch_warnings():
133+
warnings.simplefilter("ignore", bigframes.exceptions.JSONDtypeWarning)
134+
warnings.simplefilter("ignore", category=FutureWarning)
135+
return [
136+
str(col_name)
137+
for col_name, dtype in dataframe.dtypes.items()
138+
if dtypes.is_orderable(dtype)
139+
]
140+
131141
def _initial_load(self) -> None:
132142
"""Get initial data and row count."""
133143
# obtain the row counts
Collapse file

‎bigframes/display/html.py‎

Copy file name to clipboardExpand all lines: bigframes/display/html.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,13 @@ def repr_mimebundle(
363363

364364
if opts.repr_mode == "anywidget":
365365
try:
366-
return get_anywidget_bundle(obj, include=include, exclude=exclude)
366+
with bigframes.option_context("display.progress_bar", None):
367+
with warnings.catch_warnings():
368+
warnings.simplefilter(
369+
"ignore", category=bigframes.exceptions.JSONDtypeWarning
370+
)
371+
warnings.simplefilter("ignore", category=FutureWarning)
372+
return get_anywidget_bundle(obj, include=include, exclude=exclude)
367373
except ImportError:
368374
# Anywidget is an optional dependency, so warn rather than fail.
369375
# TODO(shuowei): When Anywidget becomes the default for all repr modes,
Collapse file

‎bigframes/pandas/io/api.py‎

Copy file name to clipboardExpand all lines: bigframes/pandas/io/api.py
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,14 @@ def _read_gbq_colab(
354354
)
355355
_set_default_session_location_if_possible_deferred_query(create_query)
356356
if not config.options.bigquery._session_started:
357-
with warnings.catch_warnings():
358-
# Don't warning about Polars in SQL cell.
359-
# Related to b/437090788.
360-
try:
361-
bigframes._importing.import_polars()
362-
warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning)
363-
config.options.bigquery.enable_polars_execution = True
364-
except ImportError:
365-
pass # don't fail if polars isn't available
357+
# Don't warning about Polars in SQL cell.
358+
# Related to b/437090788.
359+
try:
360+
bigframes._importing.import_polars()
361+
warnings.simplefilter("ignore", bigframes.exceptions.PreviewWarning)
362+
config.options.bigquery.enable_polars_execution = True
363+
except ImportError:
364+
pass # don't fail if polars isn't available
366365

367366
return global_session.with_default_session(
368367
bigframes.session.Session._read_gbq_colab,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.