Skip to content

Commit 9858a27

Browse files
authored
document restrictions to the inline repr (#4912)
* move the suppressed import block to the top * clarify that shape and dtype must not be included in the inline repr * show dask and sparse arrays as examples for inline reprs [skip-ci] * add sparse to the doc environment [skip-ci] * don't convert to sparse twice [skip-ci] * correctly name the variables and manually create the dask array [skip-ci]
1 parent 7c4e2ac commit 9858a27

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

ci/requirements/doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies:
2323
- rasterio>=1.1
2424
- seaborn
2525
- setuptools
26+
- sparse
2627
- sphinx=3.3
2728
- sphinx_rtd_theme>=0.4
2829
- sphinx-autosummary-accessors

doc/internals.rst

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ stack, NumPy and pandas. It is written in pure Python (no C or Cython
1010
extensions), which makes it easy to develop and extend. Instead, we push
1111
compiled code to :ref:`optional dependencies<installing>`.
1212

13+
.. ipython:: python
14+
:suppress:
15+
16+
import dask.array as da
17+
import numpy as np
18+
import pandas as pd
19+
import sparse
20+
import xarray as xr
21+
22+
np.random.seed(123456)
23+
1324
Variable objects
1425
----------------
1526

@@ -74,18 +85,24 @@ argument:
7485
7586
...
7687
77-
78-
Extending xarray
79-
----------------
88+
To avoid duplicated information, this method must omit information about the shape and
89+
:term:`dtype`. For example, the string representation of a ``dask`` array or a
90+
``sparse`` matrix would be:
8091

8192
.. ipython:: python
82-
:suppress:
8393
84-
import numpy as np
85-
import pandas as pd
86-
import xarray as xr
94+
a = da.linspace(0, 1, 20, chunks=2)
95+
a
8796
88-
np.random.seed(123456)
97+
b = np.eye(10)
98+
b[[5, 7, 3, 0], [6, 8, 2, 9]] = 2
99+
b = sparse.COO.from_numpy(b)
100+
b
101+
102+
xr.Dataset({"a": ("x", a), "b": (("y", "z"), b)})
103+
104+
Extending xarray
105+
----------------
89106

90107
xarray is designed as a general purpose library, and hence tries to avoid
91108
including overly domain specific functionality. But inevitably, the need for more

0 commit comments

Comments
 (0)