Skip to content

Commit 20ace60

Browse files
authored
Utf8 regression (#1000)
* BUG: unable to parse non-trivial UTF-8 characters * BUG: use .asstr per h5py recommendations ('https://docs.h5py.org/en/latest/strings.html#reading-strings') * asstr does not handle an empty dataset * MAINT: in1d was deprecated in numpy switch to isin * DOC: changelog mention * macos-13 no longer supported
1 parent 2b81a01 commit 20ace60

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎.github/workflows/python-package-conda.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
strategy:
8282
fail-fast: true
8383
matrix:
84-
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm, macos-13]
84+
os: [ubuntu-latest, macos-latest, windows-latest, ubuntu-24.04-arm, macos-15-intel]
8585
python_version: ${{ fromJSON(needs.conf.outputs.supported_pythons) }}
8686
use_conda: [true, false]
8787
steps:

‎ChangeLog.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
BIOM-Format ChangeLog
22
=====================
33

4+
biom-2.1.18-dev
5+
---------------
6+
7+
Bug fixes:
8+
9+
* A regression with parse of UTF-8 characters was introduced, reported [here](https://forum.qiime2.org/t/feature-table-gives-ascii-codec-cant-decode-byte-0xc3-in-position-4-error/33858/7)
10+
411
biom-2.1.17
512
-----------
613

‎biom/table.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,11 +4182,15 @@ def ensure_utf8(x):
41824182
def axis_load(grp):
41834183
"""Loads all the data of the given group"""
41844184
# fetch all of the IDs
4185-
ids = grp['ids'][:]
4185+
ids = grp['ids']
41864186

41874187
if ids.size > 0:
4188+
ids = ids.asstr()[:]
41884189
ids_dtype = 'U%d' % max([len(v) for v in ids])
41894190
ids = np.asarray(ids, dtype=ids_dtype)
4191+
else:
4192+
# .asstr does not handle an empty dataset
4193+
ids = ids[:]
41904194

41914195
parser = defaultdict(lambda: general_parser)
41924196
parser['taxonomy'] = vlen_list_of_str_parser
@@ -4234,7 +4238,7 @@ def _get_ids(source_ids, desired_ids):
42344238
else:
42354239
desired_ids = np.asarray(desired_ids)
42364240
# Get the index of the source ids to include
4237-
idx = np.in1d(source_ids, desired_ids)
4241+
idx = np.isin(source_ids, desired_ids)
42384242
# Retrieve only the ids that we are interested on
42394243
ids = source_ids[idx]
42404244
# Check that all desired ids have been found on source ids

‎biom/tests/test_parse.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import numpy as np
1818
import numpy.testing as npt
1919

20+
from biom import example_table
2021
from biom.parse import (generatedby, MetadataMap, parse_biom_table, parse_uc,
2122
load_table, save_table)
2223
from biom.table import Table
@@ -283,6 +284,15 @@ def test_parse_adjacency_table_no_header(self):
283284
obs = Table.from_adjacency(''.join(lines))
284285
self.assertEqual(obs, exp)
285286

287+
def test_parse_biom_table_hdf5_accent_utf8_regression(self):
288+
tab = example_table.copy()
289+
tab.update_ids({i: f'{i}fóó' for i in tab.ids()}, inplace=True)
290+
with NamedTemporaryFile(delete=False) as tmpfile:
291+
with h5py.File(tmpfile.name, 'w') as fp:
292+
tab.to_hdf5(fp, 'asf')
293+
obs = load_table(tmpfile.name)
294+
self.assertEqual(obs, tab)
295+
286296
def test_parse_biom_table_hdf5(self):
287297
"""Make sure we can parse a HDF5 table through the same loader"""
288298
cwd = os.getcwd()

0 commit comments

Comments
 (0)