You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: np.int_ and np.intc / np.longlong have the same __name__ but are different #9799
The string representation of numpy.intc is <class 'numpy.int32'>. This would fine if this were true--just a name pointing to the same object. But at least on Windows 7, numpy.intc is not the same object as numpy.int32; it's not even a subclass. This is very confusing for debugging objects of this type, as objects inexplicably fail an isinstance test.
Could one of these two small changes be made:
Either make intc just be another name pointing to the object behind int32
This isn't because the dtypes aren't singletons, as the linked issue describes. The problem is that int32 refers to long, and cint refers to int - but on windows long and int are both 32-bit:
In [14]: np.dtype(np.intc).charOut[14]: 'i'# intIn [15]: np.dtype(np.int32).charOut[15]: 'l'# long
Really, the issue is that we have a leaky abstraction, where internally we work in terms of char, short, int, long, long long, but to the user we show int8int16int32int64. On any platform, two of these are going to have the same name.
Either make intc just be another name pointing to the object behind int32
Because np.intc is defined to mean a C int, this would require np.int32 to refer to int as well. This is fine, but now you break np.int_ (long) in the same way as cint is currently broken, which also prints as np.int32
Or make intc print out <class 'numpy.intc'>
This is tricky, because now np.int32 will print out like that too
This is tricky, because now np.int32 will print out like that too
It seems strange that these objects would be so tightly coupled that the __str__ method couldn't be swapped out, but not so tightly coupled that the object itself can't be swapped out. But I don't know anything about the C code, so I'll just accept that there is something difficult going on.
I did find that numpy.intp is numpy.int64 returns True.
would be so tightly coupled that the str method couldn't be swapped ou
If all you want to do is change the string, here's your task: write a function to replace the one in the pseudocode below.
def get_name(c_name):
return 'int{}'.format(number_of_bits_in(c_name)) # number_of_bits_in is platform dependent
get_name("char")
get_name("short")
get_name("int") # this is intc
get_name("long") # this is int_
get_name("long long")
Can you propose a better way to generate names? One option would be to simply return c_name, but I'd argue that seeing the number of bits in the repr is useful
Maybe this happens to late and this is the problem, but somewhere the name it is supposed to ultimately have on the numpy module is assigned (e.g. setattr(numpy, 'intc', intc_object)). It would be nice is the same code that assigned the attribute name also assigned or reassigned the __repr__ string. Something like: setattr(numpy, 'intc', update_repr(intc_object, 'intc'))
changed the title [-]BUG: np.long and np.intc / np.longlong have the same `repr`[/-][+]BUG: np.int_ and np.intc / np.longlong have the same `repr`[/+]on Dec 2, 2017
changed the title [-]BUG: np.int_ and np.intc / np.longlong have the same `repr`[/-][+]BUG: np.int_ and np.intc / np.longlong have the same __name__ but are different[/+]on Dec 2, 2017
Activity
drhagen commentedon Oct 1, 2017
This is related to #6295 and others linked there.
eric-wieser commentedon Oct 1, 2017
This isn't because the dtypes aren't singletons, as the linked issue describes. The problem is that
int32refers tolong, andcintrefers toint- but on windowslongandintare both 32-bit:Really, the issue is that we have a leaky abstraction, where internally we work in terms of
char,short,int,long,long long, but to the user we showint8int16int32int64. On any platform, two of these are going to have the same name.eric-wieser commentedon Oct 1, 2017
Because
np.intcis defined to mean a Cint, this would requirenp.int32to refer tointas well. This is fine, but now you breaknp.int_(long) in the same way ascintis currently broken, which also prints asnp.int32This is tricky, because now
np.int32will print out like that toodrhagen commentedon Oct 1, 2017
It seems strange that these objects would be so tightly coupled that the
__str__method couldn't be swapped out, but not so tightly coupled that the object itself can't be swapped out. But I don't know anything about the C code, so I'll just accept that there is something difficult going on.I did find that
numpy.intp is numpy.int64returnsTrue.eric-wieser commentedon Oct 1, 2017
If all you want to do is change the string, here's your task: write a function to replace the one in the pseudocode below.
Can you propose a better way to generate names? One option would be to simply
return c_name, but I'd argue that seeing the number of bits in therepris usefuldrhagen commentedon Oct 2, 2017
Maybe this happens to late and this is the problem, but somewhere the name it is supposed to ultimately have on the
numpymodule is assigned (e.g.setattr(numpy, 'intc', intc_object)). It would be nice is the same code that assigned the attribute name also assigned or reassigned the__repr__string. Something like:setattr(numpy, 'intc', update_repr(intc_object, 'intc'))[-]`intc` displays wrong class name[/-][+]BUG: np.long and np.intc / np.longlong have the same `repr`[/+][-]BUG: np.long and np.intc / np.longlong have the same `repr`[/-][+]BUG: np.int_ and np.intc / np.longlong have the same `repr`[/+][-]BUG: np.int_ and np.intc / np.longlong have the same `repr`[/-][+]BUG: np.int_ and np.intc / np.longlong have the same __name__ but are different[/+]eric-wieser commentedon Dec 2, 2017
I've updated your description so that we can point to this as the canonical bug report
2 remaining items
Work around Numpy formatting glitch in doctest