[NumPy-Tickets] [NumPy] #1562: potentially unexpected results with loadtxt()

NumPy Trac numpy-tickets@scipy....
Tue Jul 27 11:24:26 CDT 2010


#1562: potentially unexpected results with loadtxt()
------------------------+---------------------------------------------------
 Reporter:  weathergod  |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  normal      |   Milestone:  1.5.0   
Component:  Other       |     Version:          
 Keywords:              |  
------------------------+---------------------------------------------------
 Consider the case where a user programs a script to load multi-row, multi-
 column data from a text file.  The user will then subsequently program the
 rest of code assuming that he has a 2-d array (or a 1-d record array).
 Then, when the user loads a 1 line text file, loadtxt() will return a 1-D
 array (or a "scalar" for a record array) and would cause unexpected
 results with the rest of the code.

 This is due to loadtxt() calling squeeze() on the data before returning
 it.  While this action is nice as it "magically" anticipates the users'
 intentions, it has some edge cases.

 Note, this would happen with a person working with multi-line, single-
 column data, or even single-line, multi-column data and encounters a file
 with a single value in it.

 My suggestion would be to have a keyword argument 'ndmin' (that would
 default to 0 for backwards compatibility) that would allow the users to
 specify what they always expect from loadtxt().  By having this keyword
 and documenting it well, it should raise awareness among programmers of
 these sort of edge cases.

 How exactly to use the ndmin keyword is an interesting question.  Could,
 perhaps, it get passed to numpy.squeeze, indicating to leave so many
 dimensions alone?

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


More information about the NumPy-Tickets mailing list