Merged
Conversation
max-sixty
reviewed
Dec 16, 2025
|
|
||
| if xp == np: | ||
| # numpy currently doesn't have a astype: | ||
| if xp is np or not hasattr(xp, "astype"): |
Collaborator
There was a problem hiding this comment.
Suggested change
| if xp is np or not hasattr(xp, "astype"): | |
| if not hasattr(xp, "astype"): |
wdyt?
Contributor
Author
There was a problem hiding this comment.
No objections, what I originally did until I saw this below:
xarray/xarray/core/duck_array_ops.py
Line 275 in 3c6b050
max-sixty
approved these changes
Dec 16, 2025
Collaborator
max-sixty
left a comment
There was a problem hiding this comment.
(I don't know this code at all, looks very reasonable, if anyone knows it better...)
This reverts commit abd935a.
Contributor
Author
|
Reverted abd935a as it made a lot of tests fail. |
keewis
approved these changes
Dec 22, 2025
Contributor
|
Thanks @hoxbro ! |
dcherian
added a commit
to dcherian/xarray
that referenced
this pull request
Jan 28, 2026
- Add missing bug fixes: pydata#11064, pydata#11026, pydata#11022, pydata#11005, pydata#10980, pydata#10788, pydata#11085 - Add missing documentation entries: pydata#10958, pydata#11094, pydata#11080 - Add missing performance entry: pydata#11105 - Add Internal Changes section with pydata#11108 - Fix rST roles: use :py:func:, :py:meth:, :py:class: consistently - Fix missing commas between :issue: and :pull: references - Fix typo in Dataset.identical entry - Fix wrong PR number for coord ordering (11098 -> 11091) - Add missing :pull: reference for arithmetic_compat (pydata#10943) Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
whats-new.rstapi.rstNoticed the following will fail; I copied the logic from the
asarrayfunction just below, and added a simple test.--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[1], line 11 8 mask = xp.isnan(arr) 10 da = xr.DataArray(arr, dims=("x", "y"), name="example") ---> 11 da.where(mask, 0) File [~/projects/xarray/xarray/core/common.py:1251](http://localhost:8888/home/shh/projects/xarray/xarray/core/common.py#line=1250), in DataWithCoords.where(self, cond, other, drop) 1247 cond = cond.isel(**indexers) 1249 from xarray.computation import ops -> 1251 return ops.where_method(self, cond, other) File [~/projects/xarray/xarray/computation/ops.py:184](http://localhost:8888/home/shh/projects/xarray/xarray/computation/ops.py#line=183), in where_method(self, cond, other) 182 # alignment for three arguments is complicated, so don't support it yet 183 join: Literal["inner", "exact"] = "inner" if other is dtypes.NA else "exact" --> 184 return apply_ufunc( 185 duck_array_ops.where_method, 186 self, 187 cond, 188 other, 189 join=join, 190 dataset_join=join, 191 dask="allowed", 192 keep_attrs=True, 193 ) File [~/projects/xarray/xarray/computation/apply_ufunc.py:1269](http://localhost:8888/home/shh/projects/xarray/xarray/computation/apply_ufunc.py#line=1268), in apply_ufunc(func, input_core_dims, output_core_dims, exclude_dims, vectorize, join, dataset_join, dataset_fill_value, keep_attrs, kwargs, dask, output_dtypes, output_sizes, meta, dask_gufunc_kwargs, on_missing_core_dim, *args) 1267 # feed DataArray apply_variable_ufunc through apply_dataarray_vfunc 1268 elif any(isinstance(a, DataArray) for a in args): -> 1269 return apply_dataarray_vfunc( 1270 variables_vfunc, 1271 *args, 1272 signature=signature, 1273 join=join, 1274 exclude_dims=exclude_dims, 1275 keep_attrs=keep_attrs, 1276 ) 1277 # feed Variables directly through apply_variable_ufunc 1278 elif any(isinstance(a, Variable) for a in args): File [~/projects/xarray/xarray/computation/apply_ufunc.py:312](http://localhost:8888/home/shh/projects/xarray/xarray/computation/apply_ufunc.py#line=311), in apply_dataarray_vfunc(func, signature, join, exclude_dims, keep_attrs, *args) 307 result_coords, result_indexes = build_output_coords_and_indexes( 308 args, signature, exclude_dims, combine_attrs=keep_attrs 309 ) 311 data_vars = [getattr(a, "variable", a) for a in args] --> 312 result_var = func(*data_vars) 314 out: tuple[DataArray, ...] | DataArray 315 if signature.num_outputs > 1: File [~/projects/xarray/xarray/computation/apply_ufunc.py:820](http://localhost:8888/home/shh/projects/xarray/xarray/computation/apply_ufunc.py#line=819), in apply_variable_ufunc(func, signature, exclude_dims, dask, output_dtypes, vectorize, keep_attrs, dask_gufunc_kwargs, *args) 815 elif vectorize: 816 func = _vectorize( 817 func, signature, output_dtypes=output_dtypes, exclude_dims=exclude_dims 818 ) --> 820 result_data = func(*input_data) 822 if signature.num_outputs == 1: 823 result_data = (result_data,) File [~/projects/xarray/xarray/core/duck_array_ops.py:414](http://localhost:8888/home/shh/projects/xarray/xarray/core/duck_array_ops.py#line=413), in where_method(data, cond, other) 412 if other is dtypes.NA: 413 other = dtypes.get_fill_value(data.dtype) --> 414 return where(cond, data, other) File [~/projects/xarray/xarray/core/duck_array_ops.py:404](http://localhost:8888/home/shh/projects/xarray/xarray/core/duck_array_ops.py#line=403), in where(condition, x, y) 402 condition = asarray(condition, dtype=dtype, xp=xp) 403 else: --> 404 condition = astype(condition, dtype=dtype, xp=xp) 406 promoted_x, promoted_y = as_shared_dtype([x, y], xp=xp) 408 return xp.where(condition, promoted_x, promoted_y) File [~/projects/xarray/xarray/core/duck_array_ops.py:258](http://localhost:8888/home/shh/projects/xarray/xarray/core/duck_array_ops.py#line=257), in astype(data, dtype, xp, **kwargs) 256 if xp is np: 257 return data.astype(dtype, **kwargs) --> 258 return xp.astype(data, dtype, **kwargs) File [~/.local/conda/envs/holoviz/lib/python3.13/site-packages/cupy/__init__.py:1087](http://localhost:8888/home/shh/.local/conda/envs/holoviz/lib/python3.13/site-packages/cupy/__init__.py#line=1086), in __getattr__(name) 1084 if name in _deprecated_apis: 1085 return getattr(_numpy, name) -> 1087 raise AttributeError(f"module 'cupy' has no attribute {name!r}") AttributeError: module 'cupy' has no attribute 'astype'