[NumPy-Tickets] [NumPy] #1071: loadtxt fails if the last column contains empty value
NumPy Trac
numpy-tickets@scipy....
Thu Mar 31 17:41:46 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):
Replying to [comment:8 derek]:
> But if we want to preserve this functionality, the better fix I now
realise is
Umm, using {{{line.strip()}}} would remove tab-delimited lines with all
blanks again, producing
{{{
>>> dt = np.dtype([('label', 'S4'), ('comment', 'S4')])
>>> np.loadtxt(StringIO("aa\tbb\n \t \ncc\t"), delimiter='\t', dtype=dt)
array([('aa', 'bb'), ('cc', '')],
dtype=[('label', '|S4'), ('comment', '|S4')])
}}}
as compared to
{{{
>>> np.loadtxt(StringIO("aa,bb\n , \ncc,"), delimiter=',', dtype=dt)
array([('aa', 'bb'), (' ', ' '), ('cc', '')],
dtype=[('label', '|S4'), ('comment', '|S4')])
}}}
so I would really rather propose for the patch
{{{
+ if line.strip(' '):
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1071#comment:9>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list