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

Dataset.reduce pass through non-numeric scalars #9604

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mathause
Copy link
Collaborator

  • Closes #xxxx
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

Trying to reduce a non-numeric scalar results in an error. This PR passes them through unchanged.

import xarray as xr
ds = xr.Dataset(data_vars={"y": ((), "string")})
ds.mean()
TypeError: the resolved dtypes are not compatible with add.reduce. Resolved (dtype('<U6'), dtype('<U6'), dtype('<U12'))

  • I did not find an issue for that
  • Alternatively we could skip them (this is done with non-numeric arrays)
  • Numeric scalars are still reduced

@shoyer
Copy link
Member

shoyer commented Oct 20, 2024

I'm pretty sure this was intentional -- mean of a string is not well defined.

Could we make this opt-in, by adding a new keyword argument -- perhaps something like ds.mean(skip_nonnumeric=True)?

As you note, there's also the question of whether to drop or pass through non-numeric values. I'm not sure which is more intuitive.

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.

2 participants