diff --git a/.gitignore b/.gitignore index 2dc658c..7ed2144 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ instance/ # Sphinx documentation docs/_build/ +docs/generated/ # PyBuilder .pybuilder/ diff --git a/ci/doc.yml b/ci/doc.yml index 45d6b3c..983d20f 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -2,17 +2,19 @@ name: cupy-xarray-doc channels: - conda-forge dependencies: + - cupy-core - pip - python=3.10 - sphinx - sphinx-design - sphinx-copybutton - sphinx-autosummary-accessors - - numpydoc - ipython - ipykernel - ipywidgets - furo - myst-nb - # - cupy - # - xarray + - xarray + - pip: + # relative to this file. Needs to be editable to be accepted. + - --editable .. diff --git a/cupy_xarray/accessors.py b/cupy_xarray/accessors.py index 39ae358..eacc35b 100644 --- a/cupy_xarray/accessors.py +++ b/cupy_xarray/accessors.py @@ -23,7 +23,14 @@ def __init__(self, da): @property def is_cupy(self): - """bool: The underlying data is a cupy array.""" + """ + Check to see if the underlying array is a cupy array. + + Returns + ------- + is_cupy: bool + Whether the underlying data is a cupy array. + """ if isinstance(self.da.data, dask_array_type): return isinstance(self.da.data._meta, cp.ndarray) return isinstance(self.da.data, cp.ndarray) @@ -75,7 +82,6 @@ def as_numpy(self): ------- da: DataArray DataArray with underlying data cast to numpy. - """ if self.is_cupy: if isinstance(self.da.data, dask_array_type): @@ -113,13 +119,27 @@ def __init__(self, ds): @property def is_cupy(self): + """ + Check to see if the underlying array is a cupy array. + + Returns + ------- + is_cupy: bool + Whether the underlying data is a cupy array. + """ return all([da.cupy.is_cupy for da in self.ds.data_vars.values()]) def as_cupy(self): + """ + Convert the Dataset's underlying array type to cupy. + """ data_vars = {var: da.as_cupy() for var, da in self.ds.data_vars.items()} return Dataset(data_vars=data_vars, coords=self.ds.coords, attrs=self.ds.attrs) def as_numpy(self): + """ + Converts the Dataset's underlying array type from cupy to numpy. + """ if self.is_cupy: data_vars = {var: da.cupy.as_numpy() for var, da in self.ds.data_vars.items()} return Dataset( diff --git a/docs/api.rst b/docs/api.rst index 7e0d361..c1ad4c3 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -51,4 +51,3 @@ Methods Dataset.cupy.as_cupy Dataset.cupy.as_numpy - Dataset.cupy.get diff --git a/docs/conf.py b/docs/conf.py index dfbc36e..1ba6a75 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,9 +6,10 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -# import cupy_xarray import sphinx_autosummary_accessors +import cupy_xarray # noqa: F401 + project = "cupy-xarray" copyright = "2023, cupy-xarray developers" author = "cupy-xarray developers" @@ -24,10 +25,9 @@ "sphinx.ext.doctest", "sphinx.ext.intersphinx", "sphinx.ext.extlinks", - "numpydoc", - # "sphinx_autosummary_accessors", - "IPython.sphinxext.ipython_directive", "sphinx.ext.napoleon", + "sphinx_autosummary_accessors", + "IPython.sphinxext.ipython_directive", "myst_nb", # "nbsphinx", "sphinx_copybutton", @@ -41,7 +41,7 @@ } templates_path = ["_templates", sphinx_autosummary_accessors.templates_path] -exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "api.rst"] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index 4eafd43..d965369 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -138,13 +138,13 @@ Contributing documentation ========================== We greatly appreciate documentation improvements. The docs are built from the docstrings -in the code and the docs in the ``doc`` directory. +in the code and the docs in the ``docs`` directory. To build the documentation, you will need to requirements listed in ``ci/doc.yml``. You can create an environment for building the documentation using:: conda env create --file ci/doc.yml - conda activate cupy-xarray-docs + conda activate cupy-xarray-doc You can then build the documentation using::