-
Notifications
You must be signed in to change notification settings - Fork 18
Add pint arrays support #26
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
base: main
Are you sure you want to change the base?
Changes from 17 commits
8ba696a
99ccd71
485d9c1
45aac6c
528b258
a864e6a
1c4b1a7
fa059bf
afd258e
c7580b3
9ad2357
ca9b51c
efac145
12e476a
44bd5ad
4ac8ac6
50637bb
0d841d1
5f10799
fa21b8a
34136e3
5eeaa4c
04a830d
4be620c
41c0d8d
c076239
53e5a86
cff0456
0c36ef0
d9ca81b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Let's copy this over to |
||
|
||
dask_array_type = DuckArrayModule("dask").type | ||
pint_array_type = DuckArrayModule("pint").type | ||
|
||
from pint import UnitRegistry | ||
|
||
import cupy_xarray # noqa: F401 | ||
|
||
ureg = UnitRegistry() | ||
|
||
|
||
@pytest.fixture | ||
def tutorial_ds_air(): | ||
|
@@ -26,6 +34,28 @@ def tutorial_da_air_dask(tutorial_ds_air_dask): | |
return tutorial_ds_air_dask.air | ||
|
||
|
||
@pytest.fixture | ||
def tutorial_ds_air_pint(): | ||
return xr.tutorial.load_dataset("air_temperature") * ureg.Quantity("degree_Kelvin") | ||
|
||
|
||
@pytest.fixture | ||
def tutorial_da_air_pint(tutorial_ds_air_pint): | ||
return tutorial_ds_air_pint.air | ||
|
||
|
||
@pytest.fixture | ||
def tutorial_ds_air_pint_dask(): | ||
return xr.tutorial.open_dataset( | ||
"air_temperature", chunks={"lat": 25, "lon": 25, "time": -1} | ||
) * ureg.Quantity("degree_Kelvin") | ||
|
||
|
||
@pytest.fixture | ||
def tutorial_da_air_pint_dask(tutorial_ds_air_pint_dask): | ||
return tutorial_ds_air_pint_dask.air | ||
|
||
|
||
def test_data_set_accessor(tutorial_ds_air): | ||
ds = tutorial_ds_air | ||
assert hasattr(ds, "cupy") | ||
|
@@ -64,3 +94,35 @@ def test_data_array_accessor_dask(tutorial_da_air_dask): | |
|
||
da = da.cupy.as_numpy() | ||
assert not da.cupy.is_cupy | ||
|
||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. This test checks this case:
|
||
da = tutorial_da_air_pint | ||
assert hasattr(da, "cupy") | ||
assert not da.cupy.is_cupy | ||
|
||
da = da.as_cupy() | ||
assert da.cupy.is_cupy | ||
assert isinstance(da.data, pint_array_type) | ||
|
||
da = da.cupy.as_numpy() | ||
assert not da.cupy.is_cupy | ||
assert isinstance(da.data, pint_array_type) | ||
|
||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. This test checks the following:
|
||
da = tutorial_da_air_pint_dask | ||
assert hasattr(da, "cupy") | ||
assert not da.cupy.is_cupy | ||
|
||
da = da.as_cupy() | ||
assert da.cupy.is_cupy | ||
assert isinstance(da.data, pint_array_type) | ||
assert isinstance(da.data.magnitude, dask_array_type) | ||
|
||
da = da.cupy.as_numpy() | ||
assert not da.cupy.is_cupy | ||
assert isinstance(da.data, pint_array_type) | ||
assert isinstance(da.data.magnitude, dask_array_type) |
Uh oh!
There was an error while loading. Please reload this page.