diff --git a/CHANGELOG.md b/CHANGELOG.md index 065ef061..cce0d6cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 1.0.0 (Upcoming) ### Enhancements * Added initial refactor of export, supporting references and internal/external links from Zarr to Zarr. @mavaylon1 [#194](https://github.com/hdmf-dev/hdmf-zarr/pull/194) - +* Added support for Pathlib paths. @mavaylon1 [#212](https://github.com/hdmf-dev/hdmf-zarr/pull/212) ## 0.9.0 (September 16, 2024) ### Enhancements diff --git a/src/hdmf_zarr/backend.py b/src/hdmf_zarr/backend.py index 70a02b25..cb7e629b 100644 --- a/src/hdmf_zarr/backend.py +++ b/src/hdmf_zarr/backend.py @@ -48,6 +48,9 @@ from hdmf.query import HDMFDataset from hdmf.container import Container +from pathlib import Path + + # Module variables ROOT_NAME = 'root' """ @@ -84,7 +87,7 @@ def can_read(path): return False @docval({'name': 'path', - 'type': (str, *SUPPORTED_ZARR_STORES), + 'type': (str, Path, *SUPPORTED_ZARR_STORES), 'doc': 'the path to the Zarr file or a supported Zarr store'}, {'name': 'manager', 'type': BuildManager, 'doc': 'the BuildManager to use for I/O', 'default': None}, {'name': 'mode', 'type': str, @@ -115,6 +118,8 @@ def __init__(self, **kwargs): else: self.__synchronizer = synchronizer self.__mode = mode + if isinstance(path, Path): + path = str(path) self.__path = path self.__file = None self.__storage_options = storage_options @@ -195,7 +200,7 @@ def is_remote(self): 'type': (NamespaceCatalog, TypeMap), 'doc': 'the NamespaceCatalog or TypeMap to load namespaces into'}, {'name': 'path', - 'type': (str, *SUPPORTED_ZARR_STORES), + 'type': (str, Path, *SUPPORTED_ZARR_STORES), 'doc': 'the path to the Zarr file or a supported Zarr store'}, {'name': 'storage_options', 'type': dict, 'doc': 'Zarr storage options to read remote folders', diff --git a/tests/unit/test_zarrio.py b/tests/unit/test_zarrio.py index d10cb9f9..2f4ccfa6 100644 --- a/tests/unit/test_zarrio.py +++ b/tests/unit/test_zarrio.py @@ -27,6 +27,7 @@ import shutil import warnings from numpy.testing import assert_array_equal +import pathlib CUR_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -113,6 +114,16 @@ def setUp(self): self.store = [NestedDirectoryStore(p) for p in self.store_path] +######################################### +# Pathlib Tests +######################################### +class TestPathlib(BaseTestZarrWriter): + """Test writing of builder with Zarr using a custom DirectoryStore""" + def setUp(self): + super().setUp() + self.store = pathlib.Path(self.store_path) + + ######################################### # Consolidate Metadata tests #########################################