Skip to content

Commit

Permalink
Merge pull request #557 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
Table tweaks
  • Loading branch information
GavinHuttley committed Mar 5, 2020
2 parents f5fed68 + e73111e commit 3af1913
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cogent3/util/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,9 @@ def cast_to_array(values):
dtype = "U" if types == {str} else None
try:
result = numpy.array(values, dtype=dtype)
except:
except Exception:
result = numpy.array(values, dtype=object)

return result


Expand Down Expand Up @@ -381,6 +382,7 @@ def __len__(self):
return len(self._order)

def __setitem__(self, key, val):
key = str(key)
if isinstance(val, str):
val = [val]
try:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_util/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def test_empty(self):
self.assertEqual(len(t), 0)
self.assertEqual(t.shape, (0, 2), f"failed with {data}")

def test_keys_are_str(self):
"""all column headers converted to str"""
t = Table(header=["col 1", 2], data=[[0, 1]])
self.assertEqual(t.header, ("col 1", "2"))

def test_no_index_name(self):
"""assigning None has no effect"""
t = Table(header=self.t5_header, data=self.t5_rows)
Expand Down

0 comments on commit 3af1913

Please sign in to comment.