Skip to content

feat(bigquery): add PendingDeprecationWarning for from_dataframe methods - #18048

Merged
shuoweil merged 3 commits into
mainfrom
shuowei-from-dataframe-warning
Aug 11, 2026
Merged

feat(bigquery): add PendingDeprecationWarning for from_dataframe methods#18048
shuoweil merged 3 commits into
mainfrom
shuowei-from-dataframe-warning

Conversation

@shuoweil

Copy link
Copy Markdown
Contributor

Adds PendingDeprecationWarning to Client.load_table_from_dataframe() and Client.insert_rows_from_dataframe() in google-cloud-bigquery.

This alerts users to adopt direct pandas_gbq.to_gbq() entry points ahead of future deprecation phases per the pandas-gbq migration design.

  • Added PendingDeprecationWarning to load_table_from_dataframe and insert_rows_from_dataframe in google/cloud/bigquery/client.py.
  • Added corresponding unit tests in tests/unit/test_client.py.

Fixes #<526614511 🦕

@shuoweil shuoweil self-assigned this Aug 10, 2026
@shuoweil
shuoweil requested review from a team as code owners August 10, 2026 19:52
@shuoweil
shuoweil requested review from GarrettWu, sycai and tswast and removed request for a team and GarrettWu August 10, 2026 19:52

@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 deprecates loading and inserting rows from DataFrames via google-cloud-bigquery by introducing PendingDeprecationWarning warnings and adding corresponding unit tests. Feedback on the changes highlights two issues: first, assertions for an existing test (test_insert_rows_from_dataframe_w_explicit_none_insert_ids) were accidentally deleted and need to be restored; second, the use of parenthesized context managers in the tests breaks compatibility with Python 3.8 and should be replaced with standard multi-context with statements.

Comment on lines +6566 to +6584
def test_insert_rows_from_dataframe_emits_pending_deprecation_warning(self):
pandas = pytest.importorskip("pandas")
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.table import Table

actual_calls = conn.api_request.call_args_list
assert len(actual_calls) == 1
assert actual_calls[0] == mock.call(
method="POST",
path=API_PATH,
data=EXPECTED_SENT_DATA,
timeout=DEFAULT_TIMEOUT,
)
creds = _make_credentials()
http = object()
client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
client._connection = make_connection({}, {})

schema = [SchemaField("name", "STRING", mode="REQUIRED")]
table = Table(self.TABLE_REF, schema=schema)
dataframe = pandas.DataFrame([{"name": "Alice"}])

with pytest.warns(
PendingDeprecationWarning,
match="Inserting rows from DataFrames via google-cloud-bigquery is deprecated",
):
client.insert_rows_from_dataframe(table, dataframe)

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.

high

The assertions for test_insert_rows_from_dataframe_w_explicit_none_insert_ids were accidentally deleted when adding the new test test_insert_rows_from_dataframe_emits_pending_deprecation_warning. Please restore the deleted assertions and append the new test case.

        EXPECTED_SENT_DATA = {
            "rows": [
                {"insertId": None, "json": {"name": "Little One", "adult": "false"}},
                {"insertId": None, "json": {"name": "Young Gun", "adult": "true"}},
            ]
        }

        actual_calls = conn.api_request.call_args_list
        assert len(actual_calls) == 1
        assert actual_calls[0] == mock.call(
            method="POST",
            path=API_PATH,
            data=EXPECTED_SENT_DATA,
            timeout=DEFAULT_TIMEOUT,
        )

    def test_insert_rows_from_dataframe_emits_pending_deprecation_warning(self):
        pandas = pytest.importorskip("pandas")
        from google.cloud.bigquery.schema import SchemaField
        from google.cloud.bigquery.table import Table

        creds = _make_credentials()
        http = object()
        client = self._make_one(project=self.PROJECT, credentials=creds, _http=http)
        client._connection = make_connection({}, {})

        schema = [SchemaField("name", "STRING", mode="REQUIRED")]
        table = Table(self.TABLE_REF, schema=schema)
        dataframe = pandas.DataFrame([{"name": "Alice"}])

        with pytest.warns(
            PendingDeprecationWarning,
            match="Inserting rows from DataFrames via google-cloud-bigquery is deprecated",
        ):
            client.insert_rows_from_dataframe(table, dataframe)

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.

fixed

Comment on lines +9410 to +9417
with (
load_patch,
get_table_patch,
pytest.warns(
PendingDeprecationWarning,
match="Loading DataFrames via google-cloud-bigquery is deprecated",
),
):

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

Parenthesized context managers are only supported in Python 3.9+. To maintain compatibility with Python 3.8 (which is still supported by this package), use a standard multi-context with statement without parentheses.

        with load_patch, get_table_patch, pytest.warns(
            PendingDeprecationWarning,
            match="Loading DataFrames via google-cloud-bigquery is deprecated",
        ):

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.

fixed

@shuoweil
shuoweil merged commit b84b754 into main Aug 11, 2026
52 checks passed
@shuoweil
shuoweil deleted the shuowei-from-dataframe-warning branch August 11, 2026 19:52
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