Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d887714
fix: Respect display.progress_bar=None in background threads
shuoweil Apr 17, 2026
42e4a50
refactor: Refactor BQ event progress bar config
shuoweil Apr 17, 2026
d6757bc
Refactor BQ event progress bar config and add system test
shuoweil Apr 17, 2026
3e8ddde
refactor: refactor code
shuoweil Apr 17, 2026
be825b5
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil Apr 20, 2026
96aaff3
docs: add ignore
shuoweil Apr 20, 2026
bfba719
format file
shuoweil Apr 20, 2026
4ffd647
format file
shuoweil Apr 20, 2026
ffbc397
Roll back .pre-commit-config.yaml changes
shuoweil Apr 20, 2026
27010d3
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil Apr 22, 2026
a6c42af
chore: format files
shuoweil Apr 22, 2026
9742165
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil Apr 29, 2026
cdcbf0c
rename _FALLBACK_TO_GLOBAL to _DEFAULT
shuoweil Apr 29, 2026
c20751b
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 1, 2026
a139c65
format: format code
shuoweil May 1, 2026
85bf48f
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 8, 2026
67c16c6
Apply review comments in events.py
shuoweil May 8, 2026
13b75e7
format code
shuoweil May 8, 2026
7b9f249
format code
shuoweil May 8, 2026
dd69a8d
fix mypy
shuoweil May 8, 2026
a3e4ac5
update code for lint
shuoweil May 8, 2026
f393a0d
format code
shuoweil May 8, 2026
193d33c
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 11, 2026
d001a9b
refactor: remove progress_bar from events
shuoweil May 11, 2026
6377840
refactor: use EventEnvelope for progress_bar context
shuoweil May 11, 2026
5584531
style: fix line length lints in formatting_helpers and __init__
shuoweil May 11, 2026
a7d0171
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 11, 2026
d372472
format file
shuoweil May 12, 2026
8879473
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 12, 2026
457cf84
fix lint
shuoweil May 12, 2026
2339d17
format code
shuoweil May 12, 2026
44dd6de
format code
shuoweil May 12, 2026
5e4dcd8
reformat stubs and fix flake8 E704
shuoweil May 12, 2026
26420bf
Merge branch 'main' into shuowei-anywidget-extraneous-output
shuoweil May 13, 2026
e46c163
chore: add clarifying comment for on_event envelope check
shuoweil May 13, 2026
27bba29
chore: add clarifying comment for formatting_helpers envelope check
shuoweil May 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions packages/bigframes/bigframes/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,21 @@ class BigQuerySentEvent(ExecutionRunning):
location: Optional[str] = None
job_id: Optional[str] = None
request_id: Optional[str] = None
progress_bar: Optional[str] = "fallback_to_global"
Comment thread
shuoweil marked this conversation as resolved.
Outdated

@classmethod
def from_bqclient(cls, event: google.cloud.bigquery._job_helpers.QuerySentEvent):
def from_bqclient(
cls,
event: google.cloud.bigquery._job_helpers.QuerySentEvent,
progress_bar: Optional[str] = "fallback_to_global",
):
return cls(
query=event.query,
billing_project=event.billing_project,
location=event.location,
job_id=event.job_id,
request_id=event.request_id,
progress_bar=progress_bar,
)


Expand All @@ -146,15 +152,21 @@ class BigQueryRetryEvent(ExecutionRunning):
location: Optional[str] = None
job_id: Optional[str] = None
request_id: Optional[str] = None
progress_bar: Optional[str] = "fallback_to_global"

@classmethod
def from_bqclient(cls, event: google.cloud.bigquery._job_helpers.QueryRetryEvent):
def from_bqclient(
cls,
event: google.cloud.bigquery._job_helpers.QueryRetryEvent,
progress_bar: Optional[str] = "fallback_to_global",
):
return cls(
query=event.query,
billing_project=event.billing_project,
location=event.location,
job_id=event.job_id,
request_id=event.request_id,
progress_bar=progress_bar,
)


Expand All @@ -171,10 +183,13 @@ class BigQueryReceivedEvent(ExecutionRunning):
created: Optional[datetime.datetime] = None
started: Optional[datetime.datetime] = None
ended: Optional[datetime.datetime] = None
progress_bar: Optional[str] = "fallback_to_global"

@classmethod
def from_bqclient(
cls, event: google.cloud.bigquery._job_helpers.QueryReceivedEvent
cls,
event: google.cloud.bigquery._job_helpers.QueryReceivedEvent,
progress_bar: Optional[str] = "fallback_to_global",
):
return cls(
billing_project=event.billing_project,
Expand All @@ -186,6 +201,7 @@ def from_bqclient(
created=event.created,
started=event.started,
ended=event.ended,
progress_bar=progress_bar,
)


Expand All @@ -204,10 +220,13 @@ class BigQueryFinishedEvent(ExecutionRunning):
created: Optional[datetime.datetime] = None
started: Optional[datetime.datetime] = None
ended: Optional[datetime.datetime] = None
progress_bar: Optional[str] = "fallback_to_global"

@classmethod
def from_bqclient(
cls, event: google.cloud.bigquery._job_helpers.QueryFinishedEvent
cls,
event: google.cloud.bigquery._job_helpers.QueryFinishedEvent,
progress_bar: Optional[str] = "fallback_to_global",
):
return cls(
billing_project=event.billing_project,
Expand All @@ -221,6 +240,7 @@ def from_bqclient(
created=event.created,
started=event.started,
ended=event.ended,
progress_bar=progress_bar,
)


Expand Down
5 changes: 4 additions & 1 deletion packages/bigframes/bigframes/formatting_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def progress_callback(
# This will allow cleanup to continue.
return

progress_bar = bigframes._config.options.display.progress_bar
# Prioritize progress_bar set on the event, falling back to thread-local option.
progress_bar = getattr(event, "progress_bar", "fallback_to_global")
if progress_bar == "fallback_to_global":
progress_bar = bigframes._config.options.display.progress_bar

if progress_bar == "auto":
progress_bar = "notebook" if in_ipython() else "terminal"
Expand Down
32 changes: 24 additions & 8 deletions packages/bigframes/bigframes/session/_io/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,27 @@ def add_and_trim_labels(job_config, session=None):


def create_bq_event_callback(publisher):
import bigframes._config

progress_bar = bigframes._config.options.display.progress_bar

def publish_bq_event(event):
if isinstance(event, google.cloud.bigquery._job_helpers.QueryFinishedEvent):
bf_event = bigframes.core.events.BigQueryFinishedEvent.from_bqclient(event)
bf_event = bigframes.core.events.BigQueryFinishedEvent.from_bqclient(
event, progress_bar=progress_bar
)
elif isinstance(event, google.cloud.bigquery._job_helpers.QueryReceivedEvent):
bf_event = bigframes.core.events.BigQueryReceivedEvent.from_bqclient(event)
bf_event = bigframes.core.events.BigQueryReceivedEvent.from_bqclient(
event, progress_bar=progress_bar
)
elif isinstance(event, google.cloud.bigquery._job_helpers.QueryRetryEvent):
bf_event = bigframes.core.events.BigQueryRetryEvent.from_bqclient(event)
bf_event = bigframes.core.events.BigQueryRetryEvent.from_bqclient(
event, progress_bar=progress_bar
)
elif isinstance(event, google.cloud.bigquery._job_helpers.QuerySentEvent):
bf_event = bigframes.core.events.BigQuerySentEvent.from_bqclient(event)
bf_event = bigframes.core.events.BigQuerySentEvent.from_bqclient(
event, progress_bar=progress_bar
)
else:
bf_event = bigframes.core.events.BigQueryUnknownEvent(event)
Comment thread
shuoweil marked this conversation as resolved.
Outdated

Expand All @@ -275,7 +287,8 @@ def start_query_with_client(
query_with_job: Literal[True],
publisher: bigframes.core.events.Publisher,
session=None,
) -> Tuple[google.cloud.bigquery.table.RowIterator, bigquery.QueryJob]: ...
) -> Tuple[google.cloud.bigquery.table.RowIterator, bigquery.QueryJob]:
...


@overload
Expand All @@ -291,7 +304,8 @@ def start_query_with_client(
query_with_job: Literal[False],
publisher: bigframes.core.events.Publisher,
session=None,
) -> Tuple[google.cloud.bigquery.table.RowIterator, Optional[bigquery.QueryJob]]: ...
) -> Tuple[google.cloud.bigquery.table.RowIterator, Optional[bigquery.QueryJob]]:
...


@overload
Expand All @@ -308,7 +322,8 @@ def start_query_with_client(
job_retry: google.api_core.retry.Retry,
publisher: bigframes.core.events.Publisher,
session=None,
) -> Tuple[google.cloud.bigquery.table.RowIterator, bigquery.QueryJob]: ...
) -> Tuple[google.cloud.bigquery.table.RowIterator, bigquery.QueryJob]:
...


@overload
Expand All @@ -325,7 +340,8 @@ def start_query_with_client(
job_retry: google.api_core.retry.Retry,
publisher: bigframes.core.events.Publisher,
session=None,
) -> Tuple[google.cloud.bigquery.table.RowIterator, Optional[bigquery.QueryJob]]: ...
) -> Tuple[google.cloud.bigquery.table.RowIterator, Optional[bigquery.QueryJob]]:
...


def start_query_with_client(
Expand Down
25 changes: 25 additions & 0 deletions packages/bigframes/tests/unit/test_formatting_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,28 @@ def test_get_job_url():
job_id=job_id, location=location, project_id=project_id
)
assert actual_url == expected_url


def test_progress_callback_respects_event_progress_bar():
event = bfevents.BigQuerySentEvent(
query="SELECT * FROM my_table",
progress_bar=None,
)

with mock.patch("bigframes._config.options.display.progress_bar", "terminal"):
with mock.patch("bigframes.formatting_helpers.in_ipython", return_value=False):
with mock.patch("builtins.print") as mock_print:
formatting_helpers.progress_callback(event)
mock_print.assert_not_called()


def test_progress_callback_falls_back_to_global():
event = bfevents.BigQuerySentEvent(
query="SELECT * FROM my_table",
)

with mock.patch("bigframes._config.options.display.progress_bar", "terminal"):
with mock.patch("bigframes.formatting_helpers.in_ipython", return_value=False):
with mock.patch("builtins.print") as mock_print:
formatting_helpers.progress_callback(event)
mock_print.assert_called_once()
Loading