Skip to content

Commit 791c62d

Browse files
weiji14dcherian
andauthored
Fix broken doctest and tests on accessors (#46)
* Fix doctest on cupy_xarray.accessors.CupyDataArrayAccessor.as_cupy Output type is now just `cupy.ndarray` instead of `cupy.core.core.ndarray`. Also updated pytest command in contributing.rst to include `--doctest-modules` flag. * Fix ModuleNotFoundError: No module named 'xarray.core.pycompat' Xref https://github.com/pydata/xarray/blob/v2024.06.0/xarray/namedarray/pycompat.py#L21-L43 * Use try-except instead of xr.namedarray.pycompat to get dask_array_type --------- Co-authored-by: Deepak Cherian <[email protected]>
1 parent 7fc3df5 commit 791c62d

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

cupy_xarray/accessors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
register_dataarray_accessor,
66
register_dataset_accessor,
77
)
8-
from xarray.namedarray.pycompat import DuckArrayModule
98

10-
dsk = DuckArrayModule("dask")
11-
dask_array_type = dsk.type
9+
try:
10+
import dask.array
11+
12+
dask_array_type = dask.array.Array
13+
except ImportError:
14+
dask_array_type = None
1215

1316

1417
@register_dataarray_accessor("cupy")
@@ -55,7 +58,7 @@ def as_cupy(self):
5558
>>> da = xr.tutorial.load_dataset("air_temperature").air
5659
>>> gda = da.cupy.as_cupy()
5760
>>> type(gda.data)
58-
<class 'cupy.core.core.ndarray'>
61+
<class 'cupy.ndarray'>
5962
6063
"""
6164
if isinstance(self.da.data, dask_array_type):

cupy_xarray/tests/test_accessors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import numpy as np
22
import pytest
33
import xarray as xr
4-
from xarray.core.pycompat import dask_array_type
54

65
import cupy_xarray # noqa: F401
76

7+
try:
8+
import dask.array
9+
10+
dask_array_type = dask.array.Array
11+
except ImportError:
12+
dask_array_type = None
13+
814

915
@pytest.fixture
1016
def tutorial_ds_air():

docs/source/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Running the test suite
132132
*cupy-xarray* uses the `pytest <https://docs.pytest.org/en/latest/contents.html>`_
133133
framework for testing. You can run the test suite using::
134134

135-
pytest cupy-xarray
135+
pytest --doctest-modules cupy_xarray
136136

137137
Contributing documentation
138138
==========================

0 commit comments

Comments
 (0)