pydantic-numpy icon indicating copy to clipboard operation
pydantic-numpy copied to clipboard

support shape as parameter

Open eudoxos opened this issue 3 years ago • 6 comments

This comment in the original thread was restricting shape of the array. Please consider adding shape to pydantic-numpy (I don't have the fluency with generics to do it myself).

eudoxos avatar Sep 17 '22 20:09 eudoxos

Yes, shape validation would be very helpful for me as well. Here's the syntax I would like:

shape is 2 by 3: shape=(2, 3) constrain to any number of rows and 2 columns: shape=(None, 2) constrain to any number of rows and 2 or 3 columns shape=((None, 2), (None, 3)) 2 or 3-dimensional: shape=((None, None), (None, None, None))

bendichter avatar Jan 10 '23 13:01 bendichter

@bendichter thanks for your suggestions. Maybe we can work around the missing shape parameter using typing.Annotated. See here https://stackoverflow.com/a/72585748/242594

cheind avatar Jan 10 '23 13:01 cheind

Thanks for the pointer!

bendichter avatar Jan 10 '23 15:01 bendichter

I can implement this in April for native pydantic-numpy support

caniko avatar Feb 28 '23 21:02 caniko

That would be great!

bendichter avatar Feb 28 '23 21:02 bendichter

This is now supported on pydantic-numpy ^3.0: https://github.com/caniko/pydantic-numpy

caniko avatar Jul 26 '23 07:07 caniko