From 5ac36c8e674341c27315ef55589f9e820c8f17a4 Mon Sep 17 00:00:00 2001 From: Ian Guinn Date: Thu, 25 Jul 2024 09:36:48 -0400 Subject: [PATCH] Added test+fix for read multiple files with core.read --- src/lgdo/lh5/core.py | 4 ++-- tests/lh5/test_core.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/lgdo/lh5/core.py b/src/lgdo/lh5/core.py index a98081ca..335ac351 100644 --- a/src/lgdo/lh5/core.py +++ b/src/lgdo/lh5/core.py @@ -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, diff --git a/tests/lh5/test_core.py b/tests/lh5/test_core.py index f70665b7..d908b235 100644 --- a/tests/lh5/test_core.py +++ b/tests/lh5/test_core.py @@ -1,5 +1,7 @@ from __future__ import annotations +import numpy as np + import lgdo from lgdo import lh5 @@ -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()