[Numpy-discussion] Misleading/erroneous TypeError message
Charles R Harris
charlesr.harris at gmail.com
Tue Nov 24 15:39:20 EST 2015
On Tue, Nov 24, 2015 at 12:42 PM, Peter Creasey <
p.e.creasey.00 at googlemail.com> wrote:
> I just upgraded my numpy and started to received a TypeError from one of
> my codes that relied on the old, less strict, casting behaviour. The error
> message, however, left me scratching my head when trying to debug something
> like this:
> >>> a = array(,dtype=uint64)
> >>> a += array(,dtype=int64)
> TypeError: Cannot cast ufunc add output from dtype('float64') to
> dtype('uint64') with casting rule 'same_kind'
> Where does the 'float64' come from?!?!
The combination of uint64 and int64 leads to promotion to float64 as the
best option for the combination of signed and unsigned. To fix things, you
can either use `np.add` with an output argument and `casting='unsafe'` or
just be careful about using unsigned types.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion