feat: add PendingDeprecationWarning for from_dataframe methods - #18049
feat: add PendingDeprecationWarning for from_dataframe methods#18049shuoweil wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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)|
Duplicated PR #18048 |
Adds
PendingDeprecationWarningtoClient.load_table_from_dataframe()andClient.insert_rows_from_dataframe().Guides developers toward direct
pandas_gbq.to_gbq()APIs as part of thepandas-gbqbackend consolidation.Fixes #<526614511>🦕