From db7d88f67a6cb2da00d3241d4e0e1391d09082cb Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:04:25 +1200 Subject: [PATCH 01/12] Install cupy-core and xarray The cupy-core package from conda-forge does not bring in CUDA dependencies and thus can be installed on CPU-only CI services. Xref https://github.com/conda-forge/cupy-feedstock/issues/229 --- ci/doc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/doc.yml b/ci/doc.yml index 45d6b3c..3cf878c 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -2,6 +2,7 @@ name: cupy-xarray-doc channels: - conda-forge dependencies: + - cupy-core - pip - python=3.10 - sphinx @@ -14,5 +15,4 @@ dependencies: - ipywidgets - furo - myst-nb - # - cupy - # - xarray + - xarray From 830cbecbeb068b244f9d139acc5ce6027a2cde18 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:05:58 +1200 Subject: [PATCH 02/12] Add pip install --editable to docs build instructions Also fixed some typos around doc/docs. --- docs/source/contributing.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index 4eafd43..1a5587c 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -138,13 +138,14 @@ 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 + pip install --editable . You can then build the documentation using:: From 63fd7598e7b21ada3bb405a17167dce9b7303092 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:08:26 +1200 Subject: [PATCH 03/12] Re-enable building of API page in docs/conf.py See usage instructions in https://sphinx-autosummary-accessors.readthedocs.io/en/stable/usage.html. Also need to `import cupy_xarray` to fix `exception: no module named xarray.DataArray.cupy` error following https://github.com/xarray-contrib/sphinx-autosummary-accessors/issues/107. --- .gitignore | 1 + docs/conf.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) 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/docs/conf.py b/docs/conf.py index dfbc36e..029191f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,7 +6,7 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -# import cupy_xarray +import cupy_xarray import sphinx_autosummary_accessors project = "cupy-xarray" @@ -25,7 +25,7 @@ "sphinx.ext.intersphinx", "sphinx.ext.extlinks", "numpydoc", - # "sphinx_autosummary_accessors", + "sphinx_autosummary_accessors", "IPython.sphinxext.ipython_directive", "sphinx.ext.napoleon", "myst_nb", @@ -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 From 3ee419a4e843ed7b9617d216241a21b92a7b9c10 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:10:34 +1200 Subject: [PATCH 04/12] Undocument Dataset.cupy.get Fixes `AttributeError: type object 'CupyDatasetAccessor' has no attribute 'get'` --- docs/api.rst | 1 - 1 file changed, 1 deletion(-) 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 From c687298d5d9ba19d936335f4de9d0a23d7d904ea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 22:23:26 +0000 Subject: [PATCH 05/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/conf.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 029191f..a32660d 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 + project = "cupy-xarray" copyright = "2023, cupy-xarray developers" author = "cupy-xarray developers" From 6cc911585ee024faef70aa65280b1fbc7bce0814 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:25:08 +1200 Subject: [PATCH 06/12] Add noqa: F401 to import cupy_xarray line --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a32660d..7b8c799 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -8,7 +8,7 @@ import sphinx_autosummary_accessors -import cupy_xarray +import cupy_xarray # noqa: F401 project = "cupy-xarray" copyright = "2023, cupy-xarray developers" From 4d35c46def15e5d03fcd1425055f59f5e9400b3d Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:31:05 +1200 Subject: [PATCH 07/12] PIp install cupy_xarray on readthedocs --- .readthedocs.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.readthedocs.yml b/.readthedocs.yml index 58e24e2..38e51e4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,5 +9,9 @@ build: # Optionally set the version of Python and requirements required to build your docs conda: environment: ci/doc.yml +python: + install: + - method: pip + path: . formats: [] From 3ac183c49f2dcc680bf891f7335431f9214a6238 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 22:31:19 +0000 Subject: [PATCH 08/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .readthedocs.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 38e51e4..4857f73 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -10,8 +10,8 @@ build: conda: environment: ci/doc.yml python: - install: - - method: pip - path: . + install: + - method: pip + path: . formats: [] From 5087d89ba012c8afafade10c5e1601db721ce06f Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:39:08 +1200 Subject: [PATCH 09/12] Remove numpydoc and use napolean only --- ci/doc.yml | 1 - docs/conf.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/ci/doc.yml b/ci/doc.yml index 3cf878c..5734e3f 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -9,7 +9,6 @@ dependencies: - sphinx-design - sphinx-copybutton - sphinx-autosummary-accessors - - numpydoc - ipython - ipykernel - ipywidgets diff --git a/docs/conf.py b/docs/conf.py index 7b8c799..1ba6a75 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,10 +25,9 @@ "sphinx.ext.doctest", "sphinx.ext.intersphinx", "sphinx.ext.extlinks", - "numpydoc", + "sphinx.ext.napoleon", "sphinx_autosummary_accessors", "IPython.sphinxext.ipython_directive", - "sphinx.ext.napoleon", "myst_nb", # "nbsphinx", "sphinx_copybutton", From ccc192513bb745465b2da95ea483050e1ba1dc91 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:45:00 +1200 Subject: [PATCH 10/12] Put editable install in ci/doc.yml so no need to pip install separately Xref https://docs.readthedocs.io/en/stable/faq.html#i-need-to-install-a-package-in-a-environment-with-pinned-versions --- .readthedocs.yml | 4 ---- ci/doc.yml | 3 +++ docs/source/contributing.rst | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 4857f73..58e24e2 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,9 +9,5 @@ build: # Optionally set the version of Python and requirements required to build your docs conda: environment: ci/doc.yml -python: - install: - - method: pip - path: . formats: [] diff --git a/ci/doc.yml b/ci/doc.yml index 5734e3f..42ce948 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -15,3 +15,6 @@ dependencies: - furo - myst-nb - xarray + - pip: + # relative to this file. Needs to be editable to be accepted. + - --editable .. diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index 1a5587c..d965369 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -145,7 +145,6 @@ You can create an environment for building the documentation using:: conda env create --file ci/doc.yml conda activate cupy-xarray-doc - pip install --editable . You can then build the documentation using:: From 72ac4e80b2433ce4998ca6163c5c945d3b90ae06 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 22:45:23 +0000 Subject: [PATCH 11/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ci/doc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/doc.yml b/ci/doc.yml index 42ce948..983d20f 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -16,5 +16,5 @@ dependencies: - myst-nb - xarray - pip: - # relative to this file. Needs to be editable to be accepted. - - --editable .. + # relative to this file. Needs to be editable to be accepted. + - --editable .. From e19967c2f7301fa3aa779970b434e384be7e4833 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 20 Jun 2024 11:45:51 +1200 Subject: [PATCH 12/12] Add minimal docstrings to accessor methods and attributes Adding some docstrings to the is_cupy, as_cupy and as_numpy methods, so that the API docs page looks like center-aligned. --- cupy_xarray/accessors.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) 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(