Skip to content

Commit 84843a5

Browse files
committed
Support for hdf5 proxies in lazy operands
1 parent bdc4b87 commit 84843a5

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

caterva2/hdf5.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ def cparams(self):
405405
def dparams(self):
406406
return self.b2arr.dparams
407407

408+
@property
409+
def schunk(self):
410+
# This is basically needed to certificate that it is an NDArray in the LazyArray machinery
411+
return self.b2arr.schunk
412+
408413
@property
409414
def fields(self) -> Mapping[str, numpy.dtype]:
410415
return self.b2arr.fields

caterva2/services/srv_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,16 @@ def get_relpath(ndarr, cache, personal, shared, public):
181181
path = pathlib.Path(ndarr.schunk.urlpath)
182182
if shared is not None and path.is_relative_to(shared):
183183
# Shared: /.../<shared>/<subpath> to <path> (i.e. no change)
184-
return path
184+
path = path.relative_to(shared)
185+
parts = list(path.parts)
186+
parts[0] = "@shared"
187+
return pathlib.Path(*parts)
185188
elif public is not None and path.is_relative_to(public):
186189
# Shared: /.../<public>/<subpath> to <path> (i.e. no change)
187-
return path
190+
path = path.relative_to(public)
191+
parts = list(path.parts)
192+
parts[0] = "@public"
193+
return pathlib.Path(*parts)
188194
try:
189195
# Cache: /.../<root>/<subpath> to <root>/<subpath>
190196
path = path.relative_to(cache)

caterva2/services/sub.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,12 @@ def open_b2(abspath, path):
293293
for key, value in operands.items():
294294
if value is None:
295295
raise ValueError(f'Missing operand "{key}"')
296-
if "proxy-source" in value.schunk.meta:
297-
# Save operand as Proxy, see blosc2.open doc for more info
296+
vlmetaval = value.schunk.vlmeta
297+
if "proxy-source" in value.schunk.meta or (
298+
"_ftype" in vlmetaval and vlmetaval["_ftype"] == "hdf5"
299+
):
300+
# Save operand as Proxy, see blosc2.open doc for more info.
301+
# Or, it can be an HDF5 dataset too (which should be handled in the next call)
298302
relpath = srv_utils.get_relpath(
299303
value, settings.cache, settings.personal, settings.shared, settings.public
300304
)

0 commit comments

Comments
 (0)