Skip to content

Commit 732750a

Browse files
authored
Blackdoc (#4177)
* add blackdoc to the pre-commit configuration * use the stable version of blackdoc * run blackdoc on all files * add blackdoc to the linter / formatting tools section * use language names to enable syntax highlighting * update whats-new.rst
1 parent 65ca92a commit 732750a

8 files changed

+71
-32
lines changed

.pre-commit-config.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ repos:
1111
rev: stable
1212
hooks:
1313
- id: black
14+
- repo: https://github.com/keewis/blackdoc
15+
rev: stable
16+
hooks:
17+
- id: blackdoc
1418
- repo: https://gitlab.com/pycqa/flake8
1519
rev: 3.7.9
1620
hooks:

doc/contributing.rst

+15-6
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ We'll now kick off a two-step process:
148148
1. Install the build dependencies
149149
2. Build and install xarray
150150

151-
.. code-block:: none
151+
.. code-block:: sh
152152
153153
# Create and activate the build environment
154154
# This is for Linux and MacOS. On Windows, use py37-windows.yml instead.
@@ -162,7 +162,10 @@ We'll now kick off a two-step process:
162162
# Build and install xarray
163163
pip install -e .
164164
165-
At this point you should be able to import *xarray* from your locally built version::
165+
At this point you should be able to import *xarray* from your locally
166+
built version:
167+
168+
.. code-block:: sh
166169
167170
$ python # start an interpreter
168171
>>> import xarray
@@ -256,7 +259,9 @@ Some other important things to know about the docs:
256259
- The tutorials make heavy use of the `ipython directive
257260
<http://matplotlib.org/sampledoc/ipython_directive.html>`_ sphinx extension.
258261
This directive lets you put code in the documentation which will be run
259-
during the doc build. For example::
262+
during the doc build. For example:
263+
264+
.. code:: rst
260265
261266
.. ipython:: python
262267
@@ -290,7 +295,7 @@ Requirements
290295
Make sure to follow the instructions on :ref:`creating a development environment above <contributing.dev_env>`, but
291296
to build the docs you need to use the environment file ``ci/requirements/doc.yml``.
292297

293-
.. code-block:: none
298+
.. code-block:: sh
294299
295300
# Create and activate the docs environment
296301
conda env create -f ci/requirements/doc.yml
@@ -347,7 +352,10 @@ Code Formatting
347352

348353
xarray uses several tools to ensure a consistent code format throughout the project:
349354

350-
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized code formatting
355+
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized
356+
code formatting
357+
- `blackdoc <https://blackdoc.readthedocs.io/en/stable/>`_ for
358+
standardized code formatting in documentation
351359
- `Flake8 <http://flake8.pycqa.org/en/latest/>`_ for general code quality
352360
- `isort <https://github.com/timothycrosley/isort>`_ for standardized order in imports.
353361
See also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.
@@ -356,12 +364,13 @@ xarray uses several tools to ensure a consistent code format throughout the proj
356364

357365
``pip``::
358366

359-
pip install black flake8 isort mypy
367+
pip install black flake8 isort mypy blackdoc
360368

361369
and then run from the root of the Xarray repository::
362370

363371
isort -rc .
364372
black -t py36 .
373+
blackdoc -t py36 .
365374
flake8
366375
mypy .
367376

doc/dask.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ received by the applied function.
432432
print(da.sizes)
433433
return da.time
434434
435+
435436
mapped = xr.map_blocks(func, ds.temperature)
436437
mapped
437438
@@ -461,9 +462,10 @@ Here is a common example where automated inference will not work.
461462
:okexcept:
462463
463464
def func(da):
464-
print(da.sizes)
465+
print(da.sizes)
465466
return da.isel(time=[1])
466467
468+
467469
mapped = xr.map_blocks(func, ds.temperature)
468470
469471
``func`` cannot be run on 0-shaped inputs because it is not possible to extract element 1 along a
@@ -501,6 +503,7 @@ Notice that the 0-shaped sizes were not printed to screen. Since ``template`` ha
501503
def func(obj, a, b=0):
502504
return obj + a + b
503505
506+
504507
mapped = ds.map_blocks(func, args=[10], kwargs={"b": 10})
505508
expected = ds + 10 + 10
506509
mapped.identical(expected)

doc/internals.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,10 @@ re-open it directly with Zarr:
182182

183183
.. ipython:: python
184184
185-
ds = xr.tutorial.load_dataset('rasm')
186-
ds.to_zarr('rasm.zarr', mode='w')
185+
ds = xr.tutorial.load_dataset("rasm")
186+
ds.to_zarr("rasm.zarr", mode="w")
187187
import zarr
188-
zgroup = zarr.open('rasm.zarr')
188+
189+
zgroup = zarr.open("rasm.zarr")
189190
print(zgroup.tree())
190-
dict(zgroup['Tair'].attrs)
191+
dict(zgroup["Tair"].attrs)

doc/plotting.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ from the time and assign it as a non-dimension coordinate:
220220

221221
.. ipython:: python
222222
223-
decimal_day = (air1d.time - air1d.time[0]) / pd.Timedelta('1d')
223+
decimal_day = (air1d.time - air1d.time[0]) / pd.Timedelta("1d")
224224
air1d_multi = air1d.assign_coords(decimal_day=("time", decimal_day))
225225
air1d_multi
226226
@@ -911,4 +911,4 @@ One can also make line plots with multidimensional coordinates. In this case, ``
911911
f, ax = plt.subplots(2, 1)
912912
da.plot.line(x="lon", hue="y", ax=ax[0])
913913
@savefig plotting_example_2d_hue_xy.png
914-
da.plot.line(x="lon", hue="x", ax=ax[1])
914+
da.plot.line(x="lon", hue="x", ax=ax[1])

doc/whats-new.rst

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ Internal Changes
197197
- Run the ``isort`` pre-commit hook only on python source files
198198
and update the ``flake8`` version. (:issue:`3750`, :pull:`3711`)
199199
By `Justus Magin <https://github.com/keewis>`_.
200+
- Add `blackdoc <https://blackdoc.readthedocs.io>`_ to the list of
201+
checkers for development. (:pull:`4177`)
202+
By `Justus Magin <https://github.com/keewis>`_.
200203
- Add a CI job that runs the tests with every optional dependency
201204
except ``dask``. (:issue:`3794`, :pull:`3919`)
202205
By `Justus Magin <https://github.com/keewis>`_.

xarray/core/computation.py

+34-18
Original file line numberDiff line numberDiff line change
@@ -1096,10 +1096,14 @@ def cov(da_a, da_b, dim=None, ddof=1):
10961096
10971097
Examples
10981098
--------
1099-
>>> da_a = DataArray(np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
1100-
... dims=("space", "time"),
1101-
... coords=[('space', ['IA', 'IL', 'IN']),
1102-
... ('time', pd.date_range("2000-01-01", freq="1D", periods=3))])
1099+
>>> da_a = DataArray(
1100+
... np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
1101+
... dims=("space", "time"),
1102+
... coords=[
1103+
... ("space", ["IA", "IL", "IN"]),
1104+
... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
1105+
... ],
1106+
... )
11031107
>>> da_a
11041108
<xarray.DataArray (space: 3, time: 3)>
11051109
array([[1. , 2. , 3. ],
@@ -1108,10 +1112,14 @@ def cov(da_a, da_b, dim=None, ddof=1):
11081112
Coordinates:
11091113
* space (space) <U2 'IA' 'IL' 'IN'
11101114
* time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03
1111-
>>> da_b = DataArray(np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
1112-
... dims=("space", "time"),
1113-
... coords=[('space', ['IA', 'IL', 'IN']),
1114-
... ('time', pd.date_range("2000-01-01", freq="1D", periods=3))])
1115+
>>> da_b = DataArray(
1116+
... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
1117+
... dims=("space", "time"),
1118+
... coords=[
1119+
... ("space", ["IA", "IL", "IN"]),
1120+
... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
1121+
... ],
1122+
... )
11151123
>>> da_b
11161124
<xarray.DataArray (space: 3, time: 3)>
11171125
array([[ 0.2, 0.4, 0.6],
@@ -1123,7 +1131,7 @@ def cov(da_a, da_b, dim=None, ddof=1):
11231131
>>> xr.cov(da_a, da_b)
11241132
<xarray.DataArray ()>
11251133
array(-3.53055556)
1126-
>>> xr.cov(da_a, da_b, dim='time')
1134+
>>> xr.cov(da_a, da_b, dim="time")
11271135
<xarray.DataArray (space: 3)>
11281136
array([ 0.2, -0.5, 1.69333333])
11291137
Coordinates:
@@ -1165,10 +1173,14 @@ def corr(da_a, da_b, dim=None):
11651173
11661174
Examples
11671175
--------
1168-
>>> da_a = DataArray(np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
1169-
... dims=("space", "time"),
1170-
... coords=[('space', ['IA', 'IL', 'IN']),
1171-
... ('time', pd.date_range("2000-01-01", freq="1D", periods=3))])
1176+
>>> da_a = DataArray(
1177+
... np.array([[1, 2, 3], [0.1, 0.2, 0.3], [3.2, 0.6, 1.8]]),
1178+
... dims=("space", "time"),
1179+
... coords=[
1180+
... ("space", ["IA", "IL", "IN"]),
1181+
... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
1182+
... ],
1183+
... )
11721184
>>> da_a
11731185
<xarray.DataArray (space: 3, time: 3)>
11741186
array([[1. , 2. , 3. ],
@@ -1177,10 +1189,14 @@ def corr(da_a, da_b, dim=None):
11771189
Coordinates:
11781190
* space (space) <U2 'IA' 'IL' 'IN'
11791191
* time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03
1180-
>>> da_b = DataArray(np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
1181-
... dims=("space", "time"),
1182-
... coords=[('space', ['IA', 'IL', 'IN']),
1183-
... ('time', pd.date_range("2000-01-01", freq="1D", periods=3))])
1192+
>>> da_b = DataArray(
1193+
... np.array([[0.2, 0.4, 0.6], [15, 10, 5], [3.2, 0.6, 1.8]]),
1194+
... dims=("space", "time"),
1195+
... coords=[
1196+
... ("space", ["IA", "IL", "IN"]),
1197+
... ("time", pd.date_range("2000-01-01", freq="1D", periods=3)),
1198+
... ],
1199+
... )
11841200
>>> da_b
11851201
<xarray.DataArray (space: 3, time: 3)>
11861202
array([[ 0.2, 0.4, 0.6],
@@ -1192,7 +1208,7 @@ def corr(da_a, da_b, dim=None):
11921208
>>> xr.corr(da_a, da_b)
11931209
<xarray.DataArray ()>
11941210
array(-0.57087777)
1195-
>>> xr.corr(da_a, da_b, dim='time')
1211+
>>> xr.corr(da_a, da_b, dim="time")
11961212
<xarray.DataArray (space: 3)>
11971213
array([ 1., -1., 1.])
11981214
Coordinates:

xarray/core/parallel.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ def map_blocks(
252252
to the function being applied in ``xr.map_blocks()``:
253253
254254
>>> xr.map_blocks(
255-
... calculate_anomaly, array, kwargs={"groupby_type": "time.year"}, template=array,
255+
... calculate_anomaly,
256+
... array,
257+
... kwargs={"groupby_type": "time.year"},
258+
... template=array,
256259
... )
257260
<xarray.DataArray (time: 24)>
258261
array([ 0.15361741, -0.25671244, -0.31600032, 0.008463 , 0.1766172 ,

0 commit comments

Comments
 (0)