8000 Adding floating hex (ala float.fromhex) support to loadtxt converter. (Issue 1924) by claumann · Pull Request #133 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ doc/cdoc/build
######################
.gdb_history
.DS_Store?
.DS_Store
ehthumbs.db
Icon?
Thumbs.db
Expand Down
8 changes: 7 additions & 1 deletion numpy/lib/npyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ def _savez(file, args, kwds, compress):
zip.close()

# Adapted from matplotlib
def _floatconv(x):
try:
return float(x)
except ValueError:
pass
return float.fromhex(x)

def _getconv(dtype):
typ = dtype.type
Expand All @@ -573,7 +579,7 @@ def _getconv(dtype):
if issubclass(typ, np.integer):
return lambda x: int(float(x))
elif issubclass(typ, np.floating):
return float
return _floatconv
elif issubclass(typ, np.complex):
return complex
elif issubclass(typ, np.bytes_):
Expand Down
0