calliope-project / calliope

A multi-scale energy systems modelling framework
https://www.callio.pe
Apache License 2.0
299 stars 93 forks source link

AttrDict fails when uniting regular dicts #640

Open irm-codebase opened 3 months ago

irm-codebase commented 3 months ago

What happened?

At the moment, AttrDict will fail to execute union if the merged object is a regular dictionary. This is despite the docstrings suggesting that this should be possible.

The cause is that we directly call other.keys_nested(), which is AttrDict exclusive. The solution is an additional check istype(other, AttrDict), and converting if False.

Which operating systems have you used?

Version

v0.7

Relevant log output

No response

brynpickering commented 3 months ago

We desperately want to move away from AttrDict (see #366) rather than constantly patching it. However, we haven't found an alternative that fits our needs.

irm-codebase commented 3 months ago

@brynpickering I was looking at alternatives, and I found dotmap: https://github.com/drgrib/dotmap/tree/master

The only thing its missing is the "disallow overrides" feature we have, although I feel like we are always turning that off... It has one disadvantage, though: it uses OrderedDict instead of just dict, which is slightly slower.

brynpickering commented 3 months ago

Hmm yeah, the others I found also have only one downside each, so it's three options each with one problem making them unsuitable as drop-in replacements 😄

irm-codebase commented 3 months ago

I'll try to come up with a nice working alternative later, so let's keep this issue open for now.

(subclass of Box with union_no_override or something)