|
16 | 16 |
|
17 | 17 | from __future__ import absolute_import |
18 | 18 |
|
19 | | -import copy |
20 | 19 | import datetime |
21 | 20 | import operator |
22 | 21 |
|
@@ -784,73 +783,43 @@ def __init__(self, values, field_to_index): |
784 | 783 | self._xxx_field_to_index = field_to_index |
785 | 784 |
|
786 | 785 | 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 |
794 | 787 |
|
795 | 788 | 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'] |
805 | 789 | """ |
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 |
807 | 796 |
|
808 | 797 | 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')] |
819 | 798 | """ |
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 |
822 | 809 |
|
823 | 810 | 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 | + '' |
854 | 823 | """ |
855 | 824 | index = self._xxx_field_to_index.get(key) |
856 | 825 | if index is None: |
|
0 commit comments