File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -1091,6 +1091,14 @@ def to_gbq(
10911091 .. versionadded:: 0.23.3
10921092 """
10931093
1094+ # If we get a bigframes.pandas.DataFrame object, it may be possible to use
1095+ # the code paths here, but it could potentially be quite expensive because
1096+ # of the queries involved in type detection. It would be safer just to
1097+ # fail early if there are bigframes-y methods available.
1098+ # https://github.com/googleapis/python-bigquery-pandas/issues/824
1099+ if hasattr (dataframe , "to_pandas" ) and hasattr (dataframe , "to_gbq" ):
1100+ raise TypeError (f"Expected a pandas.DataFrame, but got { repr (type (dataframe ))} " )
1101+
10941102 _test_google_api_imports ()
10951103
10961104 from google .api_core import exceptions as google_exceptions
Original file line number Diff line number Diff line change 1111from pandas_gbq import gbq
1212
1313
14+ class FakeDataFrame :
15+ """A fake bigframes DataFrame to avoid depending on bigframes."""
16+
17+ def to_gbq (self ):
18+ """Fake to_gbq() to mimic a bigframes object."""
19+
20+ def to_pandas (self ):
21+ """Fake to_pandas() to mimic a bigframes object."""
22+
23+
1424@pytest .fixture
1525def expected_load_method (mock_bigquery_client ):
1626 return mock_bigquery_client .load_table_from_dataframe
@@ -66,6 +76,15 @@ def test_to_gbq_load_method_translates_exception(
6676 expected_load_method .assert_called_once ()
6777
6878
79+ def test_to_gbq_with_bigframes_raises_typeerror ():
80+ dataframe = FakeDataFrame ()
81+
82+ with pytest .raises (
83+ TypeError , match = r"Expected a pandas.DataFrame, but got .+FakeDataFrame"
84+ ):
85+ gbq .to_gbq (dataframe , "my_dataset.my_table" , project_id = "myproj" )
86+
87+
6988def test_to_gbq_with_if_exists_append (mock_bigquery_client , expected_load_method ):
7089 from google .cloud .bigquery import SchemaField
7190
You can’t perform that action at this time.
0 commit comments