[Numpy-tickets] [NumPy] #483: Junk in the representation of string fields of recarrays

NumPy numpy-tickets@scipy....
Sun Apr 1 12:30:04 CDT 2007


#483: Junk in the representation of string fields of recarrays
--------------------+-------------------------------------------------------
 Reporter:  faltet  |        Owner:  somebody
     Type:  defect  |       Status:  new     
 Priority:  normal  |    Milestone:          
Component:  Other   |      Version:          
 Severity:  normal  |   Resolution:          
 Keywords:          |  
--------------------+-------------------------------------------------------
Comment (by faltet):

 I've found a patch for this:

 {{{
 Index: numpy/core/src/arraytypes.inc.src
 ===================================================================
 --- numpy/core/src/arraytypes.inc.src   (revision 3632)
 +++ numpy/core/src/arraytypes.inc.src   (working copy)
 @@ -638,6 +638,9 @@
                  res = PyObject_AsReadBuffer(op, &buffer, &buflen);
                  if (res == -1) goto fail;
                  memcpy(ip, buffer, MIN(buflen, itemsize));
 +                if (itemsize > buflen) {
 +                        memset(ip + buflen, 0, (itemsize - buflen));
 +                }
          }
          return 0;

 }}}

 With this:

 {{{
 >>> r=numpy.array([('abc',)], dtype=[('var1', '|S20')])
 >>> r['var1'][0]
 'abc'
 }}}

 i.e. it returns the string without the trailing junk.

 I've checked that all the tests passes ok with this patch applied.

-- 
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/483#comment:1>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.


More information about the Numpy-tickets mailing list