Skip to content

Commit

Permalink
Merge pull request #101 from iguinn/bugfix
Browse files Browse the repository at this point in the history
Added test+fix for read multiple files with core.read
  • Loading branch information
iguinn authored Jul 25, 2024
2 parents 497cce9 + 5ac36c8 commit 3c29260
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lgdo/lh5/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def read(
else:
lh5_obj = []
for h5f in lh5_file:
if isinstance(lh5_file, str):
if isinstance(h5f, str):
h5f = h5py.File(h5f, mode="r") # noqa: PLW2901
lh5_obj += h5f[name]
lh5_obj += [h5f[name]]

obj, n_rows_read = _serializers._h5_read_lgdo(
lh5_obj,
Expand Down
9 changes: 9 additions & 0 deletions tests/lh5/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import numpy as np

import lgdo
from lgdo import lh5

Expand Down Expand Up @@ -35,3 +37,10 @@ def test_read_as(lh5_file):
"/data/struct/table", lh5_file, "pd", start_row=1, with_units=True
)
assert obj1.equals(obj2)


def test_read_multiple_files(lh5_file):
lh5_obj = lh5.read("/data/struct/array", [lh5_file, lh5_file, lh5_file])
assert isinstance(lh5_obj, lgdo.Array)
assert len(lh5_obj) == 9
assert (lh5_obj.nda == np.array([2, 3, 4] * 3)).all()

0 comments on commit 3c29260

Please sign in to comment.