diff options
author | Stefan van der Walt <stefan@sun.ac.za> | 2010-05-02 20:02:14 +0000 |
---|---|---|
committer | Stefan van der Walt <stefan@sun.ac.za> | 2010-05-02 20:02:14 +0000 |
commit | 82d8d97ac30e20f9ae605df228bee43d89ef72a2 (patch) | |
tree | b62864c6ae910980f8f13746a2ff85df917b6e27 /numpy/lib | |
parent | 6dc315f8aa7e67f637bcd2beb0c4105ddfcb4a83 (diff) | |
download | numpy-82d8d97ac30e20f9ae605df228bee43d89ef72a2.tar.gz |
BUG: loadtxt should handle universal newlines.
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/npyio.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index feb336dcc..7a6e0238a 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -584,7 +584,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None, import bz2 fh = bz2.BZ2File(fname) else: - fh = file(fname) + fh = file(fname, 'U') elif hasattr(fname, 'readline'): fh = fname else: diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index a61382792..a50c6f267 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -403,6 +403,16 @@ class TestLoadTxt(TestCase): dtype=ndtype) assert_equal(test, control) + def test_universal_newline(self): + f, name = mkstemp() + os.write(f, asbytes('1 21\r3 42\r')) + os.close(f) + + try: + data = np.loadtxt(name) + assert_array_equal(data, [[1, 21], [3, 42]]) + finally: + os.unlink(name) class Testfromregex(TestCase): |