Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 938fb89

Browse files
committed
tweak imports so I can manually run doctest
pytest --doctest-modules bigframes/session/__init__.py::bigframes.session.Session.read_gbq_query
1 parent 10a8302 commit 938fb89

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

bigframes/pandas/io/api.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,11 @@ def from_glob_path(
625625

626626

627627
def _get_bqclient() -> bigquery.Client:
628-
clients_provider = bigframes.session.clients.ClientsProvider(
628+
# Address circular imports in doctest due to bigframes/session/__init__.py
629+
# containing a lot of logic and samples.
630+
from bigframes.session import clients
631+
632+
clients_provider = clients.ClientsProvider(
629633
project=config.options.bigquery.project,
630634
location=config.options.bigquery.location,
631635
use_regional_endpoints=config.options.bigquery.use_regional_endpoints,
@@ -639,11 +643,15 @@ def _get_bqclient() -> bigquery.Client:
639643

640644

641645
def _dry_run(query, bqclient) -> bigquery.QueryJob:
646+
# Address circular imports in doctest due to bigframes/session/__init__.py
647+
# containing a lot of logic and samples.
648+
from bigframes.session import metrics as bf_metrics
649+
642650
job = bqclient.query(query, bigquery.QueryJobConfig(dry_run=True))
643651

644652
# Fix for b/435183833. Log metrics even if a Session isn't available.
645-
if bigframes.session.metrics.LOGGING_NAME_ENV_VAR in os.environ:
646-
metrics = bigframes.session.metrics.ExecutionMetrics()
653+
if bf_metrics.LOGGING_NAME_ENV_VAR in os.environ:
654+
metrics = bf_metrics.ExecutionMetrics()
647655
metrics.count_job_stats(job)
648656
return job
649657

@@ -653,6 +661,10 @@ def _set_default_session_location_if_possible(query):
653661

654662

655663
def _set_default_session_location_if_possible_deferred_query(create_query):
664+
# Address circular imports in doctest due to bigframes/session/__init__.py
665+
# containing a lot of logic and samples.
666+
from bigframes.session._io import bigquery
667+
656668
# Set the location as per the query if this is the first query the user is
657669
# running and:
658670
# (1) Default session has not started yet, and
@@ -674,7 +686,7 @@ def _set_default_session_location_if_possible_deferred_query(create_query):
674686
query = create_query()
675687
bqclient = _get_bqclient()
676688

677-
if bigframes.session._io.bigquery.is_query(query):
689+
if bigquery.is_query(query):
678690
# Intentionally run outside of the session so that we can detect the
679691
# location before creating the session. Since it's a dry_run, labels
680692
# aren't necessary.

bigframes/session/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def __init__(
133133
context: Optional[bigquery_options.BigQueryOptions] = None,
134134
clients_provider: Optional[bigframes.session.clients.ClientsProvider] = None,
135135
):
136+
# Address circular imports in doctest due to bigframes/session/__init__.py
137+
# containing a lot of logic and samples.
138+
from bigframes.session import anonymous_dataset, clients, loader, metrics
139+
136140
_warn_if_bf_version_is_obsolete()
137141

138142
if context is None:
@@ -168,7 +172,7 @@ def __init__(
168172
if clients_provider:
169173
self._clients_provider = clients_provider
170174
else:
171-
self._clients_provider = bigframes.session.clients.ClientsProvider(
175+
self._clients_provider = clients.ClientsProvider(
172176
project=context.project,
173177
location=self._location,
174178
use_regional_endpoints=context.use_regional_endpoints,
@@ -220,15 +224,13 @@ def __init__(
220224
else bigframes.enums.DefaultIndexKind.NULL
221225
)
222226

223-
self._metrics = bigframes.session.metrics.ExecutionMetrics()
227+
self._metrics = metrics.ExecutionMetrics()
224228
self._function_session = bff_session.FunctionSession()
225-
self._anon_dataset_manager = (
226-
bigframes.session.anonymous_dataset.AnonymousDatasetManager(
227-
self._clients_provider.bqclient,
228-
location=self._location,
229-
session_id=self._session_id,
230-
kms_key=self._bq_kms_key_name,
231-
)
229+
self._anon_dataset_manager = anonymous_dataset.AnonymousDatasetManager(
230+
self._clients_provider.bqclient,
231+
location=self._location,
232+
session_id=self._session_id,
233+
kms_key=self._bq_kms_key_name,
232234
)
233235
# Session temp tables don't support specifying kms key, so use anon dataset if kms key specified
234236
self._session_resource_manager = (
@@ -242,7 +244,7 @@ def __init__(
242244
self._temp_storage_manager = (
243245
self._session_resource_manager or self._anon_dataset_manager
244246
)
245-
self._loader = bigframes.session.loader.GbqDataLoader(
247+
self._loader = loader.GbqDataLoader(
246248
session=self,
247249
bqclient=self._clients_provider.bqclient,
248250
storage_manager=self._temp_storage_manager,

0 commit comments

Comments
 (0)