Skip to content

Conversation

keewis
Copy link
Collaborator

@keewis keewis commented Aug 4, 2025

This makes sure we propagate attrs in coords in Dataset.map if keep_attrs == True. It uses the same semantics as for the data variables, which means that keep_attrs=True will 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_attrs property.

Alternative implementation options:

  • Instead of collecting and merging the coords then copying over coordinate attrs we could also make DataArray._copy_attrs_from iterate over the coordinates.
  • Instead of modifying Dataset.map, we could also make all weighted ops receive a keep_attrs parameter

@keewis keewis closed this Aug 12, 2025
@keewis keewis reopened this Aug 12, 2025
@dcherian
Copy link
Contributor

Instead of modifying Dataset.map, we could also make all weighted ops receive a keep_attrs parameter

I think this is a good improvement for Dataset.map. I don't think weighted should take keep_attrs, we've tried to leave that control to the actual reduction (.weighted.mean) : #4513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing coordinate attributes after weighted mean
2 participants