-
Notifications
You must be signed in to change notification settings - Fork 50
feat: to_gbq
without a destination table writes to a temporary table
#158
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
daa2079
feat: `to_gbq` without a destination table writes to a temporary table
tswast c7e3afe
add unit test covering happy path for to_gbq
tswast f2c64db
update to_gbq docs
tswast e6f30da
Merge remote-tracking branch 'origin/main' into b307942243-cached-pub…
tswast f65fc8f
Merge branch 'main' into b307942243-cached-public-no-session
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import google.cloud.bigquery | ||
import pytest | ||
|
||
from . import resources | ||
|
||
|
||
def test_dataframe_to_gbq_invalid_destination(monkeypatch: pytest.MonkeyPatch): | ||
dataframe = resources.create_dataframe(monkeypatch) | ||
|
||
with pytest.raises(ValueError, match="no_dataset_or_project"): | ||
dataframe.to_gbq("no_dataset_or_project") | ||
|
||
|
||
def test_dataframe_to_gbq_invalid_if_exists(monkeypatch: pytest.MonkeyPatch): | ||
dataframe = resources.create_dataframe(monkeypatch) | ||
|
||
with pytest.raises(ValueError, match="notreallyanoption"): | ||
# Even though the type is annotated with the literals we accept, users | ||
# might not be using a type checker, especially not in an interactive | ||
# notebook. | ||
dataframe.to_gbq(if_exists="notreallyanoption") # type: ignore | ||
|
||
|
||
def test_dataframe_to_gbq_invalid_if_exists_no_destination( | ||
monkeypatch: pytest.MonkeyPatch, | ||
): | ||
dataframe = resources.create_dataframe(monkeypatch) | ||
|
||
with pytest.raises(ValueError, match="append"): | ||
dataframe.to_gbq(if_exists="append") | ||
|
||
|
||
def test_dataframe_to_gbq_writes_to_anonymous_dataset( | ||
monkeypatch: pytest.MonkeyPatch, | ||
): | ||
anonymous_dataset_id = "my-anonymous-project.my_anonymous_dataset" | ||
anonymous_dataset = google.cloud.bigquery.DatasetReference.from_string( | ||
anonymous_dataset_id | ||
) | ||
session = resources.create_bigquery_session(anonymous_dataset=anonymous_dataset) | ||
dataframe = resources.create_dataframe(monkeypatch, session=session) | ||
|
||
destination = dataframe.to_gbq() | ||
|
||
assert destination.startswith(anonymous_dataset_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.