Closed bart1 closed 1 year ago
This is expected behavior. The main limitation is that we cannot rely on UDUNITS2 for simplification, because it only simplifies to SI units. Therefore, we have our own method (if you are curious, it's here) that extracts all the symbols in the numerator and denominator and simply cancels out the ones that are the same or at least convertible.
Here, you have ha
in the denominator, and two km
in the denominator. km
cannot be converted to ha
, and therefore no simplification is applied. So, actually, it fails for compositions of units, like km^2
. This is something that we cannot address (reasonably), because solving this for the general case would require either (1) reimplementing our own UDUNITS library with this capability, or (2) testing all possible compositions of units, which is a combinatorial problem that escalates very quickly.
Sounds reasonable. I was a bit surprised it worked for the summation and not the division so that is why I thought I would raise it. In my case changing the input units of a script at once changed the outcome by several orders of magnitude.
Maybe some obvious cases like this one could be caught with an call to ud_are_convertable
with the full denominator and numerator in the simplify function?
But then you multiply by just another unit and it stops working, leading to more confusion. I don't think that adding more complexity is worth it. As you said, if the conversion is explicitly requested, then it works, so no big deal. Automatic simplification is just a convenience feature.
I just encountered the following case, I would have expected it to behave the same as the second case where the units become
[1]
. There is a simple solution to convert the units before fromha
tom^2
but would be nice to work out of the box:Created on 2023-10-25 with reprex v2.0.2