diff --git a/pandas/tests/io/test_gbq.py b/pandas/tests/io/test_gbq.py index ab27ea7098b08..aeaf612ce28b7 100644 --- a/pandas/tests/io/test_gbq.py +++ b/pandas/tests/io/test_gbq.py @@ -195,3 +195,37 @@ def test_roundtrip(self): dialect="standard", ) assert result["num_rows"][0] == test_size + + @pytest.mark.parametrize( + "if_exists, expected_num_rows", + [("append", 300), ("fail", 200), ("replace", 100)], + ) + def test_gbq_if_exists(self, if_exists, expected_num_rows): + # GH 29598 + destination_table = DESTINATION_TABLE + "2" + + test_size = 200 + df = make_mixed_dataframe_v2(test_size) + + df.to_gbq( + destination_table, + _get_project_id(), + chunksize=None, + credentials=_get_credentials(), + ) + + df.iloc[:100].to_gbq( + destination_table, + _get_project_id(), + if_exists=if_exists, + chunksize=None, + credentials=_get_credentials(), + ) + + result = pd.read_gbq( + f"SELECT COUNT(*) AS num_rows FROM {destination_table}", + project_id=_get_project_id(), + credentials=_get_credentials(), + dialect="standard", + ) + assert result["num_rows"][0] == expected_num_rows