-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
feat(bigquery): make rowIterator._to_dataframe_iterable public #10017
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2014,6 +2014,55 @@ def test_to_arrow_w_pyarrow_none(self): | |
with self.assertRaises(ValueError): | ||
row_iterator.to_arrow() | ||
|
||
@unittest.skipIf(pandas is None, "Requires `pandas`") | ||
def test_to_dataframe_iterable(self): | ||
from google.cloud.bigquery.schema import SchemaField | ||
import types | ||
|
||
schema = [ | ||
SchemaField("name", "STRING", mode="REQUIRED"), | ||
SchemaField("age", "INTEGER", mode="REQUIRED"), | ||
] | ||
rows = [ | ||
{"f": [{"v": "Phred Phlyntstone"}, {"v": "32"}]}, | ||
{"f": [{"v": "Bharney Rhubble"}, {"v": "33"}]}, | ||
{"f": [{"v": "Wylma Phlyntstone"}, {"v": "29"}]}, | ||
{"f": [{"v": "Bhettye Rhubble"}, {"v": "27"}]}, | ||
] | ||
path = "/foo" | ||
api_request = mock.Mock(return_value={"rows": rows}) | ||
|
||
row_iterator = self._make_one( | ||
_mock_client(), api_request, path, schema, page_size=1, max_results=5 | ||
) | ||
df = row_iterator.to_dataframe_iterable() | ||
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. Since this is a generator, use a plural for the variable name |
||
|
||
self.assertIsInstance(df, types.GeneratorType) | ||
|
||
a = next(df) | ||
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.
|
||
self.assertEqual(a.name.dtype.name, "object") | ||
self.assertEqual(a.age.dtype.name, "int64") | ||
self.assertEqual(len(a), 4) | ||
|
||
@mock.patch("google.cloud.bigquery.table.pandas", new=None) | ||
def test_to_dataframe_iterable_error_if_pandas_is_none(self): | ||
from google.cloud.bigquery.schema import SchemaField | ||
|
||
schema = [ | ||
SchemaField("name", "STRING", mode="REQUIRED"), | ||
SchemaField("age", "INTEGER", mode="REQUIRED"), | ||
] | ||
rows = [ | ||
{"f": [{"v": "Phred Phlyntstone"}, {"v": "32"}]}, | ||
{"f": [{"v": "Bharney Rhubble"}, {"v": "33"}]}, | ||
] | ||
path = "/foo" | ||
api_request = mock.Mock(return_value={"rows": rows}) | ||
row_iterator = self._make_one(_mock_client(), api_request, path, schema) | ||
|
||
with self.assertRaises(ValueError): | ||
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. Let's use |
||
row_iterator.to_dataframe_iterable() | ||
|
||
@unittest.skipIf(pandas is None, "Requires `pandas`") | ||
def test_to_dataframe(self): | ||
from google.cloud.bigquery.schema import SchemaField | ||
|
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.
I'd like to see
side_effect
used to test with multiple pages.