[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?

Nathaniel Smith njs at pobox.com
Thu Jan 3 15:06:57 EST 2013


On Wed, Jan 2, 2013 at 11:24 AM, Nathaniel Smith <njs at pobox.com> wrote:
> This discussion seems to have petered out without reaching consensus
> one way or another. This seems like an important issue, so I've opened
> a bug:
>   https://github.com/numpy/numpy/issues/2878
> Hopefully this way we'll at least not forget about it; also I tried to
> summarize the main issues there and would welcome comments.

Consensus in that bug report seems to be that for array/scalar operations like:
  np.array([1], 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).

The next question is how to handle the warning period, or if there
should be a warning period, given that we've already silently changed
the semantics of this operation, so raising a warning now is perhaps
like noticing that the horses are gone and putting up a notice warning
that we plan to close the barn door shortly. But then again, people
who have already adjusted their code for 1.6 may appreciate such a
warning.

Or maybe no-one actually writes dumb things like int8-plus-1000 so it
doesn't matter, but anyway I thought the list should have a heads-up
:-)

-n



More information about the NumPy-Discussion mailing list