[NumPy-Tickets] [NumPy] #1752: np.loadtxt fails on empty files

NumPy Trac numpy-tickets@scipy....
Sat Mar 26 09:48:51 CDT 2011


#1752: np.loadtxt fails on empty files
-------------------------+--------------------------------------------------
 Reporter:  weathergod   |       Owner:  somebody    
     Type:  enhancement  |      Status:  needs_review
 Priority:  normal       |   Milestone:  1.6.0       
Component:  Other        |     Version:  1.5.1       
 Keywords:               |  
-------------------------+--------------------------------------------------
Changes (by dynetrekk):

  * status:  new => needs_review


Comment:

 I agree that the feature request would be nice. I also attach a possible
 patch, which will simply make loadtxt return an empty array.
 {{{
 diff -r 2763b87dd7e8 numpy/lib/npyio.py
 --- a/numpy/lib/npyio.py        Fri Mar 25 22:37:19 2011 -0600
 +++ b/numpy/lib/npyio.py        Sat Mar 26 13:10:36 2011 +0100
 @@ -745,7 +745,10 @@
          while not first_vals:
              first_line = fh.readline()
              if not first_line: # EOF reached
 -                raise IOError('End-of-file reached before encountering
 data.')
 +                # Break out of the loop here, so that we return an empty
 array.
 +                first_line = ''
 +                first_vals = []
 +                break
              first_vals = split_line(first_line)
          N = len(usecols or first_vals)

 }}}

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


More information about the NumPy-Tickets mailing list