-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: add nb_* conversions to fix issue #9972 #10040
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
Conversation
if (PyString_Type.tp_as_number) | ||
stringtype_as_number = *PyString_Type.tp_as_number; | ||
stringtype_as_number.nb_int = int_from_string; | ||
stringtype_as_number.nb_float = float_from_string; |
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.
Why can't you just use - hmm, I see it doesn't have one :(PyString_Type.nb_float
here?
>>> "".__float__
AttributeError: 'str' object has no attribute '__float__'
>>> "".__int__
AttributeError: 'str' object has no attribute '__int__'
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.
Can you just use PyNumber_Int(PyObject_Str(self))
here instead (swapping str
for unicode
, and int
for float
as needed)`
I don't follow your description of the problem. Do both |
Calling Calling Using |
I'm suggesting we call |
#10042 supersedes this, cleaner and more explicit |
Thanks for doing the diagnosis for me that lead to my patch! |
string- and unicode- ndarrays followed different code paths for
int(a)
vsa.__int__()
andfloat(a)
vs.a.__float()
. Implement anb_int
andnb_float
to rectify this.Unfortunately setting
tp_as_number
before callingPyType_Ready
has the side-effect of filling allNULL
nb_*
slots with functions via themro
inheritance path (pulling them fromPyGenericType_Type
). String types should not have anb_multiply
nor anb_add
since they conflict with thesq_repeat
andsq_concat
functions from PyString_Type.Fixes issue #9972
TODO: document