Skip to content

Commit 6c91033

Browse files
charlesdong1991WillAyd
authored andcommitted
TST: Add tests for if_exists keyword argument in df.to_gbq (#30447)
1 parent 2a6c2d7 commit 6c91033

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/io/test_gbq.py

+34
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,37 @@ def test_roundtrip(self):
195195
dialect="standard",
196196
)
197197
assert result["num_rows"][0] == test_size
198+
199+
@pytest.mark.parametrize(
200+
"if_exists, expected_num_rows",
201+
[("append", 300), ("fail", 200), ("replace", 100)],
202+
)
203+
def test_gbq_if_exists(self, if_exists, expected_num_rows):
204+
# GH 29598
205+
destination_table = DESTINATION_TABLE + "2"
206+
207+
test_size = 200
208+
df = make_mixed_dataframe_v2(test_size)
209+
210+
df.to_gbq(
211+
destination_table,
212+
_get_project_id(),
213+
chunksize=None,
214+
credentials=_get_credentials(),
215+
)
216+
217+
df.iloc[:100].to_gbq(
218+
destination_table,
219+
_get_project_id(),
220+
if_exists=if_exists,
221+
chunksize=None,
222+
credentials=_get_credentials(),
223+
)
224+
225+
result = pd.read_gbq(
226+
f"SELECT COUNT(*) AS num_rows FROM {destination_table}",
227+
project_id=_get_project_id(),
228+
credentials=_get_credentials(),
229+
dialect="standard",
230+
)
231+
assert result["num_rows"][0] == expected_num_rows

0 commit comments

Comments
 (0)