Skip to content

Commit

Permalink
Merge pull request #120 from legend-exp/fix
Browse files Browse the repository at this point in the history
Fix `read_as()` with file list of length 1
  • Loading branch information
gipert authored Nov 15, 2024
2 parents 4f3743c + 4fd74ee commit 05e6061
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/lgdo/lh5/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def read(
lh5_obj = lh5_file[name]
else:
lh5_files = list(lh5_file)

n_rows_read = 0
obj_buf_is_new = False

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

if isinstance(obj, tuple):
obj = obj[0]

# and finally return a view
return obj.view_as(library, **kwargs2)
2 changes: 1 addition & 1 deletion src/lgdo/types/vectorofvectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def __iter__(self) -> Iterator[NDArray]:
def __str__(self) -> str:
string = self.view_as("ak").show(stream=None)

string = string.strip().removesuffix("]")
string = str(string).strip().removesuffix("]")
string += "\n]"

tmp_attrs = self.attrs.copy()
Expand Down
2 changes: 2 additions & 0 deletions tests/lh5/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def test_read_as(lh5_file):
)
assert obj1.equals(obj2)

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


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

0 comments on commit 05e6061

Please sign in to comment.