Skip to content

Using r+ mode with zarr.open creates an empty directory #3295

@K-Meech

Description

@K-Meech

Zarr version

v3.1.0

Numcodecs version

0.16.1

Python Version

3.13

Operating System

Windows

Installation

Using pip into a virtual environment

Description

Opening a non-existent location via zarr.open with r+ mode (see 'steps to reproduce') creates an empty directory at that location. Given the description in the zarr.open docstring: 'r+ means read/write (must exist)', I would expect no files to be changed before the GroupNotFoundError is thrown.

Steps to reproduce

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "zarr@git+https://github.com/zarr-developers/zarr-python.git@main",
# ]
# ///
#
# This script automatically imports the development branch of zarr to check for issues

import zarr

# creates the new directory data/images/test_r_plus.zarr, then throws GroupNotFoundError
zarr_object = zarr.open(store="data/images/test_r_plus.zarr", mode="r+")

# Using mode r, doesn't create a new directory before it throw GroupNotFoundError
zarr_object = zarr.open(store="data/images/test_r.zarr", mode="r")

Additional output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPotential issues with the zarr-python library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions