Skip to content

feat: add PendingDeprecationWarning for from_dataframe methods - #18049

Closed
shuoweil wants to merge 1 commit into
mainfrom
shuowei-gbq-from-dataframe-warning
Closed

feat: add PendingDeprecationWarning for from_dataframe methods#18049
shuoweil wants to merge 1 commit into
mainfrom
shuowei-gbq-from-dataframe-warning

Conversation

@shuoweil

Copy link
Copy Markdown
Contributor

Adds PendingDeprecationWarning to Client.load_table_from_dataframe() and Client.insert_rows_from_dataframe().

Guides developers toward direct pandas_gbq.to_gbq() APIs as part of the pandas-gbq backend consolidation.

Fixes #<526614511>🦕

@shuoweil
shuoweil requested review from a team as code owners August 10, 2026 19:53
@shuoweil
shuoweil requested review from tswast and removed request for a team August 10, 2026 19:53

@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 raising a 'PendingDeprecationWarning' and directing users to 'pandas_gbq.to_gbq()'. It also adds corresponding unit tests. However, during the addition of these tests, the assertions for 'test_insert_rows_from_dataframe_w_explicit_none_insert_ids' were accidentally deleted and must be restored.

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

It looks like 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. This leaves the original test incomplete and without verification. Please restore the deleted assertions and append the new test properly.

        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)

@shuoweil
shuoweil removed the request for review from tswast August 10, 2026 19:55
@shuoweil shuoweil closed this Aug 10, 2026
@shuoweil

shuoweil commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Duplicated PR #18048

@shuoweil
shuoweil deleted the shuowei-gbq-from-dataframe-warning branch August 10, 2026 19:57
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