NCAS-CMS / cfunits

A Python interface to UNIDATA’s UDUNITS-2 library with CF extensions:
http://ncas-cms.github.io/cfunits
MIT License
11 stars 8 forks source link

Exception is raised for units of type float #1

Closed davidhassell closed 4 years ago

davidhassell commented 4 years ago
>>> u = cfunits.Units(1.0)                                                 
Traceback (most recent call last)
    ...

ValueError: Can't set unsupported unit: 1.0

This should instead store the bad units and set the isvalid attribute to False

See https://github.com/NCAS-CMS/cf-python/issues/23

davidhassell commented 4 years ago

Fixed in v3.2.3, now released in PyPi.

In [7]: import cfunits 

In [8]: u = cfunits.Units(1.0)

In [9]: u.isvalid
Out[9]: False

In [10]: u.reason_notvalid  
Out[10]: "Bad units type: <class 'float'>"

In [11]: u.units
Out[11]: 1.0