Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 12, 2023
1 parent e9c617b commit 57fc892
Show file tree
Hide file tree
Showing 20 changed files with 76 additions and 55 deletions.
10 changes: 6 additions & 4 deletions lib/iris/analysis/_area_weighted.py
Expand Up @@ -173,8 +173,9 @@ def _get_xy_coords(cube):
]
if len(x_coords) != 1:
raise ValueError(
"Cube {!r} must contain a single 1D x "
"coordinate.".format(cube.name())
"Cube {!r} must contain a single 1D x " "coordinate.".format(
cube.name()
)
)
x_coord = x_coords[0]

Expand All @@ -190,8 +191,9 @@ def _get_xy_coords(cube):
]
if len(y_coords) != 1:
raise ValueError(
"Cube {!r} must contain a single 1D y "
"coordinate.".format(cube.name())
"Cube {!r} must contain a single 1D y " "coordinate.".format(
cube.name()
)
)
y_coord = y_coords[0]

Expand Down
10 changes: 6 additions & 4 deletions lib/iris/analysis/_interpolation.py
Expand Up @@ -139,16 +139,18 @@ def get_xy_coords(cube, dim_coords=False):
x_coords = cube.coords(axis="x", dim_coords=dim_coords)
if len(x_coords) != 1 or x_coords[0].ndim != 1:
raise ValueError(
"Cube {!r} must contain a single 1D x "
"coordinate.".format(cube.name())
"Cube {!r} must contain a single 1D x " "coordinate.".format(
cube.name()
)
)
x_coord = x_coords[0]

y_coords = cube.coords(axis="y", dim_coords=dim_coords)
if len(y_coords) != 1 or y_coords[0].ndim != 1:
raise ValueError(
"Cube {!r} must contain a single 1D y "
"coordinate.".format(cube.name())
"Cube {!r} must contain a single 1D y " "coordinate.".format(
cube.name()
)
)
y_coord = y_coords[0]

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/analysis/_regrid.py
Expand Up @@ -455,8 +455,9 @@ def _get_horizontal_coord(cube, axis):
coords = cube.coords(axis=axis, dim_coords=False)
if len(coords) != 1:
raise ValueError(
"Cube {!r} must contain a single 1D {} "
"coordinate.".format(cube.name(), axis)
"Cube {!r} must contain a single 1D {} " "coordinate.".format(
cube.name(), axis
)
)
return coords[0]

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/analysis/cartography.py
Expand Up @@ -535,8 +535,9 @@ def cosine_latitude_weights(cube):
lat = lat_coords[0]
except IndexError:
raise ValueError(
"Cannot get latitude "
"coordinate from cube {!r}.".format(cube.name())
"Cannot get latitude " "coordinate from cube {!r}.".format(
cube.name()
)
)

# Get the dimension position(s) of the latitude coordinate.
Expand Down
10 changes: 6 additions & 4 deletions lib/iris/coord_categorisation.py
Expand Up @@ -255,17 +255,19 @@ def _validate_seasons(seasons):
]
if not_present:
raise ValueError(
"some months do not appear in any season: "
"{!s}".format(", ".join(not_present))
"some months do not appear in any season: " "{!s}".format(
", ".join(not_present)
)
)
# Make a list of months that appear multiple times...
multi_present = [
calendar.month_abbr[month] for month in range(1, 13) if c[month] > 1
]
if multi_present:
raise ValueError(
"some months appear in more than one season: "
"{!s}".format(", ".join(multi_present))
"some months appear in more than one season: " "{!s}".format(
", ".join(multi_present)
)
)
return

Expand Down
10 changes: 6 additions & 4 deletions lib/iris/cube.py
Expand Up @@ -617,8 +617,9 @@ def concatenate_cube(
msgs = []
msgs.append("An unexpected problem prevented concatenation.")
msgs.append(
"Expected only a single cube, "
"found {}.".format(n_res_cubes)
"Expected only a single cube, " "found {}.".format(
n_res_cubes
)
)
raise iris.exceptions.ConcatenateError(msgs)
else:
Expand Down Expand Up @@ -3668,8 +3669,9 @@ def slices(self, ref_to_slice, ordered=True):
dim = int(ref)
except ValueError:
raise ValueError(
"{} Incompatible type {} for "
"slicing".format(ref, type(ref))
"{} Incompatible type {} for " "slicing".format(
ref, type(ref)
)
)
if dim < 0 or dim > self.ndim:
msg = (
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/fileformats/abf.py
Expand Up @@ -80,8 +80,9 @@ def __init__(self, filename):
basename = os.path.basename(filename)
if len(basename) != 24:
raise ValueError(
"ABFField expects a filename of 24 characters: "
"{}".format(basename)
"ABFField expects a filename of 24 characters: " "{}".format(
basename
)
)
self._filename = filename

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/fileformats/netcdf/loader.py
Expand Up @@ -416,8 +416,9 @@ def coord_from_term(term):
if cf_var_name == name:
return coord
warnings.warn(
"Unable to find coordinate for variable "
"{!r}".format(name),
"Unable to find coordinate for variable " "{!r}".format(
name
),
category=iris.exceptions.IrisFactoryCoordNotFoundWarning,
)

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/fileformats/nimrod.py
Expand Up @@ -236,8 +236,9 @@ def _read_header(self, infile):
trailing_length = struct.unpack(">L", infile.read(4))[0]
if trailing_length != leading_length:
raise TranslationError(
"Expected header trailing_length of {}, "
"got {}.".format(leading_length, trailing_length)
"Expected header trailing_length of {}, " "got {}.".format(
leading_length, trailing_length
)
)

def _read_data(self, infile):
Expand Down
10 changes: 6 additions & 4 deletions lib/iris/fileformats/nimrod_load_rules.py
Expand Up @@ -458,8 +458,9 @@ def horizontal_grid(cube, field, handle_metadata_errors):
y_coord_name = "latitude"
else:
raise TranslationError(
"Horizontal grid type {} not "
"implemented".format(field.horizontal_grid_type)
"Horizontal grid type {} not " "implemented".format(
field.horizontal_grid_type
)
)
points = np.linspace(
field.x_origin,
Expand Down Expand Up @@ -594,8 +595,9 @@ def vertical_coord(cube, field):
return

warnings.warn(
"Vertical coord {!r} not yet handled"
"".format(field.vertical_coord_type),
"Vertical coord {!r} not yet handled" "".format(
field.vertical_coord_type
),
category=TranslationWarning,
)

Expand Down
5 changes: 3 additions & 2 deletions lib/iris/fileformats/pp.py
Expand Up @@ -1842,8 +1842,9 @@ def fetch_valid_values_array():
# Check whether this field uses a land or a sea mask.
if field.lbpack.n3 not in (1, 2):
raise ValueError(
"Unsupported mask compression : "
"lbpack.n3 = {}.".format(field.lbpack.n3)
"Unsupported mask compression : " "lbpack.n3 = {}.".format(
field.lbpack.n3
)
)
if field.lbpack.n3 == 2:
# Sea-mask packing : points are inverse of the land-mask.
Expand Down
20 changes: 12 additions & 8 deletions lib/iris/fileformats/rules.py
Expand Up @@ -129,13 +129,15 @@ def aux_factory(cube, aux_factory_class):
]
if not aux_factories:
raise ValueError(
"Cube does not have an aux factory of "
"type {!r}.".format(aux_factory_class)
"Cube does not have an aux factory of " "type {!r}.".format(
aux_factory_class
)
)
elif len(aux_factories) > 1:
raise ValueError(
"Cube has more than one aux factory of "
"type {!r}.".format(aux_factory_class)
"Cube has more than one aux factory of " "type {!r}.".format(
aux_factory_class
)
)
return aux_factories[0]

Expand Down Expand Up @@ -173,13 +175,15 @@ def _dereference_args(factory, reference_targets, regrid_cache, cube):
args.append(new_coord)
else:
raise _ReferenceError(
"Unable to regrid reference for"
" {!r}".format(arg.name)
"Unable to regrid reference for" " {!r}".format(
arg.name
)
)
else:
raise _ReferenceError(
"The source data contains no "
"field(s) for {!r}.".format(arg.name)
"The source data contains no " "field(s) for {!r}.".format(
arg.name
)
)
else:
# If it wasn't a Reference, then arg is a dictionary
Expand Down
6 changes: 3 additions & 3 deletions lib/iris/palette.py
Expand Up @@ -303,9 +303,9 @@ def _load_palette():
'Missing meta-data "type" keyword for color map file, "%s"'
% filename
)
assert (
cmap_type == "rgb"
), 'Invalid type [%s] for color map file "%s"' % (cmap_type, filename)
assert cmap_type == "rgb", (
'Invalid type [%s] for color map file "%s"' % (cmap_type, filename)
)

# Update the color map look-up dictionaries.
CMAP_BREWER.add(cmap_name)
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/quickplot.py
Expand Up @@ -90,8 +90,9 @@ def _label(cube, mode, result=None, ndims=2, coords=None, axes=None):
axes.set_ylabel(_title(cube, with_units=True))
else:
msg = (
"Unexpected number of dimensions ({}) given to "
"_label.".format(ndims)
"Unexpected number of dimensions ({}) given to " "_label.".format(
ndims
)
)
raise ValueError(msg)

Expand Down
3 changes: 2 additions & 1 deletion lib/iris/tests/test_io_init.py
Expand Up @@ -29,7 +29,8 @@ def test_decode_uri__str(self):
uri,
),
(
uri := "file:///data/local/someDir/PP/COLPEX/COLPEX_16a_pj001.pp"
uri
:= "file:///data/local/someDir/PP/COLPEX/COLPEX_16a_pj001.pp"
): (
uri[:4],
uri[5:],
Expand Down
Expand Up @@ -156,9 +156,7 @@ def _unrotate_equation(
np.radians(trueLongitude) - lambda_angle
) + np.sin(np.radians(rotated_lons)) * np.sin(
np.radians(trueLongitude) - lambda_angle
) * np.cos(
phi_angle
)
) * np.cos(phi_angle)
sin_rot = -(
(
np.sin(np.radians(trueLongitude) - lambda_angle)
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/common/metadata/test_CubeMetadata.py
Expand Up @@ -403,7 +403,7 @@ def test_splitattrs_cases(
"secondaryXC",
"secondaryCC",
"secondaryCD",
]
],
# NOTE: test CX as well as XC, since primary choices has "AX" but not "XA".
)
def test_splitattrs_global_local_independence(
Expand Down
2 changes: 1 addition & 1 deletion lib/iris/tests/unit/common/resolve/test_Resolve.py
Expand Up @@ -447,7 +447,7 @@ def setUp(self):
]
column_parts = [x for x in zip(*parts)]
self.metadata, self.coords, self.dims = [list(x) for x in column_parts]
self.dims = [dim for dim, in self.dims]
self.dims = [dim for (dim,) in self.dims]
for metadata, coord, dims in parts:
item = _Item(metadata=metadata, coord=coord, dims=dims)
self.items.append(item)
Expand Down
Expand Up @@ -88,7 +88,7 @@ def test_power_in_units(self):
def test_ug_per_m3_units(self):
with mock.patch("warnings.warn") as warn:
self._call_units(
data=((np.ones_like(self.cube.data) * 10)),
data=(np.ones_like(self.cube.data) * 10),
units_str="ug/m3E1",
)
self.assertEqual(warn.call_count, 0)
Expand All @@ -101,7 +101,7 @@ def test_ug_per_m3_units(self):
def test_g_per_kg(self):
with mock.patch("warnings.warn") as warn:
self._call_units(
data=((np.ones_like(self.cube.data) * 1000)), units_str="g/Kg"
data=(np.ones_like(self.cube.data) * 1000), units_str="g/Kg"
)
self.assertEqual(warn.call_count, 0)
self.assertEqual(self.cube.units, "kg/kg")
Expand Down
5 changes: 3 additions & 2 deletions lib/iris/tests/unit/fileformats/pp/test_save.py
Expand Up @@ -140,8 +140,9 @@ def check_cube_name_units_yields_lbfc(self, name, units, lbfc_expected):
self.assertEqual(
lbfc_produced,
lbfc_expected,
"Lbfc for ({!r} / {!r}) should be {:d}, "
"got {:d}".format(name, units, lbfc_expected, lbfc_produced),
"Lbfc for ({!r} / {!r}) should be {:d}, " "got {:d}".format(
name, units, lbfc_expected, lbfc_produced
),
)

def test_name_units_to_lbfc(self):
Expand Down

0 comments on commit 57fc892

Please sign in to comment.