-
-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Closed
Milestone
Description
Original ticket http://projects.scipy.org/numpy/ticket/1675 on 2010-11-15 by @pv, assigned to unknown.
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.
Reactions are currently unavailable