Uh oh!
There was an error while loading. Please reload this page.
BigQuery: docs for Row.keys, items, values, and get functions. - #4410
Conversation
| 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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ['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.
Uh oh!
There was an error while loading. Please reload this page.
| @@ -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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| >>> 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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| 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.
Uh oh!
There was an error while loading. Please reload this page.
| >>> 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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- Refactors items, keys to return iterators. - Copies values to prevent mutating the original row object.
dhermes
commented
Nov 17, 2017
@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.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
| ] | ||
| 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.
Uh oh!
There was an error while loading. Please reload this page.
dhermes
left a comment
There was a problem hiding this comment.
LGTM, though I'm a bit "sad" about the copies. (They seem necessary evils, but still evils.)
tswast
commented
Nov 17, 2017
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. |
dhermes
commented
Nov 17, 2017
@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? |
tswast
commented
Nov 17, 2017
Yeah, let's revert. I didn't think to check the system tests. |
I forgot to ask for these in #4393 before I merged.