Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize metadata on parse #853

Merged
merged 3 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions biom/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ def _identify_bad_value(dtype, fields):


def general_parser(x):
if isinstance(x, bytes):
x = x.decode('utf8')
return x


Expand Down
15 changes: 14 additions & 1 deletion biom/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
list_dict_to_sparse, dict_to_sparse,
coo_arrays_to_sparse, list_list_to_sparse,
nparray_to_sparse, list_sparse_to_sparse,
_identify_bad_value)
_identify_bad_value, general_parser)
from biom.parse import parse_biom_table
from biom.err import errstate

Expand Down Expand Up @@ -615,6 +615,19 @@ def test_max_whole(self):
obs = self.simple_derived.max('whole')
npt.assert_equal(obs, exp)

def test_general_parser(self):
test_and_exp = [(b'foo', 'foo'),
('foo', 'foo'),
(b'', ''),
('', ''),
(b'10', '10'),
('10', '10'),
(b'3.14', '3.14'),
('3.14', '3.14')]
for test, exp in test_and_exp:
obs = general_parser(test)
self.assertEqual(obs, exp)

@npt.dec.skipif(HAVE_H5PY is False, msg='H5PY is not installed')
def test_from_hdf5_non_hdf5_file_or_group(self):
with self.assertRaises(ValueError):
Expand Down