-
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
BigQuery: docs for Row.keys, items, values, and get functions. #4410
Conversation
@@ -783,22 +783,38 @@ def __init__(self, values, field_to_index): | |||
self._xxx_field_to_index = field_to_index | |||
|
|||
def values(self): | |||
"""Return the values included in this row. | |||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Examples: | ||
|
||
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).keys() | ||
['x', 'y'] | ||
""" | ||
keys = self._xxx_field_to_index.keys() | ||
return keys |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -808,18 +824,38 @@ def items(self): | |||
return items |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', default = '') | ||
'' | ||
"""Return value for ``key`` if ``key`` is in the row, else | ||
``default``. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
Args: | ||
key (str): The key of the column to access | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('x') | ||
'a' | ||
|
||
The default value is ``None`` when the key does not exist. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
- Refactors items, keys to return iterators. - Copies values to prevent mutating the original row object.
@tswast For future PRs, can you squash while merging the PR? It's harder to review a PR when I can't tell what you changed when squashing. (Though I definitely feel the seem way, I squash locally a lot because for some reason I care about commit log clutter, even though we are 5500+ commits in to this project.) |
Return keys as of a dict: | ||
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).keys() | ||
['x', 'y'] | ||
return copy.deepcopy(self._xxx_values) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
] | ||
return items | ||
for key, index in six.iteritems(self._xxx_field_to_index): | ||
yield (key, copy.deepcopy(self._xxx_values[index])) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
LGTM, though I'm a bit "sad" about the copies. (They seem necessary evils, but still evils.)
Yeah, it is a bit sad about copies. There's definitely a trade-off between safety and performance. Probably better to err on the side of safety. |
@tswast Looks like the generators broke the build: https://circleci.com/gh/GoogleCloudPlatform/google-cloud-python/4288 Shall we revert, then re-submit this PR but push the branch to the GoogleCloudPlatform remote so system tests run? |
Yeah, let's revert. I didn't think to check the system tests. |
I forgot to ask for these in #4393 before I merged.