diff options
author | Derek Homeir <derek@astro.phsik.uni-goettingen.de> | 2011-04-04 08:13:54 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-04-04 08:13:54 -0600 |
commit | ce0019c3c0ce3f5afe6eaf6326cd13093d0644e2 (patch) | |
tree | d84cda3125b3719ec8b73e95bc012199402cf3cd /numpy/lib/npyio.py | |
parent | a528b98550f9e411342659069c5ac8fb7bca7bf3 (diff) | |
download | numpy-ce0019c3c0ce3f5afe6eaf6326cd13093d0644e2.tar.gz |
BUG: ticket #1071, fix loadtxt to handle tab delimited data with missing
values in the last column and add test for same.
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r-- | numpy/lib/npyio.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index a203cc67b..306b9ce07 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -612,8 +612,8 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, A dictionary mapping column number to a function that will convert that column to a float. E.g., if column 0 is a date string: ``converters = {0: datestr2num}``. Converters can also be used to - provide a default value for missing data: - ``converters = {3: lambda s: float(s or 0)}``. Default: None. + provide a default value for missing data (but see also `genfromtxt`): + ``converters = {3: lambda s: float(s.strip() or 0)}``. Default: None. skiprows : int, optional Skip the first `skiprows` lines; default: 0. usecols : sequence, optional @@ -627,6 +627,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, ndmin : int, optional The returned array must have at least `ndmin` dimensions. Legal values: 0 (default), 1 or 2. + .. versionadded:: 1.6.0 Returns ------- @@ -734,7 +735,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, def split_line(line): """Chop off comments, strip, and split at delimiter.""" - line = asbytes(line).split(comments)[0].strip() + line = asbytes(line).split(comments)[0].strip(asbytes('\r\n')) if line: return line.split(delimiter) else: |