8000 ENH: Add support for float hex format to loadtxt. by charris · Pull Request #5504 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add support for float hex format to loadtxt. #5504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
TST: Make loadtxt able to load floats as hex strings.
The strings must be produced by the python float.hex method.
  • Loading branch information
charris committed Feb 13, 2015
commit 31f5d40b6c5a1ea1cafd2a0892bd53f7e6d50061
13 changes: 13 additions & 0 deletions numpy/lib/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,19 @@ def test_int64_type(self):
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')
Expand Down
0