From 81ee356fdf49d3927e00e5be188c2ed727aa0599 Mon Sep 17 00:00:00 2001 From: Chris Laumann Date: Wed, 3 Aug 2011 22:35:43 -0400 Subject: [PATCH] Added support for float hex format to loadtxt. Add _floatconv to npyio.py as a default floating point converter. This uses float() as a type conversion with a fallback on (ValueError) to float.fromhex(). --- .gitignore | 1 + numpy/lib/npyio.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 26581152fa67..88727bc9c14d 100644 --- a/.gitignore +++ b/.gitignore @@ -72,6 +72,7 @@ doc/cdoc/build ###################### .gdb_history .DS_Store? +.DS_Store ehthumbs.db Icon? Thumbs.db diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 44a91c0c7995..0a33c113a02e 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -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 @@ -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_):