Skip to content

fixing scalar array handling#835

Closed
neilSchroeder wants to merge 11 commits intozarr-developers:mainfrom
neilSchroeder:fix/issue-834-zarr-scalar-array-bug
Closed

fixing scalar array handling#835
neilSchroeder wants to merge 11 commits intozarr-developers:mainfrom
neilSchroeder:fix/issue-834-zarr-scalar-array-bug

Conversation

@neilSchroeder
Copy link
Contributor

@neilSchroeder neilSchroeder commented Nov 12, 2025

Summary

This PR fixes an incorrect test assertion for Zarr V3 scalar array chunk keys, as well as fixing the _handle_scalar_array function to return a correctly formatted dictionary.

Problem

The test test_scalar_chunk_mapping incorrectly expected Zarr V3 scalar arrays to use "c" as the chunk key in the manifest. This was based on a misunderstanding of how Zarr V3 stores scalar arrays.

What Actually Happens

  • Zarr V2: Stores scalar data at file path "0" → manifest chunk key: "0"
  • Zarr V3: Stores scalar data at file path "c" → manifest chunk key: "0"

The _handle_scalar_array function in zarr.py correctly handles this difference by:

  1. Accepting the storage path as a parameter (scalar_key = "0" for V2, "c" for V3)
  2. Always returning "0" as the chunk coordinate key in the manifest

This normalization is necessary because:

  • The chunk manifest validation requires numeric dot-separated coordinates (regex pattern: ([1-9]+\d*|0)+(\.[1-9]+\d*|0)*$)
  • The key "c" would fail validation since it's not numeric
  • Both V2 and V3 scalar arrays logically represent the same single chunk at coordinate (0,), so they should have the same manifest key

Context

I tried to actually open a V2 scalar array and it threw an error. I've confirmed that with this fix it correctly reads both v2 and v3 arrays.

@neilSchroeder
Copy link
Contributor Author

@TomNicholas apologies, but it looks like I didn't do an actual stress test to see if real files would actually open.

@neilSchroeder neilSchroeder marked this pull request as ready for review November 12, 2025 20:53
@neilSchroeder neilSchroeder marked this pull request as draft November 12, 2025 22:05
@codecov
Copy link

codecov bot commented Nov 12, 2025

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.40%. Comparing base (847dbde) to head (8fa6068).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
virtualizarr/parsers/zarr.py 95.45% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #835      +/-   ##
==========================================
- Coverage   88.43%   88.40%   -0.03%     
==========================================
  Files          35       35              
  Lines        1988     2009      +21     
==========================================
+ Hits         1758     1776      +18     
- Misses        230      233       +3     
Files with missing lines Coverage Δ
virtualizarr/parsers/zarr.py 97.23% <95.45%> (-1.52%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Bug: scalar arrays fail to open with ValueError: Invalid format for chunk key

1 participant