Skip to content

Commit 320ae8c

Browse files
committed
[bug fix] fix read_as() with file list of length 1
1 parent 4f3743c commit 320ae8c

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/lgdo/lh5/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,17 @@ def read(
113113
`n_rows_read` will be``1``. For tables it is redundant with
114114
``table.loc``. If `obj_buf` is ``None``, only `object` is returned.
115115
"""
116+
if not isinstance(lh5_file, str | h5py.File) and len(list(lh5_file)) == 1:
117+
lh5_file = lh5_file[0]
118+
116119
if isinstance(lh5_file, h5py.File):
117120
lh5_obj = lh5_file[name]
118121
elif isinstance(lh5_file, str):
119122
lh5_file = h5py.File(lh5_file, mode="r", locking=locking)
120123
lh5_obj = lh5_file[name]
121124
else:
122125
lh5_files = list(lh5_file)
126+
123127
n_rows_read = 0
124128
obj_buf_is_new = False
125129

tests/lh5/test_core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def test_read_as(lh5_file):
3838
)
3939
assert obj1.equals(obj2)
4040

41+
obj2 = lh5.read_as("/data/struct/table", [lh5_file], "ak")
42+
4143

4244
def test_read_multiple_files(lh5_file):
4345
lh5_obj = lh5.read("/data/struct/array", [lh5_file, lh5_file, lh5_file])

0 commit comments

Comments
 (0)