Skip to content

Commit

Permalink
Merge pull request #570 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
BUG: catch additional case in casting to array from string
  • Loading branch information
GavinHuttley committed Mar 12, 2020
2 parents 42e7c71 + 00a2a5b commit 797bfde
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cogent3/util/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def cast_str_to_array(values, static_type=False):
try:
v = eval(v)
all_fail = False
except (NameError, SyntaxError):
except (TypeError, NameError, SyntaxError):
# syntax error from empty strings
pass
result.append(v)
Expand Down
18 changes: 17 additions & 1 deletion tests/test_util/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from numpy.testing import assert_equal

from cogent3 import load_table, make_table
from cogent3.util.table import Table, cast_to_array, formatted_array
from cogent3.util.table import (
Table,
cast_str_to_array,
cast_to_array,
formatted_array,
)


try:
Expand Down Expand Up @@ -1053,6 +1058,17 @@ def test_load_table(self):
table = load_table(path)
self.assertEqual(table.shape, (10, 3))

def test_cast_str_to_array(self):
"""handle processing string series"""
d = [".123|.345", "123"]
r = cast_str_to_array(d, static_type=True)
self.assertTrue("str" in r.dtype.name)
r = cast_str_to_array(d, static_type=False)
self.assertEqual(r.dtype.name, "object")
d = [".123|.345", "123", "()"]
r = cast_str_to_array(d, static_type=False)
self.assertEqual(r[-1], ())


if __name__ == "__main__":
main()

0 comments on commit 797bfde

Please sign in to comment.