-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pint arrays support #26
base: main
Are you sure you want to change the base?
Conversation
This commit fix the issue where `is_cupy` shows wrong status for pint arrays on GPU
Thanks! Can you add a test please? You'll need to have The test should look like: @requires_pint
def test_is_cupy_pint():
pass |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
cupy_xarray/tests/test_accessors.py
Outdated
@@ -1,10 +1,18 @@ | |||
import numpy as np | |||
import pytest | |||
import xarray as xr | |||
from xarray.core.pycompat import dask_array_type | |||
from xarray.core.pycompat import DuckArrayModule | |||
from xarray.tests import requires_pint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's copy this over to tests/__init__.py
from xarray and similarly from DuckArrayModule
cupy_xarray/tests/test_accessors.py
Outdated
|
||
|
||
@requires_pint | ||
def test_data_array_accessor_pint(tutorial_da_air_pint): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks this case:
pint + xr.DataArray --> cupy --> numpy
cupy_xarray/tests/test_accessors.py
Outdated
|
||
|
||
@requires_pint | ||
def test_data_array_accessor_pint_dask(tutorial_da_air_pint_dask): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test checks the following:
pint + Dask.DataArray --> cupy --> numpy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request addresses an issue where the is_cupy
property returns an incorrect value (False) for pint xarrays that are backed by CuPy arrays. The proposed modifications effectively resolve this issue and the changes are clear. Great job. 👍
Recommendations
I have two recommendations regarding the tests:
-
To ensure all the edge cases are adequately resolved and to prevent potential future problems, please ensure that the test cases cover all relevant edge cases and scenarios, as this will help to guarantee the robustness of the implemented fix. I added more comments to go over this.
-
I suggest improving the naming of test functions in the accessors module to better reflect their purpose and the functionality being tested. I also want to recommend adding docstrings to each test function, explaining the specific case or scenario that each test covers. Currently the name of the tests (and tests) are very confusing and this caused me some confusions on which cases are covered.
The followings are the lists of tests of their purpose:
Test Function Name | Description |
---|---|
test_data_set_accessor | xr.dataset --> cupy ---> np |
test_data_array_accessor | xr.DataArray --> cupy --> np |
test_data_array_accessor_dask | dask.DataArray --> cupy --> np |
test_data_array_accessor_pint | pint + xr.DataArray --> cupy --> np |
test_data_array_accessor_pint_dask | pint + Dask.DataArray --> cupy --> np |
For example, the name test_xr_dataset_accessor
might be a better name than test_data_set_accessor
. This way we can have test_dask_dataarray_accessor
, etc.
I also suggest covering the following cases that are not covered:
pint + xr.dataset --> cupy --> np
We have tutorial_ds_air_pint
already defined above that can be used in this test.
Thank you for your comments and for the good review of the changes. |
Also closes this issue #31 |
Hey @dcherian , Do you have any additional comments for this PR? I think we can merge this PR. |
Actually I have access now. fixing things... |
as_dask = as_pint.chunk() | ||
if isinstance(as_dask, xr.DataArray): | ||
assert isinstance(as_dask.data, pint.Quantity) | ||
assert isinstance(as_dask.data.magnitude._meta, np.ndarray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@keewis is this expectation right for DataArray(pint(np.ndarray)).chunk()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
be aware that DataArray.chunk()
simply passes the wrapped duck array to dask.array.from_array
if it was not already a dask collection, which means that it would produce a dask(pint(np.ndarray))
. This is not what we want, so there's DataArray.pint.chunk
to work around this.
This commit fixes the following issue of the wrong behavior of
is_cupy
property with pint xarrays:Currently, the output is: