Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

uxarray type dropped during `xr.Dataset + UxDataArray` and `ufunc(xr.DataArray, UxDataset)`

Đang mở
#1,802 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 5 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
data

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug fix upstream
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:

  1. xr.Dataset * UxDataArray, where * can be any binary operation (e.g. multiplication, addition, subtraction)
  2. ufunc(xr.Dataset, UxDataArray), where ufunc can be any numpy binary ufunc (e.g. np.minimum, np.divmod)
  3. 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:

  1. case (K)
  2. also case (K)
  3. 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
Ngôn ngữ chính
Python
Star
229
Fork
56
Merge trung bình
8 ngày 3 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của UXARRAY/uxarray

Tất cả issue của UXARRAY/uxarray

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.