Skip to content

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

Closed

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

Activity

  1. added
    bugPotential issues with the zarr-python library
    on Jul 25, 2025
  2. K-Meech commented on Jul 28, 2025

    @K-Meech
    ContributorAuthor

    The issue seems to be inside make_store_path in src/zarr/storage/_common.py:

    • _read_only is only set for mode == 'r'
    • then a local store is opened like: await LocalStore.open(root=Path(store_like), read_only=_read_only) (where __read_only is False for r+ mode)
    • Then inside LocalStore in src/zarr/storage/_local.py - a new directory is made by _open in every case where _read_only = False
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

    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