Skip to content

fix: disambiguate google-cloud-bigquery to_dataframe usage from pandas-gbq in ua. - #18369

Open
tswast wants to merge 1 commit into
mainfrom
b540939659-user-agent
Open

tswast wants to merge 1 commit into
mainfrom
b540939659-user-agent

Conversation

@tswast

@tswast tswast commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

For internal issue b/540939659 and a follow-up to #18364

🦕

@tswast
tswast requested review from a team as code owners September 14, 2026 21:39
@tswast
tswast requested review from shuoweil and removed request for a team September 14, 2026 21:39

@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 updates the BigQuery client to include the google-cloud-bigquery version as a legacy identifier in the user agent string for to_dataframe and to_arrow operations, and adds corresponding unit tests. The review feedback suggests aliasing the imported version module to bq_version to avoid potential shadowing conflicts, and removing redundant local imports of the sys module within several test functions in test_table.py.

_versions_helpers,
enums,
job,
version,

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

Importing the version module as version can easily lead to shadowing issues or confusion because version is a very common variable and parameter name throughout this codebase. Consider aliasing it to bq_version to prevent potential naming conflicts.

Suggested change
version,
version as bq_version,


# Track the google-cloud-bigquery version as "legacy" because this code
# path is intended to be migrated to pandas-gbq itself.
user_agent = f"legacy-gcb/{version.__version__} {pandas_user_agent}"

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

Use the aliased bq_version to avoid potential shadowing issues with the common name version.

Suggested change
user_agent = f"legacy-gcb/{version.__version__} {pandas_user_agent}"
user_agent = f"legacy-gcb/{bq_version.__version__} {pandas_user_agent}"

Comment on lines +3554 to +3556
import sys

import google.auth.credentials

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

According to the general rules, do not import modules inside functions if they are already imported at the module level. Since sys is already imported at the module level of this file, this local import is redundant and can be removed.

Suggested change
import sys
import google.auth.credentials
import google.auth.credentials
References
  1. Do not import modules or classes inside functions if they are already imported at the module level.

Comment on lines +3613 to +3615
import sys

import google.auth.credentials

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

According to the general rules, do not import modules inside functions if they are already imported at the module level. Since sys is already imported at the module level of this file, this local import is redundant and can be removed.

Suggested change
import sys
import google.auth.credentials
import google.auth.credentials
References
  1. Do not import modules or classes inside functions if they are already imported at the module level.

Comment on lines +5024 to +5026
import sys

import google.auth.credentials

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

According to the general rules, do not import modules inside functions if they are already imported at the module level. Since sys is already imported at the module level of this file, this local import is redundant and can be removed.

Suggested change
import sys
import google.auth.credentials
import google.auth.credentials
References
  1. Do not import modules or classes inside functions if they are already imported at the module level.

Comment on lines +5083 to +5085
import sys

import google.auth.credentials

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

According to the general rules, do not import modules inside functions if they are already imported at the module level. Since sys is already imported at the module level of this file, this local import is redundant and can be removed.

Suggested change
import sys
import google.auth.credentials
import google.auth.credentials
References
  1. Do not import modules or classes inside functions if they are already imported at the module level.

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.

1 participant