-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
propagate attrs on coords in Dataset.map
#10602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I think this is a good improvement for |
|
agree! can we merge and then I'll merge into #10726 |
|
If I can count your comments as two approvals, then that should be enough to merge once CI passes |
* check that weighted ops propagate attrs on coords * propagate attrs on coords in `map` if keep_attrs * directly check that `map` propagates attrs on coords * whats-new
After PR pydata#10602, Dataset.map started failing when functions returned non-DataArray values (e.g., scalars), raising AttributeError when trying to access .coords on the returned values. This restores backward compatibility by converting non-DataArray outputs to DataArrays, which was the behavior before the regression. Fixes pydata#10835 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
After PR #10602, Dataset.map started failing when functions returned non-DataArray values (e.g., scalars), raising AttributeError when trying to access .coords on the returned values. This restores backward compatibility by converting non-DataArray outputs to DataArrays, which was the behavior before the regression. Fixes #10835 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
whats-new.rstThis makes sure we propagate attrs in coords in
Dataset.mapifkeep_attrs == True. It uses the same semantics as for the data variables, which means thatkeep_attrs=Truewill overwrite any changes to the attrs by the mapped function.This hides the use of the division operator in some of the weighted operations, which are solely affected by the global
keep_attrsproperty.Alternative implementation options:
DataArray._copy_attrs_fromiterate over the coordinates.Dataset.map, we could also make all weighted ops receive akeep_attrsparameter