Skip to content

DOCS: Enable numpydoc validation pre-commit hook #5762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,10 @@ repos:
hooks:
- id: sort-all
types: [file, python]

- repo: https://github.com/numpy/numpydoc
rev: v1.6.0
hooks:
- id: numpydoc-validation
exclude: "^lib/iris/tests/|docs/gallery_code/"
types: [file, python]
8 changes: 3 additions & 5 deletions benchmarks/asv_delegated_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ def __init__(

Parameters
----------
conf : Config instance

conf : Config
Config instance.
python : str
Version of Python. Must be of the form "MAJOR.MINOR".

requirements : dict
Dictionary mapping a PyPI package name to a version
identifier string.

tagged_env_vars : dict
Environment variables, tagged for build vs. non-build
Environment variables, tagged for build vs. non-build.

"""
ignored = ["`python`"]
Expand Down
14 changes: 8 additions & 6 deletions benchmarks/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@


def disable_repeat_between_setup(benchmark_object):
"""Benchmarks where object persistence would be inappropriate (decorator).
"""Benchmark where object persistence would be inappropriate (decorator).

E.g:
* Benchmarking data realisation
* Benchmarking Cube coord addition

* Benchmarking data realisation
* Benchmarking Cube coord addition

Can be applied to benchmark classes/methods/functions.

Expand Down Expand Up @@ -107,14 +108,15 @@ def _wrapper(*args, **kwargs):


def on_demand_benchmark(benchmark_object):
"""Disables these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
"""Disable these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.

This is a decorator.

For benchmarks that, for whatever reason, should not be run by default.
E.g:
* Require a local file
* Used for scalability analysis instead of commit monitoring.

* Require a local file
* Used for scalability analysis instead of commit monitoring.

Can be applied to benchmark classes/methods/functions.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def setup_cache(self):
)

def setup(self, n_cubesphere, imaginary_data=True, create_result_cube=True):
"""Combine-tests "standard" setup operation.
"""Combine tests "standard" setup operation.

Load the source cubes (full-mesh + region) from disk.
These are specific to the cubesize parameter.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/import_iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.

"""import iris benchmarking."""
"""Import iris benchmarking."""

from importlib import import_module, reload

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/load/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class ManyVars:

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

from iris import save
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/metadata_manager_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""metadata_manager_factory benchmark tests."""
"""Metadata manager factory benchmark tests."""

from iris.common import (
AncillaryVariableMetadata,
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/sperf/combine_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def setup_cache(self):
)

def setup(self, n_cubesphere, imaginary_data=True, create_result_cube=True):
"""Combine-tests "standard" setup operation.
"""Combine tests "standard" setup operation.

Load the source cubes (full-mesh + region) from disk.
These are specific to the cubesize parameter.
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/bm_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _check_requirements(package: str) -> None:


def _prep_data_gen_env() -> None:
"""Create/access a separate, unchanging environment for generating test data."""
"""Create or access a separate, unchanging environment for generating test data."""
python_version = "3.11"
data_gen_var = "DATA_GEN_PYTHON"
if data_gen_var in environ:
Expand Down
10 changes: 5 additions & 5 deletions docs/gallery_code/general/plot_custom_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def count_spells(data, threshold, axis, spell_length):
Parameters
----------
data : array
raw data to be compared with value threshold.
Raw data to be compared with value threshold.
threshold : float
threshold point for 'significant' datapoints.
Threshold point for 'significant' datapoints.
axis : int
number of the array dimension mapping the time sequences.
(Can also be negative, e.g. '-1' means last dimension)
Number of the array dimension mapping the time sequences.
(Can also be negative, e.g. '-1' means last dimension).
spell_length : int
number of consecutive times at which value > threshold to "count".
Number of consecutive times at which value > threshold to "count".

"""
if axis < 0:
Expand Down
2 changes: 1 addition & 1 deletion docs/gallery_code/general/plot_rotated_pole_mapping.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Rotated Pole Mapping
=====================
====================

This example uses several visualisation methods to achieve an array of
differing images, including:
Expand Down
2 changes: 1 addition & 1 deletion docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# serve to show the default.
# ----------------------------------------------------------------------------

"""sphinx config."""
"""Config for sphinx."""

import datetime
from importlib.metadata import version as get_version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""docstring attribute example."""
"""Docstring attribute example."""


class ExampleClass:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""docstring routine example."""
"""Docstring routine example."""


def sample_routine(arg1, arg2, kwarg1="foo", kwarg2=None):
Expand All @@ -12,16 +12,16 @@ def sample_routine(arg1, arg2, kwarg1="foo", kwarg2=None):
First argument description.
arg2 : numpy.ndarray
Second argument description.
kwarg1: str, optional
kwarg1 : str, optional
The first keyword argument. This argument description
can be multi-lined.
kwarg2 : bool, optional
**kwarg2 : bool, optional
The second keyword argument.

Returns
-------
numpy.ndarray
numpy.ndarray of arg1 * arg2
A numpy.ndarray of arg1 * arg2.

"""
pass
16 changes: 8 additions & 8 deletions docs/src/further_topics/filtering_warnings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ Warnings:

>>> my_operation()
...
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.
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.
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)
iris/coord_systems.py:768: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
iris/coord_systems.py:770: IrisDefaultingWarning: Discarding false_easting and false_northing that are not used by Cartopy.
warnings.warn(

Warnings can be suppressed using the Python warnings filter with the ``ignore``
Expand Down Expand Up @@ -110,7 +110,7 @@ You can target specific Warning messages, e.g.
... warnings.filterwarnings("ignore", message="Discarding false_easting")
... my_operation()
...
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.
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.
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)

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

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

::

python -W ignore:::iris.coord_systems:442
export PYTHONWARNINGS=ignore:::iris.coord_systems:442
python -W ignore:::iris.coord_systems:444
export PYTHONWARNINGS=ignore:::iris.coord_systems:444

Warnings from a Common Source
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -188,7 +188,7 @@ module during execution:
... )
... my_operation()
...
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.
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.
warnings.warn(wmsg, category=iris.warnings.IrisUserWarning)

----
Expand Down
13 changes: 6 additions & 7 deletions lib/iris/_concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class _DerivedCoordAndDims(
Parameters
----------
coord : :class:`iris.coord.DimCoord` or :class:`iris.coord.AuxCoord`
dims: tuple
dims : tuple
A tuple of the data dimension(s) spanned by the coordinate.
aux_factory : :class:`iris.aux_factory.AuxCoordFactory`

Expand Down Expand Up @@ -196,7 +196,7 @@ def __new__(cls, ancil, dims):

Parameters
----------
ancil : :class:`iris.coord.CellMeasure` or :class:`iris.coord.AncillaryVariable`.
ancil : :class:`iris.coord.CellMeasure` or :class:`iris.coord.AncillaryVariable`
dims :
The dimension(s) associated with ancil.

Expand Down Expand Up @@ -271,7 +271,6 @@ class _CoordExtent(namedtuple("CoordExtent", ["points", "bounds"])):
----------
points : :class:`_Extent`
The :class:`_Extent` of the coordinate point values.

bounds :
A list containing the :class:`_Extent` of the coordinate lower
bound and the upper bound. Defaults to None if no associated
Expand All @@ -297,7 +296,7 @@ def concatenate(
cubes : iterable of :class:`iris.cube.Cube`
An iterable containing one or more :class:`iris.cube.Cube` instances
to be concatenated together.
error_on_mismatch: bool, default=False
error_on_mismatch : bool, default=False
If True, raise an informative
:class:`~iris.exceptions.ContatenateError` if registration fails.
check_aux_coords : bool, default=True
Expand Down Expand Up @@ -491,7 +490,7 @@ def _coordinate_differences(self, other, attr, reason="metadata"):
between `self` and `other`.
reason : str, default="metadata"
The reason to give for mismatch (function is normally, but not
always, testing metadata)
always, testing metadata).

Returns
-------
Expand Down Expand Up @@ -763,9 +762,9 @@ def axis(self):
return self._axis

def concatenate(self):
"""Concatenates all the source-cubes registered with the :class:`_ProtoCube`.
"""Concatenate all the source-cubes registered with the :class:`_ProtoCube`.

Concatenates all the source-cubes registered with the
Concatenate all the source-cubes registered with the
:class:`_ProtoCube` over the nominated common dimension.

Returns
Expand Down
8 changes: 4 additions & 4 deletions lib/iris/_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ def __init__(self, coord_name, coord_thing):
Parameters
----------
coord_name : str
The name of the coordinate to constrain
The name of the coordinate to constrain.
coord_thing :
The object to compare
The object to compare.

"""
self.coord_name = coord_name
Expand Down Expand Up @@ -492,9 +492,9 @@ def list_of_constraints(constraints):


def as_constraint(thing):
"""Casts an object into a cube constraint where possible.
"""Cast an object into a cube constraint where possible.

Casts an object into a cube constraint where possible, otherwise
Cast an object into a cube constraint where possible, otherwise
a TypeError will be raised.

If the given object is already a valid constraint then the given object
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/_data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def _deepcopy(self, memo, data=None):

@property
def data(self):
"""Returns the real data. Any lazy data being managed will be realised.
"""Return the real data. Any lazy data being managed will be realised.

Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/_lazy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def as_concrete_data(data):
Parameters
----------
data :
A dask array, NumPy `ndarray` or masked array
A dask array, NumPy `ndarray` or masked array.

Returns
-------
Expand Down
9 changes: 5 additions & 4 deletions lib/iris/_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def _build_separable_group(
dependency on any other candidate dimensions within the space.
group :
A set of related (chained) inseparable candidate dimensions.
separable_consistent_groups:
separable_consistent_groups :
A list of candidate dimension groups that are consistently separable.
positions :
A list containing a dictionary of candidate dimension key to
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def derive_space(groups, relation_matrix, positions, function_matrix=None):
----------
groups :
A list of all related (chained) inseparable candidate dimensions.
relation_matrix:
relation_matrix :
The relation dictionary for each candidate dimension.
positions :
A list containing a dictionary of candidate dimension key to
Expand Down Expand Up @@ -1294,7 +1294,7 @@ def register(self, cube, error_on_mismatch=False):
cube :
Candidate :class:`iris.cube.Cube` to be associated with
this :class:`ProtoCube`.
error_on_mismatch :bool, default=False
error_on_mismatch : bool, default=False
If True, raise an informative
:class:`~iris.exceptions.MergeError` if registration fails.

Expand Down Expand Up @@ -1335,7 +1335,8 @@ def _guess_axis(self, name):

Returns
-------
axis : {'T', 'Z', 'Y', 'X'} or None.
str or None
{'T', 'Z', 'Y', 'X'} or None.

"""
axis = None
Expand Down
Loading