Skip to content
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

Add option to apply reduction operations also to coordinates instead of dropping them. #8317

Open
JulianGiles opened this issue Oct 16, 2023 · 3 comments

Comments

@JulianGiles
Copy link

Is your feature request related to a problem?

Applying reduction operations like .mean() to a Dataset or DataArray will remove all coordinates that have the reduced dimension.

Describe the solution you'd like

I would like a keyword argument (reduce_coords?) in the reduction method to allow for the reduction to also be applied to the coordinates.

Describe alternatives you've considered

A current solution is to promote the coordinates to variables, perform the reduction and then demote them back to coordinates, like in #1497 . But it would be nice to have a faster way of doing it, like in #3033 with keepdims=True to retain the dimensions after a reduction.

Additional context

No response

@welcome
Copy link

welcome bot commented Oct 16, 2023

Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!

@TomNicholas
Copy link
Member

TomNicholas commented Oct 16, 2023

This seems useful! Would it perhaps make sense to simply change the behaviour of keepdims to not drop coordinates which depend on the reduced dimension? To avoid adding more flags than might be necessary? That would be a breaking change though...

@JulianGiles
Copy link
Author

Yes, that could also work. Although (in my case) I only need the reduced coordinate without the reduced dimension, but it is still much easier to just take out the reduced dimension after the operation than the workaround I mentioned in the post. However, I do not know what is easier to implement.

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

No branches or pull requests

2 participants