diff --git a/kerchunk/hdf.py b/kerchunk/hdf.py index 549923d..e3edd26 100644 --- a/kerchunk/hdf.py +++ b/kerchunk/hdf.py @@ -1,6 +1,7 @@ import base64 import io import logging +import pathlib from typing import Union, BinaryIO import fsspec.core @@ -91,7 +92,7 @@ def __init__( # Open HDF5 file in read mode... lggr.debug(f"HDF5 file: {h5f}") - if isinstance(h5f, str): + if isinstance(h5f, (pathlib.Path, str)): fs, path = fsspec.core.url_to_fs(h5f, **(storage_options or {})) self.input_file = fs.open(path, "rb") url = h5f diff --git a/kerchunk/tests/test_hdf.py b/kerchunk/tests/test_hdf.py index 69fd22b..6d374e8 100644 --- a/kerchunk/tests/test_hdf.py +++ b/kerchunk/tests/test_hdf.py @@ -199,6 +199,21 @@ def test_string_embed(): assert (z.vlen_str[1:] == "").all() +def test_string_pathlib(): + # essentially copied test above + import pathlib + + fn = osp.join(here, "vlen.h5") + h = kerchunk.hdf.SingleHdf5ToZarr(pathlib.Path(fn), vlen_encode="embed") + out = h.translate() + fs = fsspec.filesystem("reference", fo=out) + assert txt in fs.references["vlen_str/0"] + z = zarr.open(fs.get_mapper()) + assert z.vlen_str.dtype == "O" + assert z.vlen_str[0] == txt + assert (z.vlen_str[1:] == "").all() + + def test_string_null(): fn = osp.join(here, "vlen.h5") h = kerchunk.hdf.SingleHdf5ToZarr(fn, fn, vlen_encode="null", inline_threshold=0)