Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
magland committed Mar 20, 2024
1 parent 4a98763 commit fc3978a
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 281 deletions.
4 changes: 3 additions & 1 deletion lindi/LindiH5pyFile/LindiH5pyDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ def _resolve_references(x: Any):
else:
for k, v in x.items():
x[k] = _resolve_references(v)
elif isinstance(x, LindiZarrWrapperReference):
return LindiH5pyReference(x)
elif isinstance(x, list):
for i, v in enumerate(x):
x[i] = _resolve_references(v)
elif isinstance(x, np.ndarray):
if x.dtype == object:
if x.dtype == object or x.dtype is None:
view_1d = x.reshape(-1)
for i in range(len(view_1d)):
view_1d[i] = _resolve_references(view_1d[i])
Expand Down
13 changes: 12 additions & 1 deletion lindi/LindiH5pyFile/LindiH5pyFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .LindiH5pyGroup import LindiH5pyGroup
from .LindiH5pyDataset import LindiH5pyDataset
from ..LindiZarrWrapper import LindiZarrWrapper, LindiZarrWrapperGroup, LindiZarrWrapperDataset
from ..LindiZarrWrapper import LindiZarrWrapper, LindiZarrWrapperGroup, LindiZarrWrapperDataset, LindiZarrWrapperReference
from .LindiH5pyAttributes import LindiH5pyAttributes
from .LindiH5pyReference import LindiH5pyReference

Expand Down Expand Up @@ -99,6 +99,10 @@ def __repr__(self):
# Group methods

def __getitem__(self, name):
if isinstance(name, LindiZarrWrapperReference):
# annoyingly we have to do this because references
# in arrays of compound types will come in as LindiZarrWrapperReference
name = LindiH5pyReference(name)
if isinstance(name, LindiH5pyReference):
assert isinstance(self._file_object, LindiZarrWrapper)
x = self._file_object[name._reference]
Expand All @@ -117,6 +121,13 @@ def __getitem__(self, name):
return LindiH5pyDataset(x, self)
else:
raise Exception(f"Unexpected type for resolved reference at path {name}: {type(x)}")
# if it contains slashes, it's a path
if isinstance(name, str) and "/" in name:
parts = name.split("/")
x = self._the_group
for part in parts:
x = x[part]
return x
return self._the_group[name]

def get(self, name, default=None, getclass=False, getlink=False):
Expand Down
7 changes: 5 additions & 2 deletions lindi/LindiH5pyFile/LindiH5pyLink.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
class LindiH5pyHardLink:
import h5py


class LindiH5pyHardLink(h5py.HardLink):
def __init__(self):
pass


class LindiH5pySoftLink:
class LindiH5pySoftLink(h5py.SoftLink):
def __init__(self, path: str):
self._path = path

Expand Down
7 changes: 6 additions & 1 deletion lindi/LindiZarrWrapper/LindiZarrWrapperReference.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class LindiZarrWrapperReference:
import h5py


# We need h5py.Reference as a base class so that type checking will be okay for
# arrays of compound types that contain references
class LindiZarrWrapperReference(h5py.Reference):
def __init__(self, obj: dict):
self._object_id = obj["object_id"]
self._path = obj["path"]
Expand Down
Loading

0 comments on commit fc3978a

Please sign in to comment.