[NumPy-Tickets] [NumPy] #1071: loadtxt fails if the last column contains empty value

NumPy Trac numpy-tickets@scipy....
Thu Mar 31 12:02:34 CDT 2011


#1071: loadtxt fails if the last column contains empty value
---------------------------------+------------------------------------------
 Reporter:  Electrion            |       Owner:  somebody    
     Type:  defect               |      Status:  needs_review
 Priority:  normal               |   Milestone:  1.6.0       
Component:  numpy.lib            |     Version:  devel       
 Keywords:  loadtxt ascii strip  |  
---------------------------------+------------------------------------------

Comment(by derek):

 There is another instance where the present code raises an error, not
 directly related to missing values/converters.
 Consider this
 {{{
 >>> dt = np.dtype([('x', float), ('label', 'S4')])
 >>> np.loadtxt(StringIO("0\tany\n2\tname"), delimiter='\t', dtype=dt)
 array([(0.0, 'any'), (2.0, 'name')],
       dtype=[('x', '<f8'), ('label', '|S4')])
 }}}
 works, and this as well
 {{{
 >>> np.loadtxt(StringIO("0,any\n2,  "), delimiter=',', dtype=dt)
 array([(0.0, 'any'), (2.0, '')],
       dtype=[('x', '<f8'), ('label', '|S4')])
 }}}
 (almost, though the whitespace is stripped), while
 {{{
 np.loadtxt(StringIO("0\tany\n2\t "), delimiter='\t', dtype=dt)
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)
 /sw/lib/python2.7/site-packages/numpy/lib/npyio.pyc in loadtxt(fname,
 dtype, comments, delimiter, converters, skiprows, usecols, unpack)
     729         except TypeError:
     730             # In the case we have an object dtype

 --> 731             X = np.array(X, dtype=dtype)
     732     else:
     733         X = np.array(X, dtype)

 TypeError: expected a readable buffer object
 }}}
 does not...
 If one wants to also preserve whitespace in string-type records, the patch
 should use {{{.strip(asbytes('\r\n'))}}} rather than {{{.strip(asbytes('
 \r\n'))}}} again, but this causes test_io: test_dtype_with_object(self) to
 fail, which seems to rely on stripping the whitespace.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1071#comment:5>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list