No way to specify compat behaviour for xr.apply_ufunc and ops that use it; binary arithmetic ufuncs don't use arithmetic_compat.
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with xr.apply_ufunc and the multi-argument ufunc paths described in the issue, including _binary_ufunc, xr.dot, xr.where, da.where, and da.fillna. Compare how compat is currently selected with arithmetic operators and identify the affected tests or callers. Done means the chosen explicit or option-based compat behavior is applied consistently without changing unrelated defaults.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem?
We're now able to override the problematic (see https://github.com/pydata/xarray/issues/9481, https://github.com/pydata/xarray/issues/10924) compat='minimal' default for arithmetic using e.g. xr.set_options(arithmetic_compat='override'):
import xarray as xr
a = xr.DataArray(1, coords={'foo': 1})
b = xr.DataArray(1, coords={'foo': 2})
with xr.set_options(arithmetic_compat='override'):
print(a + b)
<xarray.DataArray ()> Size: 8B
array(2)
Coordinates:
foo int64 8B 1
Unfortunately there's no way to set compat for xr.apply_ufunc, or for any of the multi-argument ufuncs based on it which perform compat checks
with xr.set_options(arithmetic_compat='override'):
print(xr.apply_ufunc(lambda x, y: x+y, a, b))
<xarray.DataArray ()> Size: 8B
array(2)
with xr.set_options(arithmetic_compat='override'):
print(xr.where(True, a, b))
<xarray.DataArray ()> Size: 8B
array(1)
with xr.set_options(arithmetic_compat='override'):
print(xr.ufuncs.add(a, b))
<xarray.DataArray ()> Size: 8B
array(1)
This is particularly problematic because the behavior now differs for arithmetic operators (going via _binary_op) and arithmetic ufuncs like xr.ufuncs.add or np.add, which go via apply_ufunc.
Describe the solution you'd like / alternatives you've considered
Any views on these options:
(A) : Add an explicit compat argument to apply_ufunc, defaulting to the current behaviour of 'minimal', and let multi-argument ufuncs pass this argument on. (xr.ufuncs based on _binary_ufunc already pass through extra kwargs, but some like xr.dot, xr.where, da.where, da.fillna would need updating.)
(B): Make it configurable via xr.set_options. It could share the existing arithmetic_compat setting which defaults to minimal, or add a new ufunc_compat setting.
(C): (A)+(B): there's an explicit argument for it but it defaults to e.g. OPTIONS["ufunc_compat"]
In all cases I'd suggest setting the defaults to change in a future version to 'override', along with the other planned compat default changes.
If we used the arithmetic_compat setting for apply_ufunc, it'd be reasonable to ask why not for consistency also use arithmetic_join as the default for apply_ufunc's join. However its default is currently different (exact for apply_ufunc, inner for arithmetic), so maybe using a separate ufunc_compat side-steps this.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.5k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 74
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pydata/xarray
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
`DataTree.map_over_datasets` behavior can be obscure sometimesPossibly taken @mohansree14 claimed this 23 days ago. Openneeds triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pydata/xarray#11813 · 1 comment ·
Maintainers usually reply within 1 day
-
Comparing attrs that contain a dict of NumPy arrays raises ValueError in identical / assert_identicalPossibly taken @SohamXYZDev claimed this 29 days ago. Openbug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
pydata/xarray#11777 · 1 comment ·
Maintainers usually reply within 1 day
-
RangeIndex` with datetime64 bounds cannot be printed (`Unknown format code 'g'`)Possibly taken @d-chambers claimed this 60 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pydata/xarray#11598 · 3 comments ·
Maintainers usually reply within 1 day
-
DataTree constructor error message says dict even though dict is not acceptedPossibly taken @aryansk claimed this 100 days ago. Openbug contrib-good-first-issue topic-DataTree topic-error reporting
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
pydata/xarray#11514 · 2 comments ·
Maintainers usually reply within 1 day
Similar issues
-
tests
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
[Plugin] 群聊记忆 · 人格养成Open
Difficulty 1/5 1-3 hours Newbie friendliness 74/100
-
bug maintainer-managed
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
awslabs/visual-asset-management-system#1759 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100