-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Inconsistent validation with complex number #10430
Comments
Yep, looks like a bug 👍. Can take a look later this week. |
So, I'm not opposed to supporting |
This comment was marked as outdated.
This comment was marked as outdated.
hi @sydney-runkle may I try tackling this issue, thanks! |
So I just actually tried out the sample code and played around with that complex coercion when I was reading pydantic/pydantic-core#1574. It seems that this is a numpy-only behaviour and thus I'm not sure if we should implement this for all complex numbers in pydantic.
For example, Model(x=numpy.complex128(1, 2), y=array([1.])) pydantic won't raise any error either and you'll see the coercion.
It is not valid for a complex number instantiated with the builtin complex type but such fields do accept I don't think we should follow this numpy case because coercions can be done differently:
and there's no point for pydantic to simply follow how it's done in numpy. Users might expect different outcomes. |
Initial Checks
Description
A field expecting a list of float number is valid for a numpy array of complex number, but a field expecting a float number is not valid for a complex number.
I would expect the behavior to be the same, i.e. the complex number is a valid float number.
The output of the example code below is (forget about the
ComplexWarning
):Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: