[NumPy-Tickets] [NumPy] #2093: Casting rule change since 1.6.1

NumPy Trac numpy-tickets@scipy....
Wed Mar 28 17:09:55 CDT 2012


#2093: Casting rule change since 1.6.1
---------------------------+------------------------------------------------
 Reporter:  matthew.brett  |       Owner:  somebody   
     Type:  defect         |      Status:  new        
 Priority:  normal         |   Milestone:  Unscheduled
Component:  Other          |     Version:  devel      
 Keywords:                 |  
---------------------------+------------------------------------------------
 This, in numpy 1.6.1:

 In [2]: (np.zeros((2,), dtype=np.uint8) + np.int16(257)).dtype
 Out[2]: dtype('int16')

 changed to this in current trunk:

 In [2]: (np.zeros((2,), dtype=np.uint8) + np.int16(257)).dtype
 Out[2]: dtype('uint16')

 which is different still in previous versions of numpy (e.g. 1.4.1):

 In [2]: (np.zeros((2,), dtype=np.uint8) + np.int16(257)).dtype
 Out[2]: dtype('uint8')

 (see below for more versions)

 My impression had been that the plan was to avoid changes in the
 casting rules if possible.

 I assume this change was not intentional?

 {{{
 import numpy as np

 Adata = np.zeros((2,), dtype=np.uint8)
 Bdata = np.zeros((2,), dtype=np.int16)
 Bzero = np.int16(0)
 Bbig = np.int16(256)

 print np.__version__
 print 'Array add', (Adata + Bdata).dtype
 print 'Scalar 0 add', (Adata + Bzero).dtype
 print 'Scalar 256 add', (Adata + Bbig).dtype
 }}}

 I get this output:

 1.4.1
 Array add int16
 Scalar 0 add uint8
 Scalar 256 add uint8

 1.5.1
 Array add int16
 Scalar 0 add uint8
 Scalar 256 add uint8

 1.6.1
 Array add int16
 Scalar 0 add uint8
 Scalar 256 add int16

 1.7.0.dev-aae5b0a
 Array add int16
 Scalar 0 add uint8
 Scalar 256 add uint16

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2093>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list