-
Notifications
You must be signed in to change notification settings - Fork 124
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
ENH: Add table_schema parameter for user-defined BigQuery schema #46
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8791c49
ENH: Add table_schema parameter for user-defined BigQuery schema (#46)
mremes f6f7dc9
remove unsupported gbq exception and replace with a generic one
2783f7c
fix versionadded for to_gbq table_schema parameter
6740634
fix test id numbering
4cfc00b
fix tests by using pytest raise asserts
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 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 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 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 |
---|---|---|
|
@@ -174,7 +174,7 @@ def make_mixed_dataframe_v2(test_size): | |
|
||
def test_generate_bq_schema_deprecated(): | ||
# 11121 Deprecation of generate_bq_schema | ||
with tm.assert_produces_warning(FutureWarning): | ||
with pytest.warns(FutureWarning): | ||
df = make_mixed_dataframe_v2(10) | ||
gbq.generate_bq_schema(df) | ||
|
||
|
@@ -1422,6 +1422,48 @@ def test_schema_is_subset_fails_if_not_subset(self): | |
assert self.sut.schema_is_subset( | ||
dataset, table_name, tested_schema) is False | ||
|
||
def test_upload_data_with_valid_user_schema(self): | ||
# Issue #46; tests test scenarios with user-provided | ||
# schemas | ||
df = tm.makeMixedDataFrame() | ||
test_id = "18" | ||
test_schema = [{'name': 'A', 'type': 'FLOAT'}, | ||
{'name': 'B', 'type': 'FLOAT'}, | ||
{'name': 'C', 'type': 'STRING'}, | ||
{'name': 'D', 'type': 'TIMESTAMP'}] | ||
destination_table = self.destination_table + test_id | ||
gbq.to_gbq(df, destination_table, _get_project_id(), | ||
private_key=_get_private_key_path(), | ||
table_schema=test_schema) | ||
dataset, table = destination_table.split('.') | ||
assert self.table.verify_schema(dataset, table, | ||
dict(fields=test_schema)) | ||
|
||
def test_upload_data_with_invalid_user_schema_raises_error(self): | ||
df = tm.makeMixedDataFrame() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also tests with missing keys in the schema There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test added. |
||
test_id = "19" | ||
test_schema = [{'name': 'A', 'type': 'FLOAT'}, | ||
{'name': 'B', 'type': 'FLOAT'}, | ||
{'name': 'C', 'type': 'FLOAT'}, | ||
{'name': 'D', 'type': 'FLOAT'}] | ||
destination_table = self.destination_table + test_id | ||
with pytest.raises(gbq.GenericGBQException): | ||
gbq.to_gbq(df, destination_table, _get_project_id(), | ||
private_key=_get_private_key_path(), | ||
table_schema=test_schema) | ||
|
||
def test_upload_data_with_missing_schema_fields_raises_error(self): | ||
df = tm.makeMixedDataFrame() | ||
test_id = "20" | ||
test_schema = [{'name': 'A', 'type': 'FLOAT'}, | ||
{'name': 'B', 'type': 'FLOAT'}, | ||
{'name': 'C', 'type': 'FLOAT'}] | ||
destination_table = self.destination_table + test_id | ||
with pytest.raises(gbq.GenericGBQException): | ||
gbq.to_gbq(df, destination_table, _get_project_id(), | ||
private_key=_get_private_key_path(), | ||
table_schema=test_schema) | ||
|
||
def test_list_dataset(self): | ||
dataset_id = self.dataset_prefix + "1" | ||
assert dataset_id in self.dataset.datasets() | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assume validation is now up to BQ. can you test this though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current implementation will throw
StreamingInsetError
after a chunk is done (see tests) along printing error trace from the BQ API. Which is OK.