NCAS-CMS / cfunits

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

Occasional "Units are not convertible" errors #52

Open JimBiardClimateAI opened 1 year ago

JimBiardClimateAI commented 1 year ago

I am calling Units.conform in a function called through xarray. The processing is running in multi-threaded mode, so the cfunits code is being accessed by multiple threads (potentially) simultaneously. The problem I am seeing shows up when I attempt to do a NULL conversion. That is, the code

    in_units_obj = Units("degrees_C")
    out_units_obj = Units("degrees_C")

    out_a, out_b = Units.conform((in_a, in_b), in_units_obj, out_units_obj)

sometimes (but not always) raises the exception

ValueError: Units are not convertible: <Units: degrees_C>, <Units: degrees_C>
sadielbartholomew commented 1 year ago

Thanks for reporting this, Jim. That looks like a bug, albeit one that our test suite wouldn't pick up on if it is to do with running on multiple threads. Hence it is particularly useful that you reported it.

We'll investigate shortly and report back here on what we find. Thanks.