[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?
Thu Jan 3 17:39:37 CST 2013
> Consensus in that bug report seems to be that for array/scalar operations like:
> np.array(, dtype=np.int8) + 1000 # can't be represented as an int8!
> we should raise an error, rather than either silently upcasting the
> result (as in 1.6 and 1.7) or silently downcasting the scalar (as in
> 1.5 and earlier).
I have run into this a few times as a NumPy user, and I just wanted to
comment that (in my opinion), having this case generate an error is
the worst of both worlds. The reason people can't decide between
rollover and promotion is because neither is objectively better. One
avoids memory inflation, and the other avoids losing precision. You
just need to pick one and document it. Kicking the can down the road
to the user, and making him/her explicitly test for this condition, is
not a very good solution.
What does this mean in practical terms for NumPy users? I personally
don't relish the choice of always using numpy.add, or always wrapping
my additions in checks for ValueError.
More information about the NumPy-Discussion