-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
ENH: implement __complex__ #7229
Conversation
About time, someone does this. I guess it already works for scalars (or maybe they get forwarded to ndarray)? Could you move this to the identical definitions for |
Needs release note. |
It already works for scalars. I guess I could put it over with I've updated the PR to include a comment in the release notes and to handle object or string dtypes as well as to improved the error message provided when conversion cannot be done. Supporting strings is mostly about completeness. Since it works for the scalar type it may as well work for the array type too. |
Did not look at the code yet. Leaving it where it is sounds fine, since No conversion from string please. Also I don't think it exists for the
|
I'll drop the string conversion then. Mind that your example fails because |
Updated. |
☔ The latest upstream changes (presumably #7296) made this pull request unmergeable. Please resolve the merge conflicts. |
rebased. |
Close and reopen to try to trigger appveyor. |
Hmmm, whats wrong with AppVoyer? I will try the close + reopen again. @ewmoore if you have some time, one thing that is missing are tests the failure cases as well, those would be good. Otherwise LGTM. |
Hmm, didn't help, but I very much doubt this has anything to do with the code, so.... |
} | ||
|
||
if (!PyArray_CanCastArrayTo(self, dtype, NPY_SAME_KIND_CASTING) && | ||
!(PyArray_TYPE(self) == NPY_OBJECT)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, would be nice if you can increase the indent here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
The close, reopen trick doesn't work with appveyor. |
☔ The latest upstream changes (presumably #7373) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased, comments addressed. |
Could you still add a test for the failure cases like more then 1 element in the array, and maybe some weird void type conversion to scalar? |
Tests added. |
I can squash this if you'd prefer. |
Squashing is nice, but I can live with three reasonably described commits. Thanks a lot Eric! |
Fixes gh-2491.
There is still some asymmetry here. Calling
float()
orcomplex()
on anp.string_
scalar will try to convert the string to a float or a complex. But this still doesn't work forsize = 1
arrays.