diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2015-02-12 12:51:37 -0700 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2015-02-13 10:47:34 -0700 |
| commit | 31f5d40b6c5a1ea1cafd2a0892bd53f7e6d50061 (patch) | |
| tree | 67ed0ea489bafe8afb64e31e231de3cae2929986 /numpy/lib/tests/test_io.py | |
| parent | 4aef6a89fda5015129e124099f3809fa4da894a7 (diff) | |
| download | numpy-31f5d40b6c5a1ea1cafd2a0892bd53f7e6d50061.tar.gz | |
TST: Make loadtxt able to load floats as hex strings.
The strings must be produced by the python float.hex method.
Diffstat (limited to 'numpy/lib/tests/test_io.py')
| -rw-r--r-- | numpy/lib/tests/test_io.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 05db34d0f..7054ab1fe 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -694,6 +694,19 @@ class TestLoadTxt(TestCase): res = np.loadtxt(c, dtype=np.int64) assert_equal(res, tgt) + def test_from_float_hex(self): + # IEEE doubles and floats only, otherwise the float32 + # conversion may fail. + tgt = np.logspace(-10, 10, 5).astype(np.float32) + tgt = np.hstack((tgt, -tgt)).astype(np.float) + inp = '\n'.join(map(float.hex, tgt)) + c = TextIO() + c.write(inp) + for dt in [np.float, np.float32]: + c.seek(0) + res = np.loadtxt(c, dtype=dt) + assert_equal(res, tgt, err_msg="%s" % dt) + def test_universal_newline(self): f, name = mkstemp() os.write(f, b'1 21\r3 42\r') |
