Skip to content

Fix v2 structured field selection#3996

Open
puneetdixit200 wants to merge 2 commits into
zarr-developers:mainfrom
puneetdixit200:fix-v2-structured-field-selection
Open

Fix v2 structured field selection#3996
puneetdixit200 wants to merge 2 commits into
zarr-developers:mainfrom
puneetdixit200:fix-v2-structured-field-selection

Conversation

@puneetdixit200
Copy link
Copy Markdown

Fixes #3983

This fixes field selection for Zarr v2 arrays with structured dtypes. The read path now decodes chunks into a full-dtype buffer when fields are requested, then copies the selected field view into the caller-facing output buffer. That avoids trying to assign full structured records directly into a single-field or subset-field output dtype.

I added a regression test covering direct string field indexing, basic selection with a single field, and multi-field selection for v2 structured arrays.

AI assistance: OpenAI GPT-5 was used during implementation; I reviewed the change and ran the checks below.

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
    • Not applicable: no user-facing API was added or changed.
  • New/modified features documented in docs/user-guide/*.md
    • Not applicable: this is a bug fix.
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
    • Pending after PR creation.
  • Test coverage is 100% (Codecov passes)
    • Pending after PR creation.

Local checks:

  • .venv/bin/python -m pytest tests/test_v2.py -q
  • .venv/bin/python -m pytest tests/test_v2.py::test_structured_dtype_field_selection tests/test_indexing.py::test_get_selections_with_fields -q
  • .venv/bin/python -m ruff check src/zarr/core/array.py tests/test_v2.py
  • .venv/bin/python -m ruff format --check src/zarr/core/array.py tests/test_v2.py
  • git diff --check

@puneetdixit200 puneetdixit200 force-pushed the fix-v2-structured-field-selection branch from 9632e91 to e9e8350 Compare May 21, 2026 08:03
@puneetdixit200
Copy link
Copy Markdown
Author

Pushed a follow-up for the min-deps CI failure. The failure was caused by package version discovery selecting the auxiliary zarr_metadata-v0.2.0 tag, which made the in-tree package report 0.2.1.dev...; numcodecs.zarr3 then rejected it as < 3.0.0.

Additional local checks:

$ UV_CACHE_DIR=$PWD/.uv-cache uv run --with hatch --with hatch-vcs hatch version
3.2.2.dev30+ge9e83506.d20260521
$ UV_CACHE_DIR=$PWD/.uv-cache uv run --with 'numcodecs==0.14.1' python - <<'PY'
import zarr
print(zarr.__version__)
import numcodecs.zarr3
print('numcodecs.zarr3 import ok')
PY
3.2.2.dev30+ge9e83506.d20260521
numcodecs.zarr3 import ok
$ UV_CACHE_DIR=$PWD/.uv-cache uv run --with 'numcodecs==0.14.1' pytest tests/test_codecs/test_numcodecs.py::test_get_codec_class -q
.....................                                                    [100%]
21 passed in 0.05s
$ UV_CACHE_DIR=$PWD/.uv-cache uv run pytest tests/test_v2.py::test_structured_dtype_field_selection tests/test_indexing.py::test_get_selections_with_fields -q
.x                                                                       [100%]
1 passed, 1 xfailed in 0.27s
$ UV_CACHE_DIR=$PWD/.uv-cache uv run ruff check pyproject.toml src/zarr/core/array.py tests/test_v2.py && git diff --check
All checks passed!

@d-v-b
Copy link
Copy Markdown
Contributor

d-v-b commented May 21, 2026

hi @puneetdixit200 before you get too deep in to this PR, it might make sense to resolve the points I raised in #3983

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.43%. Comparing base (27abff2) to head (1719914).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3996      +/-   ##
==========================================
+ Coverage   93.39%   93.43%   +0.04%     
==========================================
  Files          88       88              
  Lines       11839    11843       +4     
==========================================
+ Hits        11057    11066       +9     
+ Misses        782      777       -5     
Files with missing lines Coverage Δ
src/zarr/core/array.py 97.88% <100.00%> (+<0.01%) ⬆️

... and 1 file with indirect coverage changes

🚀 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.

Regression in support for indexing into structured arrays within a Zarr store (v2 -> v3)

2 participants