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
4 changes: 3 additions & 1 deletion src/mdio/api/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def _normalize_path(path: UPath | Path | str) -> UPath:


def _normalize_storage_options(path: UPath) -> dict[str, Any] | None:
return None if len(path.storage_options) == 0 else path.storage_options
# UPath.storage_options returns a read-only mappingproxy which cannot be pickled. Copy it into a
# plain dict so callers can safely pass it across process boundaries (e.g. spawned workers).
return None if len(path.storage_options) == 0 else dict(path.storage_options)


def open_mdio(input_path: UPath | Path | str, chunks: T_Chunks = None) -> xr_Dataset:
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/test_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Tests for low-level MDIO API I/O helpers."""

from __future__ import annotations

from types import MappingProxyType

from upath import UPath

from mdio.api.io import _normalize_storage_options


def test_normalize_storage_options_is_not_mappingproxy() -> None:
"""Storage options must not be a mappingproxy.

`UPath.storage_options` returns a read-only ``mappingproxy`` that cannot be pickled. Blocked-I/O
ingestion passes these options into ``ProcessPoolExecutor`` initargs, so a mappingproxy breaks
spawned workers with ``TypeError: cannot pickle 'mappingproxy' object``.
"""
storage_options = _normalize_storage_options(UPath("s3://bucket/key", key="access", secret="secret")) # noqa: S106

assert not isinstance(storage_options, MappingProxyType)