Skip to content

Commit 57e7822

Browse files
authored
feat(bigquery-storage): add deprecation warning for to_dataframe (#18022)
Following the addition of `PendingDeprecationWarning` to `ReadRowsPage.to_arrow()` in #17938, this PR adds `PendingDeprecationWarning` to `ReadRowsPage.to_dataframe()` in `google-cloud-bigquery-storage`. This notifies developers to adopt direct `pandas-gbq` APIs (`pandas_gbq.read_gbq()` or `pandas_gbq.pandas.read_bigquery_stream_batches()`) ahead of future deprecation phases. Fixes #< 526614511 > 🦕
1 parent 71e8d94 commit 57e7822

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/google-cloud-bigquery-storage/google/cloud/bigquery_storage_v1/reader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,12 @@ def to_dataframe(self, dtypes=None):
617617
pandas.DataFrame:
618618
A data frame of all rows in the stream.
619619
"""
620+
warnings.warn(
621+
"Retrieving DataFrames directly via google-cloud-bigquery-storage is deprecated. "
622+
"Please use 'pandas_gbq.read_gbq()' or 'pandas_gbq.pandas.read_bigquery_stream_batches()'.",
623+
PendingDeprecationWarning,
624+
stacklevel=2,
625+
)
620626
if pandas is None:
621627
raise ImportError(_PANDAS_REQUIRED)
622628

packages/google-cloud-bigquery-storage/tests/unit/test_reader_v1.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import pandas
2626
import pandas.testing
2727
import pytest
28-
2928
from google.cloud.bigquery_storage import types
3029

3130
from .helpers import SCALAR_BLOCKS, SCALAR_COLUMN_NAMES, SCALAR_COLUMNS
@@ -700,3 +699,20 @@ def test_to_arrow_avro_consumes_first_page(class_under_test, mock_gapic_client):
700699
# Since read_session was not provided, to_arrow() had to consume the first message
701700
# to find out it was Avro. So offset should be 1.
702701
assert reader._offset == 1
702+
703+
704+
def test_to_dataframe_emits_pending_deprecation_warning(mut):
705+
mock_parser = mock.Mock()
706+
mock_message = mock.Mock()
707+
mock_df = mock.Mock()
708+
mock_parser.to_dataframe.return_value = mock_df
709+
710+
page = mut.ReadRowsPage(mock_parser, mock_message)
711+
with pytest.warns(
712+
PendingDeprecationWarning,
713+
match="google-cloud-bigquery-storage is deprecated",
714+
):
715+
actual_df = page.to_dataframe()
716+
717+
assert actual_df == mock_df
718+
mock_parser.to_dataframe.assert_called_once_with(mock_message, dtypes=None)

0 commit comments

Comments
 (0)