I’ve been using mergewith(+, …)
with Dict
s containing Unitful
values, and it worked great for a while … until it suddenly didn’t. And slight reorganization of the arguments made it work again, so I’m not quite sure what’s going on, exactly.
A simple example:
struct K
s
end
mergewith(+,
Dict(
K("A") => 1,
"B" => 1g
),
Dict(
K("A") => 1,
),
Dict(
K("C") => 1g
))
With this, I get the error
ERROR: promotion of types Quantity{Number, NoDims, Unitful.FreeUnits{(), NoDims,
nothing}} and Int64 failed to change any arguments
I can see how you might get into trouble with two unitless scalars, where one is explicitly annotated as having no type. But with more complicated examples (haven’t as yet got a minimal example for this), I also get stuff like:
DimensionError: MyUnit and 3.9247451750516955 are not dimensionally compatible.
In this example, 3.9247451750516955
actually has the unit MyUnit
(in the first of the Dict
s being merged).
I would have thought this should have worked (given that the individual values can be added together, according to the dimensions). Could it be that the promotion “magic” of mergewith
isn’t quite robust enough? Or am I doing something wrong? (Custom hash
/==
shouldn’t be needed, I guess; and, indeed, it doesn’t seem to make a difference.)