[NumPy-Tickets] [NumPy] #1948: chararray subscription returns empty string instead of empty list

NumPy Trac numpy-tickets@scipy....
Mon Sep 5 23:54:35 CDT 2011


#1948: chararray subscription returns empty string instead of empty list
------------------------------------+---------------------------------------
 Reporter:  jazzer                  |       Owner:  somebody
     Type:  defect                  |      Status:  new     
 Priority:  normal                  |   Milestone:  1.6.2   
Component:  numpy.core              |     Version:  1.5.1   
 Keywords:  chararray empty string  |  
------------------------------------+---------------------------------------
 Current behaviour (1.5.1, 1.6.1):
 {{{
 >>> import numpy
 >>>
 a=numpy.rec.array([("a",1),("bb",2),("cc",3)],dtype=[('s','|S4'),('n','i4')])
 >>> print a.s[a.s>'b']
 ['bb' 'cc']
 >>> print a.s[a.s>'c']
 ['cc']
 >>> print a.s[a.s>'d']

 >>> a.s[a.s>'d']
 ''
 }}}

 The correct behaviour (1.2.1):
 {{{
 >>> print a.s[a.s>'d']
 []
 >>> a.s[a.s>'d']
 chararray([],
       dtype='|S4')
 }}}

 The bug was introduced in the commit:7deb4d5db4282e1e1c86, file
 numpy/core/defchararray.py (I'm not sure to which NumPy release this
 commit corresponds, it's somewhere between 1.2.1 and 1.5.1):
 {{{
      def __getitem__(self, obj):
          val = ndarray.__getitem__(self, obj)
 -        if isinstance(val, (string_, unicode_)):
 +        if issubclass(val.dtype.type, character):
              temp = val.rstrip()
 }}}
 Reverting the change in this line fixes the bug.

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


More information about the NumPy-Tickets mailing list