Uh oh!
There was an error while loading. Please reload this page.
Array conversion methods - #9823
Conversation
slevang
commented
Dec 3, 2024
TomNicholas
commented
Feb 12, 2025
I just want to note that conceptually this problem
is effectively a static typing check. Whilst in general an xarray Dataset arguably is a generic with type That's a similar problem to the one that comes up in VirtualiZarr, where users get confused by how there is no top-level " |
shoyer
commented
Feb 12, 2025
We talked about this at the Xarray developers meeting today. One concern is that I'm less sure that we need the capability to check all arrays to see if they match a given array type. We don't have that for dtypes, which suggests it may not be necessary. That said, I do think it would be nice to be able to generically flatten the data from an arbitrary xarray object into a list, to support something like I agree that these are not the most obvious APIs for working with duck array data, in particular because duck array conversion can only very loosely be interpreted as a numpy universal function. We could consider adding new methods for this, but I would start with documenting what we already have, e.g., in the documentation section on working with numpy-like arrays. |
slevang
commented
Feb 12, 2025
Yeah that all makes sense. Should we close in favor of a simple documentation PR? |
shoyer
commented
Mar 6, 2025
Yes, this would be much appreciated! |
whats-new.rstapi.rstThis implements a convenience method to convert data between duck array types, and another to check the current type of your data. Basically identical to cupy-xarray's
as_cupy()/is_cupy()methods, but exposed in a more general way.The signature I have here takes a callable plus any kwargs, so it's quite flexible:
Then:
I'm not sure about the naming. There are also other ways we could go about this, e.g. string matching for supported arrays.
Follow up to #9798.