Fix unreachable match arms in parse_dtype_v3 (float64/complex64 unsupported)#167
Merged
Merged
Conversation
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 zarr-developers#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>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… into fix/parse-dtype-v3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
parse_dtype_v3insrc/pydantic_zarr/v3.pyandsrc/pydantic_zarr/experimental/v3.pyhad two copy-paste errors in itsmatchstatement. The third and fourth float/complex arms used the wrong type classes:Because Python's structural pattern matching skips duplicate arms, the
float64andcomplex64cases were unreachable and fell through to thecase _:arm, raisingValueError.Reproduction:
Fix
Replace the two incorrect match arms:
np.dtypes.Float16DType()→np.dtypes.Float64DType()returning"float64"np.dtypes.Float32DType()→np.dtypes.Complex64DType()returning"complex64"Applied in both
pydantic_zarr.v3andpydantic_zarr.experimental.v3.Additional changes
int8/16/32/64,uint8/16/32/64,float16/32/64,complex64/128) passed asnp.dtype(...)objects throughparse_dtype_v3, in bothtests/test_pydantic_zarr/test_v3.pyandtests/test_pydantic_zarr/test_experimental/test_v3.py.Structdtype class (a subclass ofStructured) by usingissubclassinstead of==, which was causing aTypeErrorduring test collection.python_versionin[tool.mypy]from"3.11"to"3.12"to match zarr ≥3.2.0's minimum Python requirement (zarr 3.2.0+ uses Python 3.12type X = ...syntax).Fixes part of #165.
🤖 Generated with Claude Code