Skip to content

Commit 6bc9adb

Browse files
DOCS: Enable numpydoc validation pre-commit hook (#5762)
* add numpdoc_validate to pre-commit * wip * wip * wip * fixed doctest errors. * fox doctests. * Update docs/src/further_topics/filtering_warnings.rst Co-authored-by: Martin Yeo <[email protected]> * numpydoc_validation to adhere to RT02 rule. * sorted temp rules to ignore. * numpydoc_validation to adhere to GL09 rule. * numpydoc_validation to adhere to SA04 rule. * fixed indent. * fixed case and indentation. * fix doctests. * fix doctests (last time) * add "See Also" colons --------- Co-authored-by: Martin Yeo <[email protected]>
1 parent f4e2fb7 commit 6bc9adb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+690
-608
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,10 @@ repos:
6161
hooks:
6262
- id: sort-all
6363
types: [file, python]
64+
65+
- repo: https://github.com/numpy/numpydoc
66+
rev: v1.6.0
67+
hooks:
68+
- id: numpydoc-validation
69+
exclude: "^lib/iris/tests/|docs/gallery_code/"
70+
types: [file, python]

benchmarks/asv_delegated_conda.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,15 @@ def __init__(
4747
4848
Parameters
4949
----------
50-
conf : Config instance
51-
50+
conf : Config
51+
Config instance.
5252
python : str
5353
Version of Python. Must be of the form "MAJOR.MINOR".
54-
5554
requirements : dict
5655
Dictionary mapping a PyPI package name to a version
5756
identifier string.
58-
5957
tagged_env_vars : dict
60-
Environment variables, tagged for build vs. non-build
58+
Environment variables, tagged for build vs. non-build.
6159
6260
"""
6361
ignored = ["`python`"]

benchmarks/benchmarks/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111

1212
def disable_repeat_between_setup(benchmark_object):
13-
"""Benchmarks where object persistence would be inappropriate (decorator).
13+
"""Benchmark where object persistence would be inappropriate (decorator).
1414
1515
E.g:
16-
* Benchmarking data realisation
17-
* Benchmarking Cube coord addition
16+
17+
* Benchmarking data realisation
18+
* Benchmarking Cube coord addition
1819
1920
Can be applied to benchmark classes/methods/functions.
2021
@@ -107,14 +108,15 @@ def _wrapper(*args, **kwargs):
107108

108109

109110
def on_demand_benchmark(benchmark_object):
110-
"""Disables these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
111+
"""Disable these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
111112
112113
This is a decorator.
113114
114115
For benchmarks that, for whatever reason, should not be run by default.
115116
E.g:
116-
* Require a local file
117-
* Used for scalability analysis instead of commit monitoring.
117+
118+
* Require a local file
119+
* Used for scalability analysis instead of commit monitoring.
118120
119121
Can be applied to benchmark classes/methods/functions.
120122

benchmarks/benchmarks/experimental/ugrid/regions_combine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def setup_cache(self):
9292
)
9393

9494
def setup(self, n_cubesphere, imaginary_data=True, create_result_cube=True):
95-
"""Combine-tests "standard" setup operation.
95+
"""Combine tests "standard" setup operation.
9696
9797
Load the source cubes (full-mesh + region) from disk.
9898
These are specific to the cubesize parameter.

benchmarks/benchmarks/import_iris.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# This file is part of Iris and is released under the BSD license.
44
# See LICENSE in the root of the repository for full licensing details.
55

6-
"""import iris benchmarking."""
6+
"""Import iris benchmarking."""
77

88
from importlib import import_module, reload
99

benchmarks/benchmarks/load/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ManyVars:
112112

113113
@staticmethod
114114
def _create_file(save_path: str) -> None:
115-
"""Is run externally - everything must be self-contained."""
115+
"""Run externally - everything must be self-contained."""
116116
import numpy as np
117117

118118
from iris import save

benchmarks/benchmarks/metadata_manager_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# This file is part of Iris and is released under the BSD license.
44
# See LICENSE in the root of the repository for full licensing details.
5-
"""metadata_manager_factory benchmark tests."""
5+
"""Metadata manager factory benchmark tests."""
66

77
from iris.common import (
88
AncillaryVariableMetadata,

benchmarks/benchmarks/sperf/combine_regions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def setup_cache(self):
8383
)
8484

8585
def setup(self, n_cubesphere, imaginary_data=True, create_result_cube=True):
86-
"""Combine-tests "standard" setup operation.
86+
"""Combine tests "standard" setup operation.
8787
8888
Load the source cubes (full-mesh + region) from disk.
8989
These are specific to the cubesize parameter.

benchmarks/bm_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _check_requirements(package: str) -> None:
6666

6767

6868
def _prep_data_gen_env() -> None:
69-
"""Create/access a separate, unchanging environment for generating test data."""
69+
"""Create or access a separate, unchanging environment for generating test data."""
7070
python_version = "3.11"
7171
data_gen_var = "DATA_GEN_PYTHON"
7272
if data_gen_var in environ:

docs/gallery_code/general/plot_custom_aggregation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def count_spells(data, threshold, axis, spell_length):
3939
Parameters
4040
----------
4141
data : array
42-
raw data to be compared with value threshold.
42+
Raw data to be compared with value threshold.
4343
threshold : float
44-
threshold point for 'significant' datapoints.
44+
Threshold point for 'significant' datapoints.
4545
axis : int
46-
number of the array dimension mapping the time sequences.
47-
(Can also be negative, e.g. '-1' means last dimension)
46+
Number of the array dimension mapping the time sequences.
47+
(Can also be negative, e.g. '-1' means last dimension).
4848
spell_length : int
49-
number of consecutive times at which value > threshold to "count".
49+
Number of consecutive times at which value > threshold to "count".
5050
5151
"""
5252
if axis < 0:

docs/gallery_code/general/plot_rotated_pole_mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Rotated Pole Mapping
3-
=====================
3+
====================
44
55
This example uses several visualisation methods to achieve an array of
66
differing images, including:

docs/src/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# serve to show the default.
1818
# ----------------------------------------------------------------------------
1919

20-
"""sphinx config."""
20+
"""Config for sphinx."""
2121

2222
import datetime
2323
from importlib.metadata import version as get_version

docs/src/developers_guide/documenting/docstrings_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""docstring attribute example."""
1+
"""Docstring attribute example."""
22

33

44
class ExampleClass:

docs/src/developers_guide/documenting/docstrings_sample_routine.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""docstring routine example."""
1+
"""Docstring routine example."""
22

33

44
def sample_routine(arg1, arg2, kwarg1="foo", kwarg2=None):
@@ -12,16 +12,16 @@ def sample_routine(arg1, arg2, kwarg1="foo", kwarg2=None):
1212
First argument description.
1313
arg2 : numpy.ndarray
1414
Second argument description.
15-
kwarg1: str, optional
15+
kwarg1 : str, optional
1616
The first keyword argument. This argument description
1717
can be multi-lined.
18-
kwarg2 : bool, optional
18+
**kwarg2 : bool, optional
1919
The second keyword argument.
2020
2121
Returns
2222
-------
2323
numpy.ndarray
24-
numpy.ndarray of arg1 * arg2
24+
A numpy.ndarray of arg1 * arg2.
2525
2626
"""
2727
pass

docs/src/further_topics/filtering_warnings.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ Warnings:
4747

4848
>>> my_operation()
4949
...
50-
iris/coord_systems.py:442: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
50+
iris/coord_systems.py:444: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
5151
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)
52-
iris/coord_systems.py:768: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
52+
iris/coord_systems.py:770: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
5353
warnings.warn(
5454

5555
Warnings can be suppressed using the Python warnings filter with the ``ignore``
@@ -110,7 +110,7 @@ You can target specific Warning messages, e.g.
110110
... warnings.filterwarnings("ignore", message="Discarding false_easting")
111111
... my_operation()
112112
...
113-
iris/coord_systems.py:442: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
113+
iris/coord_systems.py:444: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
114114
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)
115115

116116
::
@@ -125,16 +125,16 @@ Or you can target Warnings raised by specific lines of specific modules, e.g.
125125
.. doctest:: filtering_warnings
126126

127127
>>> with warnings.catch_warnings():
128-
... warnings.filterwarnings("ignore", module="iris.coord_systems", lineno=442)
128+
... warnings.filterwarnings("ignore", module="iris.coord_systems", lineno=444)
129129
... my_operation()
130130
...
131-
iris/coord_systems.py:768: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
131+
iris/coord_systems.py:770: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
132132
warnings.warn(
133133

134134
::
135135

136-
python -W ignore:::iris.coord_systems:442
137-
export PYTHONWARNINGS=ignore:::iris.coord_systems:442
136+
python -W ignore:::iris.coord_systems:444
137+
export PYTHONWARNINGS=ignore:::iris.coord_systems:444
138138

139139
Warnings from a Common Source
140140
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -188,7 +188,7 @@ module during execution:
188188
... )
189189
... my_operation()
190190
...
191-
iris/coord_systems.py:442: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
191+
iris/coord_systems.py:444: IrisUserWarning: Setting inverse_flattening does not affect other properties of the GeogCS object. To change other properties set them explicitly or create a new GeogCS instance.
192192
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)
193193

194194
----

lib/iris/_concatenate.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class _DerivedCoordAndDims(
160160
Parameters
161161
----------
162162
coord : :class:`iris.coord.DimCoord` or :class:`iris.coord.AuxCoord`
163-
dims: tuple
163+
dims : tuple
164164
A tuple of the data dimension(s) spanned by the coordinate.
165165
aux_factory : :class:`iris.aux_factory.AuxCoordFactory`
166166
@@ -196,7 +196,7 @@ def __new__(cls, ancil, dims):
196196
197197
Parameters
198198
----------
199-
ancil : :class:`iris.coord.CellMeasure` or :class:`iris.coord.AncillaryVariable`.
199+
ancil : :class:`iris.coord.CellMeasure` or :class:`iris.coord.AncillaryVariable`
200200
dims :
201201
The dimension(s) associated with ancil.
202202
@@ -271,7 +271,6 @@ class _CoordExtent(namedtuple("CoordExtent", ["points", "bounds"])):
271271
----------
272272
points : :class:`_Extent`
273273
The :class:`_Extent` of the coordinate point values.
274-
275274
bounds :
276275
A list containing the :class:`_Extent` of the coordinate lower
277276
bound and the upper bound. Defaults to None if no associated
@@ -297,7 +296,7 @@ def concatenate(
297296
cubes : iterable of :class:`iris.cube.Cube`
298297
An iterable containing one or more :class:`iris.cube.Cube` instances
299298
to be concatenated together.
300-
error_on_mismatch: bool, default=False
299+
error_on_mismatch : bool, default=False
301300
If True, raise an informative
302301
:class:`~iris.exceptions.ContatenateError` if registration fails.
303302
check_aux_coords : bool, default=True
@@ -491,7 +490,7 @@ def _coordinate_differences(self, other, attr, reason="metadata"):
491490
between `self` and `other`.
492491
reason : str, default="metadata"
493492
The reason to give for mismatch (function is normally, but not
494-
always, testing metadata)
493+
always, testing metadata).
495494
496495
Returns
497496
-------
@@ -763,9 +762,9 @@ def axis(self):
763762
return self._axis
764763

765764
def concatenate(self):
766-
"""Concatenates all the source-cubes registered with the :class:`_ProtoCube`.
765+
"""Concatenate all the source-cubes registered with the :class:`_ProtoCube`.
767766
768-
Concatenates all the source-cubes registered with the
767+
Concatenate all the source-cubes registered with the
769768
:class:`_ProtoCube` over the nominated common dimension.
770769
771770
Returns

lib/iris/_constraints.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ def __init__(self, coord_name, coord_thing):
282282
Parameters
283283
----------
284284
coord_name : str
285-
The name of the coordinate to constrain
285+
The name of the coordinate to constrain.
286286
coord_thing :
287-
The object to compare
287+
The object to compare.
288288
289289
"""
290290
self.coord_name = coord_name
@@ -492,9 +492,9 @@ def list_of_constraints(constraints):
492492

493493

494494
def as_constraint(thing):
495-
"""Casts an object into a cube constraint where possible.
495+
"""Cast an object into a cube constraint where possible.
496496
497-
Casts an object into a cube constraint where possible, otherwise
497+
Cast an object into a cube constraint where possible, otherwise
498498
a TypeError will be raised.
499499
500500
If the given object is already a valid constraint then the given object

lib/iris/_data_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _deepcopy(self, memo, data=None):
171171

172172
@property
173173
def data(self):
174-
"""Returns the real data. Any lazy data being managed will be realised.
174+
"""Return the real data. Any lazy data being managed will be realised.
175175
176176
Returns
177177
-------

lib/iris/_lazy_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ def as_concrete_data(data):
338338
Parameters
339339
----------
340340
data :
341-
A dask array, NumPy `ndarray` or masked array
341+
A dask array, NumPy `ndarray` or masked array.
342342
343343
Returns
344344
-------

lib/iris/_merge.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ def _build_separable_group(
877877
dependency on any other candidate dimensions within the space.
878878
group :
879879
A set of related (chained) inseparable candidate dimensions.
880-
separable_consistent_groups:
880+
separable_consistent_groups :
881881
A list of candidate dimension groups that are consistently separable.
882882
positions :
883883
A list containing a dictionary of candidate dimension key to
@@ -1047,7 +1047,7 @@ def derive_space(groups, relation_matrix, positions, function_matrix=None):
10471047
----------
10481048
groups :
10491049
A list of all related (chained) inseparable candidate dimensions.
1050-
relation_matrix:
1050+
relation_matrix :
10511051
The relation dictionary for each candidate dimension.
10521052
positions :
10531053
A list containing a dictionary of candidate dimension key to
@@ -1294,7 +1294,7 @@ def register(self, cube, error_on_mismatch=False):
12941294
cube :
12951295
Candidate :class:`iris.cube.Cube` to be associated with
12961296
this :class:`ProtoCube`.
1297-
error_on_mismatch :bool, default=False
1297+
error_on_mismatch : bool, default=False
12981298
If True, raise an informative
12991299
:class:`~iris.exceptions.MergeError` if registration fails.
13001300
@@ -1335,7 +1335,8 @@ def _guess_axis(self, name):
13351335
13361336
Returns
13371337
-------
1338-
axis : {'T', 'Z', 'Y', 'X'} or None.
1338+
str or None
1339+
{'T', 'Z', 'Y', 'X'} or None.
13391340
13401341
"""
13411342
axis = None

0 commit comments

Comments
 (0)