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
No support for __format__ in scalars/arrays (Trac #1675) #2271
Numpy scalars and arrays don't work properly in the format() string formatting context:
>>> '{0:d}'.format(np.int16(1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'd' for object of type 'str'
The reason seems to be that the __format__ method is inherited from object, and it converts the item to string via str first.
The correct fix seems to be to implement a properly formatting-code aware __format__ ourselves. For most types, this can probably be done directly by calling PyInt's or PyFloat's routine. However, for e.g. long doubles we might want to implement the formatting ourselves.
Activity
numpy-gitbot commentedon Oct 19, 2012
@mwiebe wrote on 2011-03-25
Fixed in master, except for the long double formatting. Leaving it out of 1.6 as it's neither a perf nor crash bug.
numpy-gitbot commentedon Oct 19, 2012
Milestone changed to
NumPy 1.7by @charris on 2012-04-26