Skip to content

Commit

Permalink
Merge branch 'main' into docs_interoperability
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas authored Oct 26, 2023
2 parents bc0d55d + cef76ec commit ae4619b
Show file tree
Hide file tree
Showing 61 changed files with 3,731 additions and 833 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bugreport.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ body:
- label: Complete example — the example is self-contained, including all data and the text of any traceback.
- label: Verifiable example — the example copy & pastes into an IPython prompt or [Binder notebook](https://mybinder.org/v2/gh/pydata/xarray/main?urlpath=lab/tree/doc/examples/blank_template.ipynb), returning the result.
- label: New issue — a search of GitHub Issues suggests this is not a duplicate.
- label: Recent environment — the issue occurs with the latest version of xarray and its dependencies.

- type: textarea
id: log-output
Expand Down
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ topic-indexing:
- xarray/core/indexes.py
- xarray/core/indexing.py

topic-NamedArray:
- xarray/namedarray/*

topic-performance:
- asv_bench/benchmarks/*
- asv_bench/benchmarks/**/*
Expand Down
122 changes: 120 additions & 2 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ jobs:
name: Mypy
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
# temporarily skipping due to https://github.com/pydata/xarray/issues/6551
if: needs.detect-ci-trigger.outputs.triggered == 'false'
defaults:
run:
shell: bash -l {0}
Expand Down Expand Up @@ -190,6 +188,126 @@ jobs:



pyright:
name: Pyright
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
if: |
always()
&& (
contains( github.event.pull_request.labels.*.name, 'run-pyright')
)
defaults:
run:
shell: bash -l {0}
env:
CONDA_ENV_FILE: ci/requirements/environment.yml
PYTHON_VERSION: "3.10"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags.

- name: set environment variables
run: |
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Setup micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ${{env.CONDA_ENV_FILE}}
environment-name: xarray-tests
create-args: >-
python=${{env.PYTHON_VERSION}}
conda
cache-environment: true
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
- name: Install xarray
run: |
python -m pip install --no-deps -e .
- name: Version info
run: |
conda info -a
conda list
python xarray/util/print_versions.py
- name: Install pyright
run: |
python -m pip install pyright --force-reinstall
- name: Run pyright
run: |
python -m pyright xarray/
- name: Upload pyright coverage to Codecov
uses: codecov/codecov-action@v3.1.4
with:
file: pyright_report/cobertura.xml
flags: pyright
env_vars: PYTHON_VERSION
name: codecov-umbrella
fail_ci_if_error: false

pyright39:
name: Pyright 3.9
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
if: |
always()
&& (
contains( github.event.pull_request.labels.*.name, 'run-pyright')
)
defaults:
run:
shell: bash -l {0}
env:
CONDA_ENV_FILE: ci/requirements/environment.yml
PYTHON_VERSION: "3.9"

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags.

- name: set environment variables
run: |
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Setup micromamba
uses: mamba-org/setup-micromamba@v1
with:
environment-file: ${{env.CONDA_ENV_FILE}}
environment-name: xarray-tests
create-args: >-
python=${{env.PYTHON_VERSION}}
conda
cache-environment: true
cache-environment-key: "${{runner.os}}-${{runner.arch}}-py${{env.PYTHON_VERSION}}-${{env.TODAY}}-${{hashFiles(env.CONDA_ENV_FILE)}}"
- name: Install xarray
run: |
python -m pip install --no-deps -e .
- name: Version info
run: |
conda info -a
conda list
python xarray/util/print_versions.py
- name: Install pyright
run: |
python -m pip install pyright --force-reinstall
- name: Run pyright
run: |
python -m pyright xarray/
- name: Upload pyright coverage to Codecov
uses: codecov/codecov-action@v3.1.4
with:
file: pyright_report/cobertura.xml
flags: pyright39
env_vars: PYTHON_VERSION
name: codecov-umbrella
fail_ci_if_error: false



min-version-policy:
name: Minimum Version Policy
runs-on: "ubuntu-latest"
Expand Down
32 changes: 32 additions & 0 deletions asv_bench/benchmarks/dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np

from xarray import Dataset

from . import requires_dask


class DatasetBinaryOp:
def setup(self):
self.ds = Dataset(
{
"a": (("x", "y"), np.ones((300, 400))),
"b": (("x", "y"), np.ones((300, 400))),
}
)
self.mean = self.ds.mean()
self.std = self.ds.std()

def time_normalize(self):
(self.ds - self.mean) / self.std


class DatasetChunk:
def setup(self):
requires_dask()
self.ds = Dataset()
array = np.ones(1000)
for i in range(250):
self.ds[f"var{i}"] = ("x", array)

def time_chunk(self):
self.ds.chunk(x=(1,) * 1000)
4 changes: 2 additions & 2 deletions asv_bench/benchmarks/dataset_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def load(self) -> tuple:
n_variables = 2000

# Important to have a shape and dtype for lazy loading.
shape = (1,)
shape = (1000,)
dtype = np.dtype(int)
variables = {
f"long_variable_name_{v}": xr.Variable(
Expand Down Expand Up @@ -643,7 +643,7 @@ def open_dataset(

self.engine = PerformanceBackend

@parameterized(["chunks"], ([None, {}]))
@parameterized(["chunks"], ([None, {}, {"time": 10}]))
def time_open_dataset(self, chunks):
"""
Time how fast xr.open_dataset is without the slow data reading part.
Expand Down
1 change: 1 addition & 0 deletions ci/requirements/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
- sphinx-book-theme >= 0.3.0
- sphinx-copybutton
- sphinx-design
- sphinx-inline-tabs
- sphinx>=5.0
- zarr>=2.10
- pip:
Expand Down
32 changes: 31 additions & 1 deletion doc/api-hidden.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
Variable.dims
Variable.dtype
Variable.encoding
Variable.reset_encoding
Variable.drop_encoding
Variable.imag
Variable.nbytes
Variable.ndim
Expand Down Expand Up @@ -351,6 +351,36 @@
IndexVariable.sizes
IndexVariable.values


namedarray.core.NamedArray.all
namedarray.core.NamedArray.any
namedarray.core.NamedArray.attrs
namedarray.core.NamedArray.chunks
namedarray.core.NamedArray.chunksizes
namedarray.core.NamedArray.copy
namedarray.core.NamedArray.count
namedarray.core.NamedArray.cumprod
namedarray.core.NamedArray.cumsum
namedarray.core.NamedArray.data
namedarray.core.NamedArray.dims
namedarray.core.NamedArray.dtype
namedarray.core.NamedArray.get_axis_num
namedarray.core.NamedArray.max
namedarray.core.NamedArray.mean
namedarray.core.NamedArray.median
namedarray.core.NamedArray.min
namedarray.core.NamedArray.nbytes
namedarray.core.NamedArray.ndim
namedarray.core.NamedArray.prod
namedarray.core.NamedArray.reduce
namedarray.core.NamedArray.shape
namedarray.core.NamedArray.size
namedarray.core.NamedArray.sizes
namedarray.core.NamedArray.std
namedarray.core.NamedArray.sum
namedarray.core.NamedArray.var


plot.plot
plot.line
plot.step
Expand Down
4 changes: 2 additions & 2 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ Dataset contents
Dataset.drop_indexes
Dataset.drop_duplicates
Dataset.drop_dims
Dataset.drop_encoding
Dataset.set_coords
Dataset.reset_coords
Dataset.reset_encoding
Dataset.convert_calendar
Dataset.interp_calendar
Dataset.get_index
Expand Down Expand Up @@ -303,8 +303,8 @@ DataArray contents
DataArray.drop_vars
DataArray.drop_indexes
DataArray.drop_duplicates
DataArray.drop_encoding
DataArray.reset_coords
DataArray.reset_encoding
DataArray.copy
DataArray.convert_calendar
DataArray.interp_calendar
Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"sphinx_copybutton",
"sphinxext.rediraffe",
"sphinx_design",
"sphinx_inline_tabs",
]


Expand Down Expand Up @@ -230,6 +231,7 @@
# canonical_url="",
repository_url="https://github.com/pydata/xarray",
repository_branch="main",
navigation_with_keys=False, # pydata/pydata-sphinx-theme#1492
path_to_docs="doc",
use_edit_page_button=True,
use_repository_button=True,
Expand Down
58 changes: 37 additions & 21 deletions doc/internals/how-to-add-new-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ to integrate any code in Xarray; all you need to do is:
- Create a class that inherits from Xarray :py:class:`~xarray.backends.BackendEntrypoint`
and implements the method ``open_dataset`` see :ref:`RST backend_entrypoint`

- Declare this class as an external plugin in your ``setup.py``, see :ref:`RST backend_registration`
- Declare this class as an external plugin in your project configuration, see :ref:`RST
backend_registration`

If you also want to support lazy loading and dask see :ref:`RST lazy_loading`.

Expand Down Expand Up @@ -267,42 +268,57 @@ interface only the boolean keywords related to the supported decoders.
How to register a backend
+++++++++++++++++++++++++

Define a new entrypoint in your ``setup.py`` (or ``setup.cfg``) with:
Define a new entrypoint in your ``pyproject.toml`` (or ``setup.cfg/setup.py`` for older
configurations), with:

- group: ``xarray.backends``
- name: the name to be passed to :py:meth:`~xarray.open_dataset` as ``engine``
- object reference: the reference of the class that you have implemented.

You can declare the entrypoint in ``setup.py`` using the following syntax:
You can declare the entrypoint in your project configuration like so:

.. code-block::
.. tab:: pyproject.toml

setuptools.setup(
entry_points={
"xarray.backends": ["my_engine=my_package.my_module:MyBackendEntryClass"],
},
)
.. code:: toml
[project.entry-points."xarray-backends"]
my_engine = "my_package.my_module:MyBackendEntrypoint"
.. tab:: pyproject.toml [Poetry]

.. code-block:: toml
[tool.poetry.plugins."xarray.backends"]
my_engine = "my_package.my_module:MyBackendEntrypoint"
in ``setup.cfg``:
.. tab:: setup.cfg

.. code-block:: cfg
.. code-block:: cfg
[options.entry_points]
xarray.backends =
my_engine = my_package.my_module:MyBackendEntryClass
[options.entry_points]
xarray.backends =
my_engine = my_package.my_module:MyBackendEntrypoint
.. tab:: setup.py

See https://packaging.python.org/specifications/entry-points/#data-model
for more information
.. code-block::
If you are using `Poetry <https://python-poetry.org/>`_ for your build system, you can accomplish the same thing using "plugins". In this case you would need to add the following to your ``pyproject.toml`` file:
setuptools.setup(
entry_points={
"xarray.backends": [
"my_engine=my_package.my_module:MyBackendEntrypoint"
],
},
)
.. code-block:: toml
[tool.poetry.plugins."xarray.backends"]
"my_engine" = "my_package.my_module:MyBackendEntryClass"
See the `Python Packaging User Guide
<https://packaging.python.org/specifications/entry-points/#data-model>`_ for more
information on entrypoints and details of the syntax.

See https://python-poetry.org/docs/pyproject/#plugins for more information on Poetry plugins.
If you're using Poetry, note that table name in ``pyproject.toml`` is slightly different.
See `the Poetry docs <https://python-poetry.org/docs/pyproject/#plugins>`_ for more
information on plugins.

.. _RST lazy_loading:

Expand Down
6 changes: 3 additions & 3 deletions doc/user-guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ Note that all operations that manipulate variables other than indexing
will remove encoding information.

In some cases it is useful to intentionally reset a dataset's original encoding values.
This can be done with either the :py:meth:`Dataset.reset_encoding` or
:py:meth:`DataArray.reset_encoding` methods.
This can be done with either the :py:meth:`Dataset.drop_encoding` or
:py:meth:`DataArray.drop_encoding` methods.

.. ipython:: python
ds_no_encoding = ds_disk.reset_encoding()
ds_no_encoding = ds_disk.drop_encoding()
ds_no_encoding.encoding
.. _combining multiple files:
Expand Down
Loading

0 comments on commit ae4619b

Please sign in to comment.