Skip to content

TST: Add tests for if_exists keyword argument in df.to_gbq #30447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ Other
- Fixed :class:`IntegerArray` returning ``inf`` rather than ``NaN`` for operations dividing by 0 (:issue:`27398`)
- Fixed ``pow`` operations for :class:`IntegerArray` when the other value is ``0`` or ``1`` (:issue:`29997`)
- Bug in :meth:`Series.count` raises if use_inf_as_na is enabled (:issue:`29478`)

- Add tests for keyword argument ``if_exists`` in :meth:`DataFrame.to_gbq` (:issue:`29598`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No note needed as this isn't a user-facing change


.. _whatsnew_1000.contributors:

Expand Down
34 changes: 34 additions & 0 deletions pandas/tests/io/test_gbq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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