fix: suppress JSONDtypeWarning in Anywidget mode and clean up progres… · googleapis/python-bigquery-dataframes@e0d185a · GitHub
Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit e0d185a

Browse 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

5 files changed

Lines changed: 56 additions & 28 deletions

File tree

bigframes/__init__.py

Lines changed: 20 additions & 7 deletions

bigframes/dataframe.py

Lines 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):

bigframes/display/anywidget.py

Lines 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

bigframes/display/html.py

Lines 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,

bigframes/pandas/io/api.py

Lines changed: 8 additions & 9 deletions

0 commit comments

Comments
 (0)