Skip to content

Added ArrayNotFoundError #3367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ruaridhg
Copy link

@ruaridhg ruaridhg commented Aug 11, 2025

Fixes #2961

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/user-guide/*.rst
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions bot added the needs release notes Automatically applied to PRs which haven't added release notes label Aug 11, 2025
@github-actions github-actions bot removed the needs release notes Automatically applied to PRs which haven't added release notes label Aug 11, 2025
@d-v-b
Copy link
Contributor

d-v-b commented Aug 11, 2025

thank you, this looks good. we should make sure we cover all the places in the codebase where we try to read an array. maybe it's just the 1 place you found, but we should double-check.

Copy link
Contributor

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two inline comments. In addition, did you thoroughly check that there's only a single place where an ArrayNotFoundError should be raised?

@@ -161,7 +166,7 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
assert z.read_only

# path not found
with pytest.raises(FileNotFoundError):
with pytest.raises(ArrayNotFoundError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently failing the tests, because it actually raises a GroupNotFoundError now. I think the sensible thing to do here would be to create another new error, NodeNotFoundError, that is raised when a non-specific function is used (e.g., just open) to try and open either an array or a group.

@d-v-b
Copy link
Contributor

d-v-b commented Aug 12, 2025

it might be helpful to check out #3012, which unfortunately was too bloated to merge

Copy link

codecov bot commented Aug 19, 2025

Codecov Report

❌ Patch coverage is 81.48148% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.51%. Comparing base (4b26501) to head (1b883fa).

Files with missing lines Patch % Lines
src/zarr/errors.py 72.22% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3367      +/-   ##
==========================================
- Coverage   94.55%   94.51%   -0.05%     
==========================================
  Files          79       79              
  Lines        9447     9466      +19     
==========================================
+ Hits         8933     8947      +14     
- Misses        514      519       +5     
Files with missing lines Coverage Δ
src/zarr/api/asynchronous.py 87.62% <100.00%> (ø)
src/zarr/core/array.py 97.11% <100.00%> (+<0.01%) ⬆️
src/zarr/errors.py 86.84% <72.22%> (-13.16%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -185,10 +192,27 @@ async def test_open_array(memory_store: MemoryStore, zarr_format: ZarrFormat) ->
assert z.read_only

# path not found
with pytest.raises(FileNotFoundError):
with pytest.raises((NodeNotFoundError, GroupNotFoundError)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this raising two errors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah fair point, I was getting errors in my tests with only 1 error raised but now I've changed it so GroupNotFoundError and ArrayNotFoundError inherit from NodeNotFoundError

Comment on lines +65 to +72
def __init__(self, *args: Any) -> None:
if len(args) == 1:
# Pre-formatted message
super(BaseZarrError, self).__init__(args[0])
else:
# Store and path arguments - format them
_msg = "No group found in store {!r} at path {!r}"
super(BaseZarrError, self).__init__(_msg.format(*args))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a separate PR we should remove the pre-formatting of exception messages, and make every exception just take a single string

@@ -0,0 +1 @@
Added `~zarr.errors.ArrayNotFoundError`, which is raised when attempting to open a zarr array that does not exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Added `~zarr.errors.ArrayNotFoundError`, which is raised when attempting to open a zarr array that does not exist.
Added `zarr.errors.ArrayNotFoundError`, which is raised when attempting to open a zarr array that does not exist, and `zarr.errors.NodeNotFoundError`, which is raised when failing to open an array or a group in a context where either an array or a group was expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zarr.errors ArrayNotFoundError is gone in zarr 3.0
3 participants