-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Pydantic v2 and numpy.typing conflict when using npt.DtypeLike in pydantic.BaseModel with python <=3.11 #25206
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
Comments
Thanks for the report @rbavery. We're already relying on It can't really be considered a numpy bug of course, all we're doing is |
I put up a PR to address the imports, am I missing anything besides changing the imports? |
This is the current numpy/numpy/_typing/_dtype_like.py Lines 96 to 128 in 5825d67
The Wouldn't it be easiest to create a custom alias like that for use in pydantic, that doesn't require the PydanticDTypeLike TypeAlias = np.dtype[Any] | type | str | None which would match the most frequently used (non-void) dtype-likes |
I'm closing this for the reasons explained in #25352 (review). |
Describe the issue:
When I try to use npt.DTypeLike in a pydantic BaseModel, I get an error from pydantic that won't be fixed by pydantic
this issue was first reported here:
pydantic/pydantic#6645
and this is where TypedDict is used from the typing module: https://github.com/numpy/numpy/blob/main/numpy/_typing/_dtype_like.py#L8
Reproduce the code example:
Error message:
Runtime information:
Context for the issue:
I'm trying to define pydantic models for a metadata standard for computer vision models that operate on satellite images. validating numpy types would be very useful so that users of the standard can easily check if their model inputs match the correct numpy type and dimension shape. Supporting this functionality with numpy.typing is desirable across python versions and so I don't need to reinvent the wheel on how to serialize and deserialize numpy types.
The text was updated successfully, but these errors were encountered: