Skip to content

Commit ce96e85

Browse files
authored
Revert "BigQuery: docs for Row.keys, items, values, and get functions. (#4410)" (#4412)
This reverts commit f3e745e.
1 parent f3e745e commit ce96e85

File tree

2 files changed

+30
-61
lines changed

2 files changed

+30
-61
lines changed

bigquery/google/cloud/bigquery/table.py

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
from __future__ import absolute_import
1818

19-
import copy
2019
import datetime
2120
import operator
2221

@@ -784,73 +783,43 @@ def __init__(self, values, field_to_index):
784783
self._xxx_field_to_index = field_to_index
785784

786785
def values(self):
787-
"""Return the values included in this row.
788-
789-
Returns:
790-
Sequence[object]: A sequence of length ``len(row)``.
791-
"""
792-
for value in self._xxx_values:
793-
yield copy.deepcopy(value)
786+
return self._xxx_values
794787

795788
def keys(self):
796-
"""Return the keys for using a row as a dict.
797-
798-
Returns:
799-
Sequence[str]: The keys corresponding to the columns of a row
800-
801-
Examples:
802-
803-
>>> list(Row(('a', 'b'), {'x': 0, 'y': 1}).keys())
804-
['x', 'y']
805789
"""
806-
return six.iterkeys(self._xxx_field_to_index)
790+
Return keys as of a dict:
791+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).keys()
792+
['x', 'y']
793+
"""
794+
keys = self._xxx_field_to_index.keys()
795+
return keys
807796

808797
def items(self):
809-
"""Return items as ``(key, value)`` pairs.
810-
811-
Returns:
812-
Sequence[Tuple[str, object]]:
813-
The ``(key, value)`` pairs representing this row.
814-
815-
Examples:
816-
817-
>>> list(Row(('a', 'b'), {'x': 0, 'y': 1}).items())
818-
[('x', 'a'), ('y', 'b')]
819798
"""
820-
for key, index in six.iteritems(self._xxx_field_to_index):
821-
yield (key, copy.deepcopy(self._xxx_values[index]))
799+
Return items as of a dict:
800+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).items()
801+
[('x', 'a'), ('y', 'b')]
802+
"""
803+
items = [
804+
(k, self._xxx_values[i])
805+
for k, i
806+
in self._xxx_field_to_index.items()
807+
]
808+
return items
822809

823810
def get(self, key, default=None):
824-
"""Return a value for key, with a default value if it does not exist.
825-
826-
Args:
827-
key (str): The key of the column to access
828-
default (object):
829-
The default value to use if the key does not exist. (Defaults
830-
to :data:`None`.)
831-
832-
Returns:
833-
object:
834-
The value associated with the provided key, or a default value.
835-
836-
Examples:
837-
When the key exists, the value associated with it is returned.
838-
839-
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('x')
840-
'a'
841-
842-
The default value is ``None`` when the key does not exist.
843-
844-
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z')
845-
None
846-
847-
The default value can be overrided with the ``default`` parameter.
848-
849-
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', '')
850-
''
851-
852-
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', default = '')
853-
''
811+
"""
812+
Return value under specified key
813+
Defaults to None or specified default
814+
if key does not exist:
815+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('x')
816+
'a'
817+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z')
818+
None
819+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', '')
820+
''
821+
>>> Row(('a', 'b'), {'x': 0, 'y': 1}).get('z', default = '')
822+
''
854823
"""
855824
index = self._xxx_field_to_index.get(key)
856825
if index is None:

bigquery/tests/unit/test_table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ def test_row(self):
764764
self.assertEqual(row[1], 2)
765765
self.assertEqual(row['c'], 3)
766766
self.assertEqual(len(row), 3)
767-
self.assertEqual(tuple(row.values()), VALUES)
767+
self.assertEqual(row.values(), VALUES)
768768
self.assertEqual(set(row.keys()), set({'a': 1, 'b': 2, 'c': 3}.keys()))
769769
self.assertEqual(set(row.items()),
770770
set({'a': 1, 'b': 2, 'c': 3}.items()))

0 commit comments

Comments
 (0)