cupy-xarray icon indicating copy to clipboard operation
cupy-xarray copied to clipboard

Add pint arrays support

Open kadykov opened this issue 2 years ago • 6 comments

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'>

kadykov avatar Jan 13 '23 13:01 kadykov

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

dcherian avatar Jan 13 '23 16:01 dcherian

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.

kadykov avatar Apr 05 '23 14:04 kadykov

Also closes this issue #31

kadykov avatar May 12 '23 13:05 kadykov

Hey @dcherian , Do you have any additional comments for this PR? I think we can merge this PR.

negin513 avatar Aug 15 '23 23:08 negin513

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?

dcherian avatar Oct 27 '23 21:10 dcherian

Actually I have access now. fixing things...

dcherian avatar Oct 27 '23 22:10 dcherian