You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I suspect this might require changes to the standard as well as to xarray - in particular see this list of common numpy functions which are not currently in the array API standard. Of these xarray currently uses (FYI @ralfgommers ):
np.pad is an interesting example in the context of chunked arrays (xref #6807) - dask implements it (parallelized using various approaches, including map_blocks internally), but cubed currently doesn't implement it because it's not part of the array API standard. (cc @tomwhite)
Quick update from the Array API standard, both take and tile have been merged in the standard. take is available as of the 2022.12 revision and tile will be included in the 2023 revision.
Thanks @kgryte! We also just bumped our minimum-supported numpy to 1.22 (#8346), which means we could potentially start using numpy.array_api internally for various operations...
I don't have any knowledge about jax specifically, but packages like cubed have been wrapped successfully by xarray using the existing Array API support. So I'd say that as long as jax fully supports the Array API, you should be able to do this already. If not, could you please open a dedicated issue?
There might be a few operations that are needlessly verbose, though, so someone would have to create a integration package (jax-xarray or xarray-jax, not sure).
Wrapping JAX with Xarray is a great idea in need of a champion / beta-tester. As Justus says it should just work, but most of the Xarray devs concentrate on making the high-level wrappers compliant, rather than exposing all the edge cases the specific libraries.
If you or one of your colleagues wants to just have a go and report back what happens that would be a great start!
so it sounds like Xarray should have compliance with the Array API?
at least as far as dispatching to wrapped arrays goes, yes. The full Array API is not a good fit for xarray's objects and adopting just a subset is not allowed, so we don't implement it for those.
To clarify, xarray aims to be able to wrap any array-API compliant object. This should already work, and is already being used to wrap some array types successfully (e.g. cubed), but it's likely that trying this with JAX will turn up some corner cases.
@keewis I think is referring to the separate idea of xarray objects (e.g. xr.Variable) following the array API, (as wrappable objects rather than wrappers), which we decided against.
So all I'm suggesting that you guys do @allen-adastra is try wrapping a JAX array with xarray and see what happens, and report back any failures. I'm not suggesting you take on the task of making xarray work for any array-API compliant object (as we're already trying to do that for the general case).
Now I think of it: this is not really xarray-specific, but I would have expected there to be a canonical 'generic' array API namespace that dispatches based on array_namespace of the arguments, e.g.
import array_api.generic_ufuncs as xnp
xnp.exp(jax_array) -> jax_array
xnp.exp(numpy_array) -> numpy_array
Does anything like this exist, and if not, should it exist? and could xarray piggy-pack off it without implementing the array API for xarray datatypes directly?
The problem is that Xarray objects shouldn't implement __array_namespace__, because they are not fully array API compliant. We talked about this pretty extensively in data-apis/array-api#698
If anyone wants to take a stab at adding this xarray.ufuncs module it would just have to be defined at the top-level and then examine the wrapped array type .data to decide which namespace to use on it for the particular operation.
I would have a go at this, although it looks like it would be easier for someone with more context about the old ufuncs.py. The old version contains some multi-argument dispatch logic which I'm not sure if you'd want to preserve or not, for example. And it goes via _unary_op and _binary_op, so not clear to me if the dispatch based on underlying array type should live there, or in ufuncs.py. If it lives in _unary_op/_binary_op, could that be disentangled from the dispatch logic in ufuncs.py, etc.
I was wondering what the status is of this issue. I am using a package (pyet meteo_utils.py::326) that calls numpy.clip. With the combination of numpy 2.1.3 and xarray 2025.1.2, I get an error for TypeError: DataWithCoords.clip() got an unexpected keyword argument 'out'.
The best solution would be that xarray would be compatible with numpy.clip. An alternative would be that I make a PR for that 3rd party package to solve it.
Is there any chance that the last functions are going to be compatible with numpy soon?
I was wondering what the status is of this issue. I am using a package (pyet meteo_utils.py::326) that calls numpy.clip. With the combination of numpy 2.1.3 and xarray 2025.1.2, I get an error for TypeError: DataWithCoords.clip() got an unexpected keyword argument 'out'.
This looks like a different NumPy/Xarray compatibility quirk, likely unrelated to the Array API standard. Could you please open another issue to discuss?
I was wondering what the status is of this issue. I am using a package (pyet meteo_utils.py::326) that calls numpy.clip. With the combination of numpy 2.1.3 and xarray 2025.1.2, I get an error for TypeError: DataWithCoords.clip() got an unexpected keyword argument 'out'.
This looks like a different NumPy/Xarray compatibility quirk, likely unrelated to the Array API standard. Could you please open another issue to discuss?
This was all my bad. The issue occurs due to a DeprecationWarning and only occurs in pytest. I was not able to reproduce it without pytest.
This ensures that DeprecationWarnings are treated as errors, and therefore I get the error. I guess this still needs to be fixed at a later stage. But I'm leaving it for now.
Can we please fork the deprecation warning about np.clip to another issue? It has nothing to do with the array API standard, besides the fact that they both involve a function named clip.
Activity
TomNicholas commentedon May 18, 2023
np.padis an interesting example in the context of chunked arrays (xref #6807) - dask implements it (parallelized using various approaches, includingmap_blocksinternally), but cubed currently doesn't implement it because it's not part of the array API standard. (cc @tomwhite)shoyer commentedon Aug 14, 2023
Probably the most important missing feature for Xarray in the Array API standard is support for indexing with integer arrays: data-apis/array-api#669
kgryte commentedon Oct 19, 2023
Quick update from the Array API standard, both
takeandtilehave been merged in the standard.takeis available as of the2022.12revision andtilewill be included in the2023revision.TomNicholas commentedon Oct 19, 2023
Thanks @kgryte! We also just bumped our minimum-supported numpy to 1.22 (#8346), which means we could potentially start using
numpy.array_apiinternally for various operations...allen-adastra commentedon May 19, 2024
Hi! I'm wondering if this is still a concerted effort? Def would love to see tight Xarray <-> Jax integration.
keewis commentedon May 19, 2024
I don't have any knowledge about
jaxspecifically, but packages likecubedhave been wrapped successfully byxarrayusing the existing Array API support. So I'd say that as long asjaxfully supports the Array API, you should be able to do this already. If not, could you please open a dedicated issue?There might be a few operations that are needlessly verbose, though, so someone would have to create a integration package (
jax-xarrayorxarray-jax, not sure).TomNicholas commentedon May 19, 2024
Hey @allen-adastra, great to see you here.
Wrapping JAX with Xarray is a great idea in need of a champion / beta-tester. As Justus says it should just work, but most of the Xarray devs concentrate on making the high-level wrappers compliant, rather than exposing all the edge cases the specific libraries.
If you or one of your colleagues wants to just have a go and report back what happens that would be a great start!
allen-adastra commentedon May 19, 2024
Gotcha, so it sounds like Xarray should have compliance with the Array API?
Probably too much for me to take on, but going to talk around to see if we can drum up sufficient support somehow...
keewis commentedon May 19, 2024
at least as far as dispatching to wrapped arrays goes, yes. The full Array API is not a good fit for
xarray's objects and adopting just a subset is not allowed, so we don't implement it for those.TomNicholas commentedon May 20, 2024
To clarify, xarray aims to be able to wrap any array-API compliant object. This should already work, and is already being used to wrap some array types successfully (e.g. cubed), but it's likely that trying this with JAX will turn up some corner cases.
@keewis I think is referring to the separate idea of xarray objects (e.g.
xr.Variable) following the array API, (as wrappable objects rather than wrappers), which we decided against.So all I'm suggesting that you guys do @allen-adastra is try wrapping a JAX array with xarray and see what happens, and report back any failures. I'm not suggesting you take on the task of making xarray work for any array-API compliant object (as we're already trying to do that for the general case).
13 remaining items
shoyer commentedon Sep 10, 2024
The problem is that Xarray objects shouldn't implement
__array_namespace__, because they are not fully array API compliant. We talked about this pretty extensively in data-apis/array-api#698mjwillson commentedon Sep 16, 2024
I would have a go at this, although it looks like it would be easier for someone with more context about the old ufuncs.py. The old version contains some multi-argument dispatch logic which I'm not sure if you'd want to preserve or not, for example. And it goes via _unary_op and _binary_op, so not clear to me if the dispatch based on underlying array type should live there, or in ufuncs.py. If it lives in _unary_op/_binary_op, could that be disentangled from the dispatch logic in ufuncs.py, etc.
mjwillson commentedon Sep 17, 2024
Alternatively would ufuncs.py now be better implemented just as thin wrappers around apply_ufunc?
shoyer commentedon Sep 17, 2024
Yes, I would lean towards this. If I recall correctly,
xarray.ufuncspre-dated apply_ufunc.Add `__array_namespace__` to `ArrayBox` (#647)
slevang commentedon Nov 13, 2024
I ran into the ufuncs issue trying to do basic ops on objects containing
jaxarrays. Opened #9776 for discussion.lucascolley commentedon Nov 18, 2024
might be good to reopen this for further discussion
slevang commentedon Nov 18, 2024
Opened #9798 as another follow up, curious to get feedback.
deltamarnix commentedon Mar 6, 2025
I was wondering what the status is of this issue. I am using a package (pyet meteo_utils.py::326) that calls
numpy.clip. With the combination of numpy 2.1.3 and xarray 2025.1.2, I get an error forTypeError: DataWithCoords.clip() got an unexpected keyword argument 'out'.The best solution would be that xarray would be compatible with
numpy.clip. An alternative would be that I make a PR for that 3rd party package to solve it.Is there any chance that the last functions are going to be compatible with numpy soon?
shoyer commentedon Mar 6, 2025
This looks like a different NumPy/Xarray compatibility quirk, likely unrelated to the Array API standard. Could you please open another issue to discuss?
deltamarnix commentedon Mar 6, 2025
This was all my bad. The issue occurs due to a
DeprecationWarningand only occurs inpytest. I was not able to reproduce it withoutpytest.This ensures that
DeprecationWarnings are treated as errors, and therefore I get the error. I guess this still needs to be fixed at a later stage. But I'm leaving it for now.Minimal example
lucascolley commentedon Mar 6, 2025
I can reproduce a
DeprecationWarningwith the following, but it is different to the warning quoted above:I see the same warning with latest NumPy.
shoyer commentedon Mar 6, 2025
Can we please fork the deprecation warning about
np.clipto another issue? It has nothing to do with the array API standard, besides the fact that they both involve a function namedclip.