Skip to content

Commit 67bb5ae

Browse files
tkknightpre-commit-ci[bot]bjlittle
authored
ruff compliance for D401. (#5687)
* ruff complliance for D205 (wip) * wip * wip * wip * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * various minor fixes. * fix doctest. * gallery noqa and minor fixes. * removed comments * ruff compliance for D401. * removed temp noqa's * wip * wip * fix typo. * Update lib/iris/fileformats/_ff.py Co-authored-by: Bill Little <[email protected]> * review actions. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Bill Little <[email protected]>
1 parent 54f9e98 commit 67bb5ae

Some content is hidden

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

52 files changed

+154
-155
lines changed

.ruff.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ lint.ignore = [
2929
"D102", # Missing docstring in public method
3030
# (D-3) Temporary, before an initial review, either fix ocurrences or move to (2).
3131
"D103", # Missing docstring in public function
32-
"D401", # First line of docstring should be in imperative mood: ...
3332

3433
# pyupgrade (UP)
3534
# https://docs.astral.sh/ruff/rules/#pyupgrade-up

benchmarks/benchmarks/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
def disable_repeat_between_setup(benchmark_object):
13-
"""Decorator for benchmarks where object persistence would be inappropriate.
13+
"""Benchmarks where object persistence would be inappropriate (decorator).
1414
1515
E.g:
1616
* Benchmarking data realisation
@@ -86,7 +86,7 @@ def addedmem_mb(self):
8686

8787
@staticmethod
8888
def decorator(decorated_func):
89-
"""Decorates this benchmark to track growth in resident memory during execution.
89+
"""Benchmark to track growth in resident memory during execution.
9090
9191
Intended for use on ASV ``track_`` benchmarks. Applies the
9292
:class:`TrackAddedMemoryAllocation` context manager to the benchmark
@@ -107,7 +107,9 @@ def _wrapper(*args, **kwargs):
107107

108108

109109
def on_demand_benchmark(benchmark_object):
110-
"""Decorator. Disables these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
110+
"""Disables these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
111+
112+
This is a decorator.
111113
112114
For benchmarks that, for whatever reason, should not be run by default.
113115
E.g:

benchmarks/benchmarks/cperf/load.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@on_demand_benchmark
1111
class SingleDiagnosticLoad(SingleDiagnosticMixin):
1212
def time_load(self, _, __, ___):
13-
"""The 'real world comparison'.
13+
"""Perform a 'real world comparison'.
1414
1515
* UM coords are always realised (DimCoords).
1616
* LFRic coords are not realised by default (MeshCoords).
@@ -26,7 +26,7 @@ def time_load(self, _, __, ___):
2626
assert coord.has_lazy_bounds() == expecting_lazy_coords
2727

2828
def time_load_w_realised_coords(self, _, __, ___):
29-
"""A valuable extra comparison where both UM and LFRic coords are realised."""
29+
"""Valuable extra comparison where both UM and LFRic coords are realised."""
3030
cube = self.load()
3131
for coord_name in "longitude", "latitude":
3232
coord = cube.coord(coord_name)

benchmarks/benchmarks/cube.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def setup(self):
4545
raise NotImplementedError
4646

4747
def create(self):
48-
"""Generic cube creation.
48+
"""Create a cube (generic).
4949
5050
cube_kwargs allow dynamic inclusion of different components;
5151
specified in subclasses.

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-
"""The 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/generate_data/stock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _external(func_name_, temp_file_dir, **kwargs_):
4949
def create_file__xios_2d_face_half_levels(
5050
temp_file_dir, dataset_name, n_faces=866, n_times=1
5151
):
52-
"""Wrapper for :meth:`iris.tests.stock.netcdf.create_file__xios_2d_face_half_levels`.
52+
"""Create file wrapper for :meth:`iris.tests.stock.netcdf.create_file__xios_2d_face_half_levels`.
5353
5454
Have taken control of temp_file_dir
5555
@@ -67,7 +67,7 @@ def create_file__xios_2d_face_half_levels(
6767
def create_file__xios_3d_face_half_levels(
6868
temp_file_dir, dataset_name, n_faces=866, n_times=1, n_levels=38
6969
):
70-
"""Wrapper for :meth:`iris.tests.stock.netcdf.create_file__xios_3d_face_half_levels`.
70+
"""Create file wrapper for :meth:`iris.tests.stock.netcdf.create_file__xios_3d_face_half_levels`.
7171
7272
Have taken control of temp_file_dir
7373
@@ -84,7 +84,7 @@ def create_file__xios_3d_face_half_levels(
8484

8585

8686
def sample_mesh(n_nodes=None, n_faces=None, n_edges=None, lazy_values=False):
87-
"""Wrapper for :meth:iris.tests.stock.mesh.sample_mesh`."""
87+
"""Sample mesh wrapper for :meth:iris.tests.stock.mesh.sample_mesh`."""
8888

8989
def _external(*args, **kwargs):
9090
from iris.experimental.ugrid import save_mesh
@@ -112,7 +112,7 @@ def _external(*args, **kwargs):
112112

113113

114114
def sample_meshcoord(sample_mesh_kwargs=None, location="face", axis="x"):
115-
"""Wrapper for :meth:`iris.tests.stock.mesh.sample_meshcoord`.
115+
"""Sample meshcoord wrapper for :meth:`iris.tests.stock.mesh.sample_meshcoord`.
116116
117117
Parameters deviate from the original as cannot pass a
118118
:class:`iris.experimental.ugrid.Mesh to the separate Python instance - must

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-
"""The 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
@@ -332,7 +332,7 @@ def add_asv_arguments(self) -> None:
332332
@staticmethod
333333
@abstractmethod
334334
def func(args: argparse.Namespace):
335-
"""The function to return when the subparser is parsed.
335+
"""Return when the subparser is parsed.
336336
337337
`func` is then called, performing the user's selected sub-command.
338338

docs/gallery_code/general/plot_custom_file_loading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090

9191

9292
def load_NAME_III(filename):
93-
"""Loads the Met Office's NAME III grid output files.
93+
"""Load the Met Office's NAME III grid output files.
9494
9595
Loads the Met Office's NAME III grid output files returning headers, column
9696
definitions and data arrays as 3 separate lists.
@@ -180,7 +180,7 @@ def load_NAME_III(filename):
180180

181181

182182
def NAME_to_cube(filenames, callback):
183-
"""Returns a generator of cubes given a list of filenames and a callback."""
183+
"""Return a generator of cubes given a list of filenames and a callback."""
184184
for filename in filenames:
185185
header, column_headings, data_arrays = load_NAME_III(filename)
186186

docs/gallery_code/meteorology/plot_COP_maps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
def cop_metadata_callback(cube, field, filename):
35-
"""Function which adds an "Experiment" coordinate which comes from the filename."""
35+
"""Add an "Experiment" coordinate which comes from the filename."""
3636
# Extract the experiment name (such as A1B or E1) from the filename (in
3737
# this case it is just the start of the file name, before the first ".").
3838
fname = os.path.basename(filename) # filename without path.

docs/gallery_tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
@pytest.fixture
2020
def image_setup_teardown():
21-
"""Setup and teardown fixture.
21+
"""Perform setup and teardown fixture.
2222
2323
Ensures all figures are closed before and after test to prevent one test
2424
polluting another if it fails with a figure unclosed.

docs/gallery_tests/test_gallery_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
def gallery_examples():
20-
"""Generator to yield all current gallery examples."""
20+
"""Entry point for generator to yield all current gallery examples."""
2121
for example_file in GALLERY_DIR.glob("*/plot*.py"):
2222
yield example_file.stem
2323

lib/iris/_concatenate.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def name(self):
151151
class _DerivedCoordAndDims(
152152
namedtuple("DerivedCoordAndDims", ["coord", "dims", "aux_factory"])
153153
):
154-
"""Container for a derived coordinate and dimnesions(s).
154+
"""Container for a derived coordinate and dimensions(s).
155155
156156
Container for a derived coordinate, the associated AuxCoordFactory, and the
157157
associated data dimension(s) spanned over a :class:`iris.cube.Cube`.
@@ -385,10 +385,7 @@ class _CubeSignature:
385385
"""
386386

387387
def __init__(self, cube):
388-
"""Represents the cube metadata and associated coordinate metadata.
389-
390-
Represents the cube metadata and associated coordinate metadata that
391-
allows suitable cubes for concatenation to be identified.
388+
"""Represent the cube metadata and associated coordinate metadata.
392389
393390
Parameters
394391
----------
@@ -733,10 +730,7 @@ class _ProtoCube:
733730
"""Framework for concatenating multiple source-cubes over one common dimension."""
734731

735732
def __init__(self, cube):
736-
"""Create a new _ProtoCube and record the cube as a source-cube.
737-
738-
Create a new _ProtoCube from the given cube and record the cube
739-
as a source-cube.
733+
"""Create a new _ProtoCube from the given cube and record the cube as a source-cube.
740734
741735
Parameters
742736
----------

lib/iris/_data_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def __ne__(self, other):
117117
return result
118118

119119
def __repr__(self):
120-
"""Returns an string representation of the instance."""
120+
"""Return an string representation of the instance."""
121121
fmt = "{cls}({data!r})"
122122
result = fmt.format(data=self.core_data(), cls=type(self).__name__)
123123

@@ -269,7 +269,7 @@ def shape(self):
269269
return self.core_data().shape
270270

271271
def copy(self, data=None):
272-
"""Returns a deep copy of this :class:`~iris._data_manager.DataManager` instance.
272+
"""Return a deep copy of this :class:`~iris._data_manager.DataManager` instance.
273273
274274
Parameters
275275
----------

lib/iris/_merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ def _report_duplicate(self, nd_indexes, group_by_nd_index):
11821182
raise iris.exceptions.DuplicateDataError(msg)
11831183

11841184
def merge(self, unique=True):
1185-
"""Returns the list of cubes resulting from merging the registered source-cubes.
1185+
"""Return the list of cubes resulting from merging the registered source-cubes.
11861186
11871187
Parameters
11881188
----------
@@ -1319,7 +1319,7 @@ def register(self, cube, error_on_mismatch=False):
13191319
return match
13201320

13211321
def _guess_axis(self, name):
1322-
"""Returns a "best guess" axis name of the candidate dimension.
1322+
"""Return a "best guess" axis name of the candidate dimension.
13231323
13241324
Heuristic categoration of the candidate dimension
13251325
(i.e. scalar_defn index) into either label 'T', 'Z', 'Y', 'X'
@@ -1564,7 +1564,7 @@ def _get_cube(self, data):
15641564
return cube
15651565

15661566
def _nd_index(self, position):
1567-
"""Returns the n-dimensional index of thr source-cube, within the merged cube."""
1567+
"""Return the n-dimensional index of thr source-cube, within the merged cube."""
15681568
index = []
15691569

15701570
# Determine the index of the source-cube cell for each dimension.

lib/iris/_representation/cube_printout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class CubePrinter:
134134
N_INDENT_EXTRA = 4
135135

136136
def __init__(self, cube_or_summary):
137-
"""An object that provides a printout of a cube.
137+
"""Object that provides a printout of a cube.
138138
139139
Parameters
140140
----------

lib/iris/analysis/_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def get_xy_coords(cube, dim_coords=False):
158158

159159

160160
def snapshot_grid(cube):
161-
"""Helper function that returns deep copies of lateral (dimension) coordinates from a cube."""
161+
"""Return deep copies of lateral (dimension) coordinates from a cube."""
162162
x, y = get_xy_dim_coords(cube)
163163
return x.copy(), y.copy()
164164

lib/iris/analysis/_regrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def __init__(self, src_grid_cube, target_grid_cube, weights=None):
407407

408408
@staticmethod
409409
def _get_horizontal_coord(cube, axis):
410-
"""Gets the horizontal coordinate on the supplied cube along the specified axis.
410+
"""Get the horizontal coordinate on the supplied cube along the specified axis.
411411
412412
Parameters
413413
----------

lib/iris/analysis/cartography.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def _quadrant_area(radian_lat_bounds, radian_lon_bounds, radius_of_earth):
376376

377377

378378
def area_weights(cube, normalize=False):
379-
r"""Returns an array of area weights, with the same dimensions as the cube.
379+
r"""Return an array of area weights, with the same dimensions as the cube.
380380
381381
This is a 2D lat/lon area weights array, repeated over the non lat/lon
382382
dimensions.

lib/iris/analysis/maths.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def _add_subtract_common(
323323
dim=None,
324324
in_place=False,
325325
):
326-
"""Function which shares common code between addition and subtraction of cubes.
326+
"""Share common code between addition and subtraction of cubes.
327327
328328
Parameters
329329
----------
@@ -532,7 +532,7 @@ def divide(cube, other, dim=None, in_place=False):
532532

533533

534534
def exponentiate(cube, exponent, in_place=False):
535-
"""Returns the result of the given cube to the power of a scalar.
535+
"""Return the result of the given cube to the power of a scalar.
536536
537537
Parameters
538538
----------
@@ -821,7 +821,7 @@ def _binary_op_common(
821821
in_place=False,
822822
sanitise_metadata=True,
823823
):
824-
"""Function which shares common code between binary operations.
824+
"""Share common code between binary operations.
825825
826826
Parameters
827827
----------
@@ -1172,7 +1172,7 @@ def __call__(
11721172
new_name=None,
11731173
**kwargs_data_func,
11741174
):
1175-
"""Applies the ifunc to the cube(s).
1175+
"""Apply the ifunc to the cube(s).
11761176
11771177
Parameters
11781178
----------

lib/iris/analysis/trajectory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Trajectory:
3737
"""A series of given waypoints with pre-calculated sample points."""
3838

3939
def __init__(self, waypoints, sample_count=10):
40-
"""Defines a trajectory using a sequence of waypoints.
40+
"""Define a trajectory using a sequence of waypoints.
4141
4242
Parameters
4343
----------
@@ -128,7 +128,7 @@ def _get_interp_points(self):
128128
return [(k, v) for k, v in points.items()]
129129

130130
def _src_cube_anon_dims(self, cube):
131-
"""A helper method to locate the index of anonymous dimensions.
131+
"""Locate the index of anonymous dimensions.
132132
133133
A helper method to locate the index of anonymous dimensions on the
134134
interpolation target, ``cube``.
@@ -712,7 +712,7 @@ class UnstructuredNearestNeigbourRegridder:
712712
# TODO: cache the necessary bits of the operation so reuse can actually
713713
# be more efficient.
714714
def __init__(self, src_cube, target_grid_cube):
715-
"""A nearest-neighbour regridder.
715+
"""Nearest-neighbour regridder.
716716
717717
A nearest-neighbour regridder to perform regridding from the source
718718
grid to the target grid.

lib/iris/common/_split_attribute_dicts.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ def _convert_pairedkeys_dict_to_splitattrs(dic):
6666

6767

6868
def adjust_for_split_attribute_dictionaries(operation):
69-
"""Decorator to make a function of attribute-dictionaries work with split attributes.
69+
"""Generate attribute-dictionaries to work with split attributes.
70+
71+
Decorator to make a function of attribute-dictionaries work with split attributes.
7072
7173
The wrapped function of attribute-dictionaries is currently always one of "equals",
7274
"combine" or "difference", with signatures like :
@@ -91,6 +93,7 @@ def adjust_for_split_attribute_dictionaries(operation):
9193
"Split" dictionaries are all of class :class:`~iris.cube.CubeAttrsDict`, since
9294
the only usage of 'split' attribute dictionaries is in Cubes (i.e. they are not
9395
used for cube components).
96+
9497
"""
9598

9699
@wraps(operation)

0 commit comments

Comments
 (0)