Skip to content

zarr.open and friends should handle Path objects #601

Description

@clbarnes

Strictly, anything which doesn't cause os.fspath to raise a TypeError.

Minimal, reproducible code sample, a copy-pastable example if possible

import zarr
from pathlib import Path

path_str = "path/to/array.zarr"

zarr.open(path_str)  # works fine
zarr.open(Path(path_str))  # fails with TypeError because it's not a str and not iterable

Problem description

pathlib is great and everyone should use it whenever appropriate. Personally, I even subclass PurePosixPath for manipulations of object names inside hdf5/ zarr/ n5 containers.

People with zarr objects on the file system should want to use Paths to refer to them, so zarr should support people doing so.

This should just be a case of trying os.fspath on the store/path argument(s) for most of the functions in convenience.

Version and installation information

Please provide the following:

  • Value of zarr.__version__: 2.4.0
  • Value of numcodecs.__version__: 0.6.4
  • Version of Python interpreter: 3.8.5
  • Operating system (Linux/Windows/Mac): Linux
  • How Zarr was installed (e.g., "using pip into virtual environment", or "using conda"): pip in virtual environment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions