Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/spikeinterface/core/tests/test_zarrextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,12 @@ def test_ZarrSortingExtractor_lazy_search(tmp_path):
test_ZarrSortingExtractor(tmp_path)
test_ZarrSampleIndexSearch(tmp_path)
test_ZarrSortingExtractor_lazy_search(tmp_path)


def test_zarr_path_with_hash(tmp_path):
# zarr 3 parses str paths as URLs, truncating them at '#'
folder = tmp_path / "Record Node 103#Probe.zarr"
sorting = generate_sorting(durations=[2], num_units=3)
ZarrSortingExtractor.write_sorting(sorting, folder)
loaded = ZarrSortingExtractor(folder)
assert loaded.get_num_units() == 3
12 changes: 12 additions & 0 deletions src/spikeinterface/core/zarr_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,15 @@ def build_codec_pipeline(filters=None, compressors=None):
codec_kwargs["serializer"] = serializers[0] if len(serializers) == 1 else "auto"
codec_kwargs["compressors"] = byte_compressors
return codec_kwargs


def local_zarr_store(path):
"""
Return a zarr LocalStore for local paths (remote paths are returned as str).
Passing a plain str to zarr 3 parses it as a URL, so characters like '#' truncate the path.
"""
from .core_tools import is_path_remote

if is_path_remote(str(path)):
return str(path)
Comment thread
alejoe91 marked this conversation as resolved.
Resolved
return zarr.storage.LocalStore(path)
8 changes: 4 additions & 4 deletions src/spikeinterface/core/zarrextractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
is_path_remote,
)
from .job_tools import split_job_kwargs, fix_job_kwargs
from .zarr_tools import iterate_zarr_group, adjust_chunks_shards_and_job_kwargs, build_codec_pipeline
from .zarr_tools import local_zarr_store, iterate_zarr_group, adjust_chunks_shards_and_job_kwargs, build_codec_pipeline
from .time_series_tools import _write_time_series_to_zarr

# The spike vector uses the numcodecs Delta filter (not in the zarr v3 spec) because it greatly
Expand Down Expand Up @@ -97,7 +97,7 @@ def super_zarr_open(folder_path: str | Path, mode: str = "r", storage_options: d
raise ValueError(f"Folder {folder_path} does not exist")
for use_consolidated in use_consolidated_options:
try:
root = zarr.open(str(folder_path), mode=mode, use_consolidated=use_consolidated)
root = zarr.open(local_zarr_store(folder_path), mode=mode, use_consolidated=use_consolidated)
break
except Exception as e:
exception = e
Expand Down Expand Up @@ -266,7 +266,7 @@ def write_recording(
**kwargs,
):
folder_path = create_zarr_path_for_write(folder_path, overwrite=overwrite)
zarr_root = zarr.open(str(folder_path), mode="w", storage_options=storage_options)
zarr_root = zarr.open(local_zarr_store(folder_path), mode="w", storage_options=storage_options)
zarr_root.attrs["zarr_class_info"] = retrieve_importing_provenance(ZarrRecordingExtractor)
add_recording_to_zarr_group(recording, zarr_root, **kwargs)
return ZarrRecordingExtractor(folder_path, storage_options=storage_options)
Expand Down Expand Up @@ -676,7 +676,7 @@ def write_sorting(
Write a sorting extractor to zarr format.
"""
folder_path = create_zarr_path_for_write(folder_path, overwrite=overwrite)
zarr_root = zarr.open(str(folder_path), mode="w", storage_options=storage_options)
zarr_root = zarr.open(local_zarr_store(folder_path), mode="w", storage_options=storage_options)
zarr_root.attrs["zarr_class_info"] = retrieve_importing_provenance(ZarrSortingExtractor)
add_sorting_to_zarr_group(sorting, zarr_root, relative_to=relative_to, **kwargs)
return ZarrSortingExtractor(folder_path, storage_options=storage_options)
Expand Down
Loading