Skip to content

Commit 05e6061

Browse files
authored
Merge pull request #120 from legend-exp/fix
Fix `read_as()` with file list of length 1
2 parents 4f3743c + 4fd74ee commit 05e6061

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

src/lgdo/lh5/core.py

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def read(
120120
lh5_obj = lh5_file[name]
121121
else:
122122
lh5_files = list(lh5_file)
123+
123124
n_rows_read = 0
124125
obj_buf_is_new = False
125126

@@ -353,5 +354,8 @@ def read_as(
353354
# NOTE: providing a buffer does not make much sense
354355
obj = read(name, lh5_file, **kwargs1)
355356

357+
if isinstance(obj, tuple):
358+
obj = obj[0]
359+
356360
# and finally return a view
357361
return obj.view_as(library, **kwargs2)

src/lgdo/types/vectorofvectors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def __iter__(self) -> Iterator[NDArray]:
503503
def __str__(self) -> str:
504504
string = self.view_as("ak").show(stream=None)
505505

506-
string = string.strip().removesuffix("]")
506+
string = str(string).strip().removesuffix("]")
507507
string += "\n]"
508508

509509
tmp_attrs = self.attrs.copy()

tests/lh5/test_core.py

+2
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)