What is your issue?
I was trying to use dataset.map to update the attributes of every data variable in my dataset. It looks like there's no way to do this since passing keep_attrs=True retains the previous attributes while passing keep_attrs=False wipes the attributes. Maybe keep_attrs should be one of ["source", "destination", "wipe"] rather than being a boolean.
My motivating usecase involves a dataset with variables with units of kilograms. Each data variable has attr dict {"units": "kg"}. I then run ds.map(lambda x: x / x.sum()) to get a dataset of unitless mass distributions, each of which I'd like to have an attr dict of {"units": "unitless"}.
Unfortunately, running
ds.map(lambda x: (x / x.sum()).assign_attrs(units="unitless"), keep_attrs=keep_attrs)
either results in the original attr dict or an empty attr dict depending on whether keep_attrs is True or False
I think the inability to use .map to update variable attributes is a legitimate missing capability in an otherwise very well-considered API. But... if there's a deep reason that it needs to be this way then I'd also love to know why.
What is your issue?
I was trying to use dataset.map to update the attributes of every data variable in my dataset. It looks like there's no way to do this since passing
keep_attrs=Trueretains the previous attributes while passingkeep_attrs=Falsewipes the attributes. Maybekeep_attrsshould be one of["source", "destination", "wipe"]rather than being a boolean.My motivating usecase involves a dataset with variables with units of kilograms. Each data variable has attr dict
{"units": "kg"}. I then runds.map(lambda x: x / x.sum())to get a dataset of unitless mass distributions, each of which I'd like to have an attr dict of{"units": "unitless"}.Unfortunately, running
either results in the original attr dict or an empty attr dict depending on whether
keep_attrsisTrueorFalseI think the inability to use
.mapto update variable attributes is a legitimate missing capability in an otherwise very well-considered API. But... if there's a deep reason that it needs to be this way then I'd also love to know why.