Skip to content

Commit cf5413c

Browse files
[pre-commit.ci] pre-commit autoupdate (#4587)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 21.12b0 → 22.1.0](psf/black@21.12b0...22.1.0) - [github.com/asottile/blacken-docs: v1.12.0 → v1.12.1](adamchainz/blacken-docs@v1.12.0...v1.12.1) - [github.com/aio-libs/sort-all: v1.1.0 → v1.2.0](aio-libs/sort-all@v1.1.0...v1.2.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cbc31c7 commit cf5413c

File tree

20 files changed

+55
-59
lines changed

20 files changed

+55
-59
lines changed

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repos:
2929
- id: no-commit-to-branch
3030

3131
- repo: https://github.com/psf/black
32-
rev: 21.12b0
32+
rev: 22.1.0
3333
hooks:
3434
- id: black
3535
pass_filenames: false
@@ -50,14 +50,14 @@ repos:
5050
args: [--filter-files]
5151

5252
- repo: https://github.com/asottile/blacken-docs
53-
rev: v1.12.0
53+
rev: v1.12.1
5454
hooks:
5555
- id: blacken-docs
5656
types: [file, rst]
5757
additional_dependencies: [black==21.6b0]
5858

5959
- repo: https://github.com/aio-libs/sort-all
60-
rev: v1.1.0
60+
rev: v1.2.0
6161
hooks:
6262
- id: sort-all
6363
types: [file, python]

benchmarks/benchmarks/generate_data/um_files.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ def add_field(level_: int, time_step_: int) -> None:
107107
six_rec = 20 / 3
108108
three_rec = six_rec / 2
109109

110-
new_field.blev = level_1 ** 2 * six_rec - six_rec
110+
new_field.blev = level_1**2 * six_rec - six_rec
111111
new_field.brsvd1 = (
112-
level_1 ** 2 * six_rec + (six_rec * level_1) - three_rec
112+
level_1**2 * six_rec + (six_rec * level_1) - three_rec
113113
)
114114

115115
brsvd2_simulated = np.linspace(0.995, 0, len_z)

benchmarks/benchmarks/plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def setup(self):
2222
# Should generate 10 distinct contours, regardless of dim size.
2323
dim_size = int(ARTIFICIAL_DIM_SIZE / 5)
2424
repeat_number = int(dim_size / 10)
25-
repeat_range = range(int((dim_size ** 2) / repeat_number))
25+
repeat_range = range(int((dim_size**2) / repeat_number))
2626
data = np.repeat(repeat_range, repeat_number)
2727
data = data.reshape((dim_size,) * 2)
2828

docs/gallery_code/meteorology/plot_wind_barbs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030

3131
# To illustrate the full range of barbs, scale the wind speed up to pretend
3232
# that a storm is passing over
33-
magnitude = (uwind ** 2 + vwind ** 2) ** 0.5
33+
magnitude = (uwind**2 + vwind**2) ** 0.5
3434
magnitude.convert_units("knot")
3535
max_speed = magnitude.collapsed(
3636
("latitude", "longitude"), iris.analysis.MAX
@@ -41,7 +41,7 @@ def main():
4141
vwind = vwind / max_speed * max_desired
4242

4343
# Create a cube containing the wind speed
44-
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5
44+
windspeed = (uwind**2 + vwind**2) ** 0.5
4545
windspeed.rename("windspeed")
4646
windspeed.convert_units("knot")
4747

docs/gallery_code/meteorology/plot_wind_speed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def main():
2727
vwind = iris.load_cube(infile, "y_wind")
2828

2929
# Create a cube containing the wind speed.
30-
windspeed = (uwind ** 2 + vwind ** 2) ** 0.5
30+
windspeed = (uwind**2 + vwind**2) ** 0.5
3131
windspeed.rename("windspeed")
3232

3333
# Plot the wind speed as a contour plot.

lib/iris/analysis/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ def _lazy_rms(array, axis, **kwargs):
13941394
# all. Thus trying to use this aggregator with weights will currently
13951395
# raise an error in dask due to the unexpected keyword `weights`,
13961396
# rather than silently returning the wrong answer.
1397-
return da.sqrt(da.mean(array ** 2, axis=axis, **kwargs))
1397+
return da.sqrt(da.mean(array**2, axis=axis, **kwargs))
13981398

13991399

14001400
@_build_dask_mdtol_function

lib/iris/analysis/_grid_angles.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _angle(p, q, r):
120120
mid_lons = np.deg2rad(q[0])
121121

122122
pr = _3d_xyz_from_latlon(r[0], r[1]) - _3d_xyz_from_latlon(p[0], p[1])
123-
pr_norm = np.sqrt(np.sum(pr ** 2, axis=0))
123+
pr_norm = np.sqrt(np.sum(pr**2, axis=0))
124124
pr_top = pr[1] * np.cos(mid_lons) - pr[0] * np.sin(mid_lons)
125125

126126
index = pr_norm == 0

lib/iris/analysis/_scipy_interpolate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def compute_interp_weights(self, xi, method=None):
229229
xi_shape, method, indices, norm_distances, out_of_bounds = prepared
230230

231231
# Allocate arrays for describing the sparse matrix.
232-
n_src_values_per_result_value = 2 ** ndim
232+
n_src_values_per_result_value = 2**ndim
233233
n_result_values = len(indices[0])
234234
n_non_zero = n_result_values * n_src_values_per_result_value
235235
weights = np.ones(n_non_zero, dtype=norm_distances[0].dtype)

lib/iris/analysis/calculus.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,10 @@ def curl(i_cube, j_cube, k_cube=None):
629629
# (d/dtheta (i_cube * sin(lat)) - d_j_cube_dphi)
630630
# phi_cmpt = 1/r * ( d/dr (r * j_cube) - d_k_cube_dtheta)
631631
# theta_cmpt = 1/r * ( 1/cos(lat) * d_k_cube_dphi - d/dr (r * i_cube)
632-
if (
633-
y_coord.name()
634-
not in [
635-
"latitude",
636-
"grid_latitude",
637-
]
638-
or x_coord.name() not in ["longitude", "grid_longitude"]
639-
):
632+
if y_coord.name() not in [
633+
"latitude",
634+
"grid_latitude",
635+
] or x_coord.name() not in ["longitude", "grid_longitude"]:
640636
raise ValueError(
641637
"Expecting latitude as the y coord and "
642638
"longitude as the x coord for spherical curl."

lib/iris/analysis/cartography.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _quadrant_area(radian_lat_bounds, radian_lon_bounds, radius_of_earth):
335335
raise ValueError("Bounds must be [n,2] array")
336336

337337
# fill in a new array of areas
338-
radius_sqr = radius_of_earth ** 2
338+
radius_sqr = radius_of_earth**2
339339
radian_lat_64 = radian_lat_bounds.astype(np.float64)
340340
radian_lon_64 = radian_lon_bounds.astype(np.float64)
341341

@@ -1010,8 +1010,8 @@ def _transform_distance_vectors_tolerance_mask(
10101010
# Squared magnitudes should be equal to one within acceptable tolerance.
10111011
# A value of atol=2e-3 is used, which corresponds to a change in magnitude
10121012
# of approximately 0.1%.
1013-
sqmag_1_0 = u_one_t ** 2 + v_zero_t ** 2
1014-
sqmag_0_1 = u_zero_t ** 2 + v_one_t ** 2
1013+
sqmag_1_0 = u_one_t**2 + v_zero_t**2
1014+
sqmag_0_1 = u_zero_t**2 + v_one_t**2
10151015
mask = np.logical_not(
10161016
np.logical_and(
10171017
np.isclose(sqmag_1_0, ones, atol=2e-3),

lib/iris/analysis/maths.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ def power(data, out=None):
540540
return _math_op_common(
541541
cube,
542542
power,
543-
cube.units ** exponent,
543+
cube.units**exponent,
544544
new_dtype=new_dtype,
545545
in_place=in_place,
546546
)

lib/iris/analysis/stats.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ def _ones_like(cube):
168168
covar = (s1 * s2).collapsed(
169169
corr_coords, iris.analysis.SUM, weights=weights_1, mdtol=mdtol
170170
)
171-
var_1 = (s1 ** 2).collapsed(
171+
var_1 = (s1**2).collapsed(
172172
corr_coords, iris.analysis.SUM, weights=weights_1
173173
)
174-
var_2 = (s2 ** 2).collapsed(
174+
var_2 = (s2**2).collapsed(
175175
corr_coords, iris.analysis.SUM, weights=weights_2
176176
)
177177

lib/iris/fileformats/netcdf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2738,9 +2738,9 @@ def _create_cf_data_variable(
27382738
cmin, cmax = _co_realise_lazy_arrays([cmin, cmax])
27392739
n = dtype.itemsize * 8
27402740
if masked:
2741-
scale_factor = (cmax - cmin) / (2 ** n - 2)
2741+
scale_factor = (cmax - cmin) / (2**n - 2)
27422742
else:
2743-
scale_factor = (cmax - cmin) / (2 ** n - 1)
2743+
scale_factor = (cmax - cmin) / (2**n - 1)
27442744
if dtype.kind == "u":
27452745
add_offset = cmin
27462746
elif dtype.kind == "i":

lib/iris/fileformats/pp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def _calculate_str_value_from_value(self):
403403

404404
def _calculate_value_from_str_value(self):
405405
self._value = np.sum(
406-
[10 ** i * val for i, val in enumerate(self._strvalue)]
406+
[10**i * val for i, val in enumerate(self._strvalue)]
407407
)
408408

409409
def __len__(self):
@@ -418,7 +418,7 @@ def __getitem__(self, key):
418418
# if the key returns a list of values, then combine them together
419419
# to an integer
420420
if isinstance(val, list):
421-
val = sum([10 ** i * val for i, val in enumerate(val)])
421+
val = sum([10**i * val for i, val in enumerate(val)])
422422

423423
return val
424424

lib/iris/tests/integration/test_netcdf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def setUp(self):
416416
levels.units = "centimeters"
417417
levels.positive = "down"
418418
levels.axis = "Z"
419-
levels[:] = np.linspace(0, 10 ** 5, 3)
419+
levels[:] = np.linspace(0, 10**5, 3)
420420

421421
volcello.id = "volcello"
422422
volcello.out_name = "volcello"
@@ -507,9 +507,9 @@ def _get_scale_factor_add_offset(cube, datatype):
507507
else:
508508
masked = False
509509
if masked:
510-
scale_factor = (cmax - cmin) / (2 ** n - 2)
510+
scale_factor = (cmax - cmin) / (2**n - 2)
511511
else:
512-
scale_factor = (cmax - cmin) / (2 ** n - 1)
512+
scale_factor = (cmax - cmin) / (2**n - 1)
513513
if dt.kind == "u":
514514
add_offset = cmin
515515
elif dt.kind == "i":

lib/iris/tests/test_basic_maths.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_apply_ufunc(self):
249249
np.square,
250250
a,
251251
new_name="squared temperature",
252-
new_unit=a.units ** 2,
252+
new_unit=a.units**2,
253253
in_place=False,
254254
)
255255
self.assertCMLApproxData(a, ("analysis", "apply_ufunc_original.cml"))
@@ -259,14 +259,14 @@ def test_apply_ufunc(self):
259259
np.square,
260260
a,
261261
new_name="squared temperature",
262-
new_unit=a.units ** 2,
262+
new_unit=a.units**2,
263263
in_place=True,
264264
)
265265
self.assertCMLApproxData(b, ("analysis", "apply_ufunc.cml"))
266266
self.assertCMLApproxData(a, ("analysis", "apply_ufunc.cml"))
267267

268268
def vec_mag(u, v):
269-
return math.sqrt(u ** 2 + v ** 2)
269+
return math.sqrt(u**2 + v**2)
270270

271271
c = a.copy() + 2
272272

@@ -295,7 +295,7 @@ def test_apply_ufunc_fail(self):
295295
def test_ifunc(self):
296296
a = self.cube
297297

298-
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units ** 2)
298+
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units**2)
299299
b = my_ifunc(a, new_name="squared temperature", in_place=False)
300300

301301
self.assertCMLApproxData(a, ("analysis", "apply_ifunc_original.cml"))
@@ -307,7 +307,7 @@ def test_ifunc(self):
307307
self.assertCMLApproxData(a, ("analysis", "apply_ifunc.cml"))
308308

309309
def vec_mag(u, v):
310-
return math.sqrt(u ** 2 + v ** 2)
310+
return math.sqrt(u**2 + v**2)
311311

312312
c = a.copy() + 2
313313

@@ -347,7 +347,7 @@ def test_ifunc_init_fail(self):
347347
def test_ifunc_call_fail(self):
348348
a = self.cube
349349

350-
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units ** 2)
350+
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda a: a.units**2)
351351

352352
# should now NOT fail because giving 2 arguments to an ifunc that
353353
# expects only one will now ignore the surplus argument and raise
@@ -367,7 +367,7 @@ def test_ifunc_call_fail(self):
367367
my_ifunc(a)
368368

369369
my_ifunc = iris.analysis.maths.IFunc(
370-
lambda a: (a, a ** 2.0), lambda cube: cf_units.Unit("1")
370+
lambda a: (a, a**2.0), lambda cube: cf_units.Unit("1")
371371
)
372372

373373
# should fail because data function returns a tuple
@@ -553,9 +553,9 @@ def test_square_root(self):
553553
a.data = abs(a.data)
554554
a.units **= 2
555555

556-
e = a ** 0.5
556+
e = a**0.5
557557

558-
self.assertArrayAllClose(e.data, a.data ** 0.5)
558+
self.assertArrayAllClose(e.data, a.data**0.5)
559559
self.assertCML(e, ("analysis", "sqrt.cml"), checksum=False)
560560
self.assertRaises(ValueError, iris.analysis.maths.exponentiate, a, 0.3)
561561

@@ -585,26 +585,26 @@ def test_apply_ufunc(self):
585585
np.square,
586586
a,
587587
new_name="more_thingness",
588-
new_unit=a.units ** 2,
588+
new_unit=a.units**2,
589589
in_place=False,
590590
)
591591

592-
ans = a.data ** 2
592+
ans = a.data**2
593593

594594
self.assertArrayEqual(b.data, ans)
595595
self.assertEqual(b.name(), "more_thingness")
596596
self.assertEqual(b.units, cf_units.Unit("m^2"))
597597

598598
def vec_mag(u, v):
599-
return math.sqrt(u ** 2 + v ** 2)
599+
return math.sqrt(u**2 + v**2)
600600

601601
c = a.copy() + 2
602602

603603
vec_mag_ufunc = np.frompyfunc(vec_mag, 2, 1)
604604
b = iris.analysis.maths.apply_ufunc(vec_mag_ufunc, a, c)
605605

606-
ans = a.data ** 2 + c.data ** 2
607-
b2 = b ** 2
606+
ans = a.data**2 + c.data**2
607+
b2 = b**2
608608

609609
self.assertArrayAlmostEqual(b2.data, ans)
610610

@@ -617,17 +617,17 @@ def test_ifunc(self):
617617
a = self.cube
618618
a.units = cf_units.Unit("meters")
619619

620-
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda x: x.units ** 2)
620+
my_ifunc = iris.analysis.maths.IFunc(np.square, lambda x: x.units**2)
621621
b = my_ifunc(a, new_name="more_thingness", in_place=False)
622622

623-
ans = a.data ** 2
623+
ans = a.data**2
624624

625625
self.assertArrayEqual(b.data, ans)
626626
self.assertEqual(b.name(), "more_thingness")
627627
self.assertEqual(b.units, cf_units.Unit("m^2"))
628628

629629
def vec_mag(u, v):
630-
return math.sqrt(u ** 2 + v ** 2)
630+
return math.sqrt(u**2 + v**2)
631631

632632
c = a.copy() + 2
633633

@@ -637,12 +637,12 @@ def vec_mag(u, v):
637637
)
638638
b = my_ifunc(a, c)
639639

640-
ans = (a.data ** 2 + c.data ** 2) ** 0.5
640+
ans = (a.data**2 + c.data**2) ** 0.5
641641

642642
self.assertArrayAlmostEqual(b.data, ans)
643643

644644
def vec_mag_data_func(u_data, v_data):
645-
return np.sqrt(u_data ** 2 + v_data ** 2)
645+
return np.sqrt(u_data**2 + v_data**2)
646646

647647
vec_mag_ifunc = iris.analysis.maths.IFunc(
648648
vec_mag_data_func, lambda a, b: (a + b).units

lib/iris/tests/unit/analysis/cartography/test_rotate_winds.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ def test_orig_coords(self):
343343
def test_magnitude_preservation(self):
344344
u, v = self._uv_cubes_limited_extent()
345345
ut, vt = rotate_winds(u, v, iris.coord_systems.OSGB())
346-
orig_sq_mag = u.data ** 2 + v.data ** 2
347-
res_sq_mag = ut.data ** 2 + vt.data ** 2
346+
orig_sq_mag = u.data**2 + v.data**2
347+
res_sq_mag = ut.data**2 + vt.data**2
348348
self.assertArrayAllClose(orig_sq_mag, res_sq_mag, rtol=5e-4)
349349

350350
def test_data_values(self):
@@ -437,9 +437,9 @@ def test_rotated_to_osgb(self):
437437
self.assertArrayEqual(expected_mask, vt.data.mask)
438438

439439
# Check unmasked values have sufficiently small error in mag.
440-
expected_mag = np.sqrt(u.data ** 2 + v.data ** 2)
440+
expected_mag = np.sqrt(u.data**2 + v.data**2)
441441
# Use underlying data to ignore mask in calculation.
442-
res_mag = np.sqrt(ut.data.data ** 2 + vt.data.data ** 2)
442+
res_mag = np.sqrt(ut.data.data**2 + vt.data.data**2)
443443
# Calculate percentage error (note there are no zero magnitudes
444444
# so we can divide safely).
445445
anom = 100.0 * np.abs(res_mag - expected_mag) / expected_mag

lib/iris/tests/unit/analysis/regrid/test_RectilinearRegridder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def setUp(self):
3333
self.xs, self.ys = np.meshgrid(self.x.points, self.y.points)
3434

3535
def transformation(x, y):
36-
return x + y ** 2
36+
return x + y**2
3737

3838
# Construct a function which adds dimensions to the 2D data array
3939
# so that we can test higher dimensional functionality.

lib/iris/tests/unit/coord_categorisation/test_add_categorised_coord.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_vectorise_call(self):
3636
# The reason we use numpy.vectorize is to support multi-dimensional
3737
# coordinate points.
3838
def fn(coord, v):
39-
return v ** 2
39+
return v**2
4040

4141
with mock.patch(
4242
"numpy.vectorize", return_value=self.vectorised

0 commit comments

Comments
 (0)