Skip to content

feat: prepare client-side delegation and telemetry for pandas-gbq - #17704

Draft
shuoweil wants to merge 28 commits into
mainfrom
shuowei-gbq-delegation-telemetry-mvp
Draft

feat: prepare client-side delegation and telemetry for pandas-gbq#17704
shuoweil wants to merge 28 commits into
mainfrom
shuowei-gbq-delegation-telemetry-mvp

Conversation

@shuoweil

@shuoweil shuoweil commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Adds PandasGBQVersions capability checks to _versions_helpers.py and propagates pandas-gbq/<version> user-agent telemetry across BigQuery client entry points when delegating execution.

Changes Made

  1. pandas-gbq Version Capability Helper (packages/google-cloud-bigquery):
    • Added PandasGBQVersions class to google/cloud/bigquery/_versions_helpers.py to inspect pandas-gbq installation, version, and _internal_delegation_api_version.
    • Exposed PANDAS_GBQ_VERSIONS singleton for capability checks across query and storage entry points.
  2. Telemetry Header Propagation (packages/google-cloud-bigquery):
    • Updated client initialization and delegation routines to append pandas-gbq/<version> to ClientInfo.user_agent while preserving existing user-agent headers and client options.
  3. Unit Tests (packages/google-cloud-bigquery):
    • Added 34 unit tests in tests/unit/test__versions_helpers.py verifying version parsing, fallback behavior on uninstalled/corrupted packages (0.0.0), and caching.

Fixes #<526614511> 🦕

@shuoweil
shuoweil requested a review from tswast July 13, 2026 21:38
@shuoweil shuoweil self-assigned this Jul 13, 2026
@shuoweil
shuoweil requested review from a team as code owners July 13, 2026 21:38

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces query delegation support to the pandas-gbq package when retrieving dataframes via to_dataframe. It adds version helper utilities to check if delegation is supported, issues a deprecation warning if the core client fallback is used, and delegates the dataframe creation to pandas_gbq when available. The review feedback suggests making the pandas-gbq import and version checks more robust by catching general exceptions rather than just ImportError, using getattr to safely retrieve the package version, and ensuring that pyarrow is skipped in tests when not installed to prevent test failures.

Comment on lines +260 to +268
if self._installed_version is None:
try:
import pandas_gbq # type: ignore

self._installed_version = packaging.version.parse(
getattr(pandas_gbq, "__version__", "0.0.0")
)
except ImportError:
self._installed_version = packaging.version.parse("0.0.0")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching only ImportError when importing pandas_gbq can lead to unhandled exceptions if the import fails due to other issues (e.g., compiled extension load failures, AttributeError, or TypeError from broken dependencies). Additionally, packaging.version.parse can raise InvalidVersion if the version string is malformed. Catching Exception ensures a robust fallback to version 0.0.0.

Suggested change
if self._installed_version is None:
try:
import pandas_gbq # type: ignore
self._installed_version = packaging.version.parse(
getattr(pandas_gbq, "__version__", "0.0.0")
)
except ImportError:
self._installed_version = packaging.version.parse("0.0.0")
if self._installed_version is None:
try:
import pandas_gbq # type: ignore
self._installed_version = packaging.version.parse(
getattr(pandas_gbq, "__version__", "0.0.0")
)
except Exception:
self._installed_version = packaging.version.parse("0.0.0")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to hide errors for users.

Comment on lines +275 to +283
if self._delegation_api_version is None:
try:
import pandas_gbq # type: ignore

self._delegation_api_version = getattr(
pandas_gbq, "_internal_delegation_api_version", 0
)
except ImportError:
self._delegation_api_version = 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to installed_version, catching only ImportError when importing pandas_gbq can lead to unhandled exceptions if the import fails due to other issues. Catching Exception ensures a robust fallback to 0.

Suggested change
if self._delegation_api_version is None:
try:
import pandas_gbq # type: ignore
self._delegation_api_version = getattr(
pandas_gbq, "_internal_delegation_api_version", 0
)
except ImportError:
self._delegation_api_version = 0
if self._delegation_api_version is None:
try:
import pandas_gbq # type: ignore
self._delegation_api_version = getattr(
pandas_gbq, "_internal_delegation_api_version", 0
)
except Exception:
self._delegation_api_version = 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to hide errors for users.

Comment thread packages/google-cloud-bigquery/google/cloud/bigquery/table.py Outdated
Comment thread packages/google-cloud-bigquery/tests/unit/test_table.py
@parthea
parthea marked this pull request as draft July 14, 2026 14:11
@parthea

parthea commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Converting to draft until presubmits are green

@shuoweil
shuoweil removed the request for review from tswast July 21, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants