Description
Is your feature request related to a problem? Please describe.
Reading attributes from h5py-files is rather slow. So instead of retrieving it immediately I wanted to create a lazy dict-class that only retrieves the attribute values when necessary. But this is difficult to achieve since xarray keeps forcing the attrs to dicts in a lot of places.
Describe the solution you'd like
- Replace in
xarray/xarray/core/variable.py
Line 865 in dddac11
Line 798 in dddac11
asdict(value)
function that checks if the input is a valid dict-like, if not convert to dict. Things that might be good to check:MutableMapping
hasattr(dict_like, "copy")
isinstance(dict_like, dict) == True
- Remove unneccessary conversions to dict. For example
Line 523 in dddac11
Describe alternatives you've considered
- One could lazify with dicts as well, for example by replacing the value with a function. This however won't look good in reprs, that's why having a convienence class is nice.
dict(LazyDict)
always forces to dict, it does not let it pass through unchanged even ifisinstance(LazyDict, dict) == True
.
Interesting reading:
https://stackoverflow.com/questions/16669367/setup-dictionary-lazily
https://stackoverflow.com/questions/3387691/how-to-perfectly-override-a-dict