Skip to content

Commit

Permalink
fix column and values methods
Browse files Browse the repository at this point in the history
  • Loading branch information
papajohn committed Jan 29, 2016
1 parent 4ed3faa commit 7410de6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
43 changes: 14 additions & 29 deletions datascience/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,42 +415,27 @@ def column(self, index_or_label):
table.column(label) is equivalent to table[label].
>>> tiles = Table().with_columns([
... 'letter', ['c', 'd'],
... 'count', [2, 4],
... ])
>>> list(tiles.column('letter'))
['c', 'd']
>>> tiles.column(1)
array([2, 4])
Args:
label (int or str): The index or label of a column
Returns:
An array
An instance of ``numpy.array``.
"""
return column[index_or_label]
return self._columns[self._as_label(index_or_label)]

def values(self, label):
"""Returns the values of a column as an array.
``__getitem__`` is aliased to this, so bracket notation can be used
ie. table.values(label) is equivalent to table[label].
>>> letter = ['a', 'b', 'c', 'z']
>>> count = [9, 3, 3, 1]
>>> points = [1, 2, 2, 10]
>>> t = Table([letter, count, points], ['letter', 'count', 'points'])
>>> t
letter | count | points
a | 9 | 1
b | 3 | 2
c | 3 | 2
z | 1 | 10
>>> t.values("letter") # doctest: +NORMALIZE_WHITESPACE
array(['a', 'b', 'c', 'z'], dtype='<U1')
>>> t.values("count")
array([9, 3, 3, 1])
Args:
label (str): The name of the column
Returns:
An instance of ``numpy.array``.
"""
return self._columns[label]
"""Returns the values of a column as an array."""
warnings.warn("deprecated", DeprecationWarning)
return self.column(label)

def column_index(self, column_label):
"""Return the index of a column."""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ def test_basic(t):
z | 1 | 10
""")

def test_values(table):
def test_column(table):
"""Test table.values()"""
assert_array_equal(table.values('letter'), np.array(['a', 'b', 'c', 'z']))
assert_array_equal(table.values('count'), np.array([9, 3, 3, 1]))
assert_array_equal(table.column('letter'), np.array(['a', 'b', 'c', 'z']))
assert_array_equal(table.column(1), np.array([9, 3, 3, 1]))


def test_basic_points(t):
Expand Down

0 comments on commit 7410de6

Please sign in to comment.