Skip to content

Fix test collection and mypy under zarr 3.2.x#171

Merged
d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:fix/zarr-3.2-test-compat
Jun 19, 2026
Merged

Fix test collection and mypy under zarr 3.2.x#171
d-v-b merged 3 commits into
zarr-developers:mainfrom
d-v-b:fix/zarr-3.2-test-compat

Conversation

@d-v-b

@d-v-b d-v-b commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Fixes test-suite collection and type-checking under zarr-python 3.2.x. Part of #165.

zarr-python's CI matrix here pins zarr to 3.0.10/3.1.0, which hides two breakages that occur the moment a user installs the current zarr (3.2.x):

  1. Test collection crashes. zarr 3.2 added a Struct dtype that subclasses Structured and is registered separately. conftest.py did an exact dtype_cls == Structured check, so the new Struct class fell through to the else branch and was instantiated with no fields= argument, raising TypeError at import time and aborting the whole suite. Changed to issubclass(dtype_cls, Structured).

  2. mypy can't parse zarr 3.2. zarr 3.2 uses PEP 695 type X = ... statements, which mypy rejects under python_version = "3.11". Bumped the mypy target to 3.12. (The package still supports 3.11 at runtime — this only affects the type-check target.)

This does not add zarr 3.2 to the CI matrix: full 3.2.x support also needs to address ~187 API-deprecation test failures, which is a larger separate effort. This PR just stops a 3.2.x install from breaking collection and type-checking outright.

🤖 Generated with Claude Code

d-v-b and others added 2 commits June 15, 2026 09:37
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d-v-b added a commit to d-v-b/pydantic-zarr that referenced this pull request Jun 15, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d-v-b added a commit to d-v-b/pydantic-zarr that referenced this pull request Jun 15, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
d-v-b added a commit that referenced this pull request Jun 19, 2026
…ported) (#167)

* Fix unreachable match arms in parse_dtype_v3 (float64/complex64)

Two match arms in `parse_dtype_v3` (in both `pydantic_zarr.v3` and
`pydantic_zarr.experimental.v3`) were copy-paste errors: the third arm
used `Float16DType` instead of `Float64DType`, and the fourth used
`Float32DType` instead of `Complex64DType`. This made `float64` and
`complex64` dtypes unreachable, causing `ValueError: Unsupported dtype`
for those types. Fixes part of #165.

Also fixes the test conftest to handle zarr 3.2.1's new `Struct` dtype
class (a subclass of `Structured`) by using `issubclass` instead of
`==` in the special-case branch, and bumps the mypy `python_version`
to 3.12 to match zarr >=3.2.0's minimum Python requirement.

Adds parametrized regression tests covering all 13 supported numpy
dtypes through `parse_dtype_v3` in both test suites.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add changelog fragment for PR #167

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Move zarr 3.2.x compat changes to dedicated PR #171

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* make tests pass

* import struct under conditional

* robust import

* pin pytest and fix iterator issue in test fixtures

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
d-v-b added a commit that referenced this pull request Jun 19, 2026
…mp (#169)

* Fix NameError in v3 from_zarr/ArraySpec.like and KeyError in model_dump

- ArraySpec.like in v3.py used bare `isinstance(other, zarr.Array)` with zarr
  only imported under TYPE_CHECKING, causing NameError at runtime; switch to
  the sys.modules guard already used by GroupSpec.like.
- Module-level from_zarr in v3.py and experimental/v3.py referenced zarr.Array
  with no runtime import; add `import zarr` inside the function body (mirrors v2.py).
- ArraySpec.model_dump in both v3.py and experimental/v3.py did
  d["dimension_names"] unconditionally, raising KeyError when dimension_names
  was excluded via model_dump(exclude={...}); use d.get() + pop(key, None).
- Fix conftest.py for zarr 3.2 compatibility: Structured was renamed to Struct
  and requires fields; detect whichever name is present in the registry.
- Bump mypy python_version from 3.11 to 3.12 so mypy can parse zarr 3.2
  which uses the PEP 695 `type` statement syntax.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Add towncrier fragment for PR #169

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Move zarr 3.2.x compat changes to dedicated PR #171

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
@d-v-b d-v-b marked this pull request as ready for review June 19, 2026 11:08
@d-v-b d-v-b merged commit 679e7d8 into zarr-developers:main Jun 19, 2026
16 checks passed
@d-v-b d-v-b deleted the fix/zarr-3.2-test-compat branch June 19, 2026 11:13
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.

1 participant