[NumPy-Tickets] [NumPy] #1924: Support floating point hex representation in loadtxt

NumPy Trac numpy-tickets@scipy....
Wed Aug 3 12:52:18 CDT 2011

#1924: Support floating point hex representation in loadtxt
 Reporter:  claumann     |       Owner:  somebody   
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  Other        |     Version:  1.6.0      
 Keywords:               |  
 Python supports a hexadecimal representation for floating numbers in
 float.hex() and float.fromhex():

 >>> a = 3.14

 >>> a.hex()

 >>> float.fromhex(a.hex())

 Numpy's loadtxt does not support this hex text format but it seems like it
 would be a useful enhancement. For example, a simple implementation might
 come from changing the default converter returned by _getconv for columns
 of type float:

 def _floatconv(x):
     return float(x)
   except ValueError:
   return float.fromhex(x)

 And then change the return float in _getconv to return _floatconv. This
 converter obeys essentially the same semantics (and exceptions) as float()
 except that it falls back on fromhex before giving up.

 A slightly less permissive change would be to check that the string x
 begins with '0x' before calling fromhex and throwing a ValueError if not.
 The code above would accept 'bad' and convert it to 2989, which might be
 unnecessarily permissive.

 Best, Chris

Ticket URL: <http://projects.scipy.org/numpy/ticket/1924>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list