uxarray type dropped during `xr.Dataset + UxDataArray` and `ufunc(xr.DataArray, UxDataset)`
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
Run the provided MCVE for the three mixed xarray/uxarray cases and inspect xarray method dispatch together with NumPy array_ufunc handling. Determine the xarray hook needed for these operations to preserve UxDataset, then verify that all listed binary operations and ufunc examples return UxDataset.
由索引模型根据 Issue 内容生成。
描述
Version
v2026.09.1
How did you install UXarray?
Source
What happened?
Spinoff of #1685 and #1695 to track a few remaining difficult-to-solve cases, which should now be considered out of scope for those issues. Results from binary operations with one xarray object and one uxarray object, when one is a Dataset and the other is a DataArray, currently do not always return a UxDataset (but they should).
(Workaround for any users encountering this bug: explicitly cast objects to uxarray types before or after performing the operation.)
These cases are:
xr.Dataset * UxDataArray, where * can be any binary operation (e.g. multiplication, addition, subtraction)ufunc(xr.Dataset, UxDataArray), where ufunc can be any numpy binary ufunc (e.g.np.minimum,np.divmod)ufunc(xr.DataArray, UxDataset), where ufunc can be any numpy binary ufunc (e.g.np.minimum,np.divmod)
In the docstring of test_nondestructive_binary_ops_and_binary_ufuncs_output_types() in #1767, these cases map to:
- case (K)
- also case (K)
- case (J)
All of these issues cannot be fixed in uxarray directly. Rather, to get these properly fixed would require editing xarray directly to, at minimum, provide a hook which subclasses can use in these cases.
(1) cannot be fixed in uxarray directly because the operation goes directly to xr.Dataset's methods, and when xr.Dataset sees that the second term is an instance of xr.DataArray it decides to handle everything, without giving the second term a chance to alter the behavior in any way.
(2) and (3) cannot be fixed in uxarray directly because numpy's __array_ufunc__ sees that the first term is not a subclass of the second term (or vice versa), so it starts trying to apply __array_ufunc__ in order of inputs. This leads to applying the xarray object's __array_ufunc__, which similarly decides to handle everything after seeing that the second term is an instance of an xarray object (xr.DataArray in (2); xr.Dataset in (3)), without giving the second term a chance to alter the behavior in any way.
What did you expect to happen?
I expected these cases to all return objects with type UxDataset.
Can you provide a MCVE to repoduce the bug?
import numpy as np
import uxarray as ux
uxds = ux.tutorial.open_dataset('quad-hexagon')
uxda = uxds['t2m']
xrds = uxds.to_xarray()
xrda = uxda.to_xarray()
# case 1
print(type(xrds * uxda)) # expected UxDataset, got xr.Dataset
# case 2
print(type(np.minimum(xrds, uxda))) # expected UxDataset, got xr.Dataset
# case 3
print(type(np.maximum(xrda, uxds))) # expected UxDataset, got xr.Dataset
- 主要语言
- Python
- 星标
- 230
- 派生
- 56
- 平均合并
- 6 天 3 小时
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
UXARRAY/uxarray 的其他 Issue
-
Update installation docs to include new conda recipes可能已有人在做 @Sevans711 于 15 天前认领。 未关闭documentation
难度 1/5 1 小时以内 新手友好度 82/100
UXARRAY/uxarray#1793 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
developer experience
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 2 天内回复
-
zonal_mean() and weighted_mean() should return the same type of object可能已有人在做 @Sevans711 于 24 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
UXARRAY/uxarray#1733 · 已指派 1 人 ·
维护者通常 2 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复
-
Neighborhood filter radii in kilometers可能已有人在做 @cmdupuis3 于 2 天前认领。 未关闭improvement
UXARRAY/uxarray#1824 · 已指派 1 人 ·
维护者通常 2 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
huggingface/sentence-transformers#4186 ·
维护者通常 5 天内回复
-
documentation good first issue
难度 2/5 半天 新手友好度 72/100
sujithputta02/Esapay#13 ·
-
bot-triaged module: correctness (silent) module: mps module: NaNs and Infs triage review
难度 2/5 半天 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
SCIInstitute/SCIRun#2842 ·
维护者通常 3 天内回复