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(
1091
1091
.. versionadded:: 0.23.3
1092
1092
"""
1093
1093
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
+
1094
1102
_test_google_api_imports ()
1095
1103
1096
1104
from google .api_core import exceptions as google_exceptions
Original file line number Diff line number Diff line change 11
11
from pandas_gbq import gbq
12
12
13
13
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
+
14
24
@pytest .fixture
15
25
def expected_load_method (mock_bigquery_client ):
16
26
return mock_bigquery_client .load_table_from_dataframe
@@ -66,6 +76,15 @@ def test_to_gbq_load_method_translates_exception(
66
76
expected_load_method .assert_called_once ()
67
77
68
78
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
+
69
88
def test_to_gbq_with_if_exists_append (mock_bigquery_client , expected_load_method ):
70
89
from google .cloud .bigquery import SchemaField
71
90
You can’t perform that action at this time.
0 commit comments