summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib/npyio.py')
-rw-r--r--numpy/lib/npyio.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 9ae5d0b59..3b6a1c563 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -732,10 +732,15 @@ def _getconv(dtype):
""" Find the correct dtype converter. Adapted from matplotlib """
def floatconv(x):
- x.lower()
- if '0x' in x:
- return float.fromhex(x)
- return float(x)
+ try:
+ return float(x) # The fastest path.
+ except ValueError:
+ if '0x' in x: # Don't accidentally convert "a" ("0xa") to 10.
+ try:
+ return float.fromhex(x)
+ except ValueError:
+ pass
+ raise # Raise the original exception, which makes more sense.
typ = dtype.type
if issubclass(typ, np.bool_):