cupy-xarray
cupy-xarray copied to clipboard
Add pint arrays support
This commit fixes the following issue of the wrong behavior of is_cupy
property with pint xarrays:
import xarray as xr
import cupy as cp
import pint_xarray
import cupy_xarray
from pint_xarray import unit_registry as ureg
cp_da = xr.DataArray(
cp.linspace(0, 1, 11),
coords=dict(
x=np.linspace(0, 10, 11),
),
)
pint_da = cp_da.pint.quantify("meter")
print(f"is_cupy response: {pint_da.cupy.is_cupy}")
print(f"pint_da type {type(pint_da.pint.magnitude)}")
Currently, the output is:
is_cupy response: False
pint_da type <class 'cupy.ndarray'>
Thanks!
Can you add a test please? You'll need to have pint
as an optional dependency. SO we'll need to copy some of this code from Xarray: https://github.com/pydata/xarray/blob/6c5840e1198707cdcf7dc459f27ea9510eb76388/xarray/tests/init.py#L83
The test should look like:
@requires_pint
def test_is_cupy_pint():
pass
Thank you for your comments and for the good review of the changes. I re-implemented the tests with the clearer naming and wider coverage of input data.
Also closes this issue #31
Hey @dcherian , Do you have any additional comments for this PR? I think we can merge this PR.
Sorry for the massive delay here. @kadykov
I cleaned up the combinatorial explosion of variables ;) but I don't have a machine to actually run the tests on. Can either you or @negin513 confirm that the tests work please?
Actually I have access now. fixing things...