Skip to content

Commit d9f2a23

Browse files
committed
Merge remote-tracking branch 'upstream/master' into groupby-repr
* upstream/master: Revisit # noqa annotations (pydata#3359) Fix codecov.io upload on Windows (pydata#3360) Add how do I ... section (pydata#3357) Add glossary to documentation (pydata#3352) Documentation improvements (pydata#3328) Remove `complex.nc` from built docs (pydata#3353) Fix DataArray.to_netcdf type annotation (pydata#3325)
2 parents d8422c0 + 21705e6 commit d9f2a23

37 files changed

+1196
-217
lines changed

asv_bench/benchmarks/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def decorator(func):
1616

1717
def requires_dask():
1818
try:
19-
import dask # noqa
19+
import dask # noqa: F401
2020
except ImportError:
2121
raise NotImplementedError
2222

asv_bench/benchmarks/dataarray_missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from . import randn, requires_dask
66

77
try:
8-
import dask # noqa
8+
import dask # noqa: F401
99
except ImportError:
1010
pass
1111

ci/azure/unit-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ steps:
1919
displayName: Run tests
2020

2121
- bash: |
22-
bash <(curl https://codecov.io/bash) -t 688f4d53-31bb-49b5-8370-4ce6f792cf3d
22+
curl https://codecov.io/bash > codecov.sh
23+
bash codecov.sh -t 688f4d53-31bb-49b5-8370-4ce6f792cf3d
2324
displayName: Upload coverage to codecov.io
2425

2526
# TODO: publish coverage results to Azure, once we can merge them across

doc/_static/style.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,12 @@
1616
.wy-nav-top {
1717
background-color: #555;
1818
}
19+
20+
table.colwidths-given {
21+
table-layout: fixed;
22+
width: 100%;
23+
}
24+
table.docutils td {
25+
white-space: unset;
26+
word-wrap: break-word;
27+
}

doc/examples/_code/weather_data_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import pandas as pd
3-
import seaborn as sns # noqa, pandas aware plotting library
3+
import seaborn as sns
44

55
import xarray as xr
66

doc/gallery/plot_cartopy_facetgrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
For more details see `this discussion`_ on github.
1313
1414
.. _this discussion: https://github.com/pydata/xarray/issues/1397#issuecomment-299190567
15-
""" # noqa
15+
"""
1616

1717

1818
import cartopy.crs as ccrs

doc/howdoi.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. currentmodule:: xarray
2+
3+
.. _howdoi:
4+
5+
How do I ...
6+
============
7+
8+
.. list-table::
9+
:header-rows: 1
10+
:widths: 40 60
11+
12+
* - How do I...
13+
- Solution
14+
* - add variables from other datasets to my dataset
15+
- :py:meth:`Dataset.merge`
16+
* - add a new dimension and/or coordinate
17+
- :py:meth:`DataArray.expand_dims`, :py:meth:`Dataset.expand_dims`
18+
* - add a new coordinate variable
19+
- :py:meth:`DataArray.assign_coords`
20+
* - change a data variable to a coordinate variable
21+
- :py:meth:`Dataset.set_coords`
22+
* - change the order of dimensions
23+
- :py:meth:`DataArray.transpose`, :py:meth:`Dataset.transpose`
24+
* - remove a variable from my object
25+
- :py:meth:`Dataset.drop`, :py:meth:`DataArray.drop`
26+
* - remove dimensions of length 1 or 0
27+
- :py:meth:`DataArray.squeeze`, :py:meth:`Dataset.squeeze`
28+
* - remove all variables with a particular dimension
29+
- :py:meth:`Dataset.drop_dims`
30+
* - convert non-dimension coordinates to data variables or remove them
31+
- :py:meth:`DataArray.reset_coords`, :py:meth:`Dataset.reset_coords`
32+
* - rename a variable, dimension or coordinate
33+
- :py:meth:`Dataset.rename`, :py:meth:`DataArray.rename`, :py:meth:`Dataset.rename_vars`, :py:meth:`Dataset.rename_dims`,
34+
* - convert a DataArray to Dataset or vice versa
35+
- :py:meth:`DataArray.to_dataset`, :py:meth:`Dataset.to_array`
36+
* - extract the underlying array (e.g. numpy or Dask arrays)
37+
- :py:attr:`DataArray.data`
38+
* - convert to and extract the underlying numpy array
39+
- :py:attr:`DataArray.values`
40+
* - find out if my xarray object is wrapping a Dask Array
41+
- :py:func:`dask.is_dask_collection`
42+
* - know how much memory my object requires
43+
- :py:attr:`DataArray.nbytes`, :py:attr:`Dataset.nbytes`
44+
* - convert a possibly irregularly sampled timeseries to a regularly sampled timeseries
45+
- :py:meth:`DataArray.resample`, :py:meth:`Dataset.resample` (see :ref:`resampling` for more)
46+
* - apply a function on all data variables in a Dataset
47+
- :py:meth:`Dataset.apply`
48+
* - write xarray objects with complex values to a netCDF file
49+
- :py:func:`Dataset.to_netcdf`, :py:func:`DataArray.to_netcdf` specifying ``engine="h5netcdf", invalid_netcdf=True``
50+
* - make xarray objects look like other xarray objects
51+
- :py:func:`~xarray.ones_like`, :py:func:`~xarray.zeros_like`, :py:func:`~xarray.full_like`, :py:meth:`Dataset.reindex_like`, :py:meth:`Dataset.interpolate_like`, :py:meth:`Dataset.broadcast_like`, :py:meth:`DataArray.reindex_like`, :py:meth:`DataArray.interpolate_like`, :py:meth:`DataArray.broadcast_like`
52+
* - replace NaNs with other values
53+
- :py:meth:`Dataset.fillna`, :py:meth:`Dataset.ffill`, :py:meth:`Dataset.bfill`, :py:meth:`Dataset.interpolate_na`, :py:meth:`DataArray.fillna`, :py:meth:`DataArray.ffill`, :py:meth:`DataArray.bfill`, :py:meth:`DataArray.interpolate_na`
54+
* - extract the year, month, day or similar from a DataArray of time values
55+
- ``obj.dt.month`` for example where ``obj`` is a :py:class:`~xarray.DataArray` containing ``datetime64`` or ``cftime`` values. See :ref:`dt_accessor` for more.
56+
* - round off time values to a specified frequency
57+
- ``obj.dt.ceil``, ``obj.dt.floor``, ``obj.dt.round``. See :ref:`dt_accessor` for more.
58+
* - make a mask that is ``True`` where an object contains any of the values in a array
59+
- :py:meth:`Dataset.isin`, :py:meth:`DataArray.isin`

doc/index.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Documentation
4646

4747
**User Guide**
4848

49+
* :doc:`terminology`
4950
* :doc:`data-structures`
5051
* :doc:`indexing`
5152
* :doc:`interpolation`
@@ -65,6 +66,7 @@ Documentation
6566
:hidden:
6667
:caption: User Guide
6768

69+
terminology
6870
data-structures
6971
indexing
7072
interpolation
@@ -82,6 +84,7 @@ Documentation
8284
**Help & reference**
8385

8486
* :doc:`whats-new`
87+
* :doc:`howdoi`
8588
* :doc:`api`
8689
* :doc:`internals`
8790
* :doc:`roadmap`
@@ -94,6 +97,7 @@ Documentation
9497
:caption: Help & reference
9598

9699
whats-new
100+
howdoi
97101
api
98102
internals
99103
roadmap

doc/io.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ and currently raises a warning unless ``invalid_netcdf=True`` is set:
516516
# Reading it back
517517
xr.open_dataarray("complex.nc", engine="h5netcdf")
518518
519+
.. ipython:: python
520+
:suppress:
521+
522+
import os
523+
os.remove('complex.nc')
519524
520525
.. warning::
521526

doc/terminology.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.. _terminology:
2+
3+
Terminology
4+
===========
5+
6+
*Xarray terminology differs slightly from CF, mathematical conventions, and pandas; and therefore using xarray, understanding the documentation, and parsing error messages is easier once key terminology is defined. This glossary was designed so that more fundamental concepts come first. Thus for new users, this page is best read top-to-bottom. Throughout the glossary,* ``arr`` *will refer to an xarray* :py:class:`DataArray` *in any small examples. For more complete examples, please consult the relevant documentation.*
7+
8+
----
9+
10+
**DataArray:** A multi-dimensional array with labeled or named dimensions. ``DataArray`` objects add metadata such as dimension names, coordinates, and attributes (defined below) to underlying "unlabeled" data structures such as numpy and Dask arrays. If its optional ``name`` property is set, it is a *named DataArray*.
11+
12+
----
13+
14+
**Dataset:** A dict-like collection of ``DataArray`` objects with aligned dimensions. Thus, most operations that can be performed on the dimensions of a single ``DataArray`` can be performed on a dataset. Datasets have data variables (see **Variable** below), dimensions, coordinates, and attributes.
15+
16+
----
17+
18+
**Variable:** A `NetCDF-like variable <https://www.unidata.ucar.edu/software/netcdf/netcdf/Variables.html>`_ consisting of dimensions, data, and attributes which describe a single array. The main functional difference between variables and numpy arrays is that numerical operations on variables implement array broadcasting by dimension name. Each ``DataArray`` has an underlying variable that can be accessed via ``arr.variable``. However, a variable is not fully described outside of either a ``Dataset`` or a ``DataArray``.
19+
20+
.. note::
21+
22+
The :py:class:`Variable` class is low-level interface and can typically be ignored. However, the word "variable" appears often enough in the code and documentation that is useful to understand.
23+
24+
----
25+
26+
**Dimension:** In mathematics, the *dimension* of data is loosely the number of degrees of freedom for it. A *dimension axis* is a set of all points in which all but one of these degrees of freedom is fixed. We can think of each dimension axis as having a name, for example the "x dimension". In xarray, a ``DataArray`` object's *dimensions* are its named dimension axes, and the name of the ``i``-th dimension is ``arr.dims[i]``. If an array is created without dimensions, the default dimension names are ``dim_0``, ``dim_1``, and so forth.
27+
28+
----
29+
30+
**Coordinate:** An array that labels a dimension of another ``DataArray``. Loosely, the coordinate array's values can be thought of as tick labels along a dimension. There are two types of coordinate arrays: *dimension coordinates* and *non-dimension coordinates* (see below). A coordinate named ``x`` can be retrieved from ``arr.coords[x]``. A ``DataArray`` can have more coordinates than dimensions because a single dimension can be assigned multiple coordinate arrays. However, only one coordinate array can be a assigned as a particular dimension's dimension coordinate array. As a consequence, ``len(arr.dims) <= len(arr.coords)`` in general.
31+
32+
----
33+
34+
**Dimension coordinate:** A coordinate array assigned to ``arr`` with both a name and dimension name in ``arr.dims``. Dimension coordinates are used for label-based indexing and alignment, like the index found on a :py:class:`pandas.DataFrame` or :py:class:`pandas.Series`. In fact, dimension coordinates use :py:class:`pandas.Index` objects under the hood for efficient computation. Dimension coordinates are marked by ``*`` when printing a ``DataArray`` or ``Dataset``.
35+
36+
----
37+
38+
**Non-dimension coordinate:** A coordinate array assigned to ``arr`` with a name in ``arr.dims`` but a dimension name *not* in ``arr.dims``. These coordinate arrays are useful for auxiliary labeling. However, non-dimension coordinates are not indexed, and any operation on non-dimension coordinates that leverages indexing will fail. Printing ``arr.coords`` will print all of ``arr``'s coordinate names, with the assigned dimensions in parentheses. For example, ``coord_name (dim_name) 1 2 3 ...``.
39+
40+
----
41+
42+
**Index:** An *index* is a data structure optimized for efficient selecting and slicing of an associated array. Xarray creates indexes for dimension coordinates so that operations along dimensions are fast, while non-dimension coordinates are not indexed. Under the hood, indexes are implemented as :py:class:`pandas.Index` objects. The index associated with dimension name ``x`` can be retrieved by ``arr.indexes[x]``. By construction, ``len(arr.dims) == len(arr.indexes)``

0 commit comments

Comments
 (0)