Skip to content

Commit eb36c3d

Browse files
committed
MNT: Use zip's strict keyword argument available with 3.10
Identified by ruff.
1 parent 695e6a2 commit eb36c3d

26 files changed

+74
-68
lines changed

examples/formats/NEXRAD_Level_2_File.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@
7373
fig = plt.figure(figsize=(15, 8))
7474
add_metpy_logo(fig, 190, 85, size='large')
7575

76-
for var_data, var_range, ax_rect in zip((ref, rho), (ref_range, rho_range), spec):
76+
for var_data, var_range, ax_rect in zip((ref, rho), (ref_range, rho_range), spec,
77+
strict=False):
7778
# Turn into an array, then mask
7879
data = np.ma.array(var_data)
7980
data[np.isnan(data)] = np.ma.masked

examples/formats/NEXRAD_Level_3_File.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
ctables = (('NWSStormClearReflectivity', -20, 0.5), # dBZ
2727
('NWS8bitVel', -100, 1.0)) # m/s
2828

29-
for v, ctable, ax_rect in zip(('N0Q', 'N0U'), ctables, spec):
29+
for v, ctable, ax_rect in zip(('N0Q', 'N0U'), ctables, spec, strict=False):
3030
# Open the file
3131
name = get_test_data(f'nids/KOUN_SDUS54_{v}TLX_201305202016', as_file_obj=False)
3232
f = Level3File(name)

examples/gridding/Inverse_Distance_Verification.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def draw_circle(ax, x, y, r, m, label):
6161
#
6262
# The variable ``indices`` represents the index of each matched coordinate within the
6363
# cKDTree's ``data`` list.
64-
grid_points = np.array(list(zip(sim_gridx, sim_gridy)))
64+
grid_points = np.array(list(zip(sim_gridx, sim_gridy, strict=False)))
6565

6666
radius = 40
67-
obs_tree = cKDTree(list(zip(xp, yp)))
67+
obs_tree = cKDTree(list(zip(xp, yp, strict=False)))
6868
indices = obs_tree.query_ball_point(grid_points, r=radius)
6969

7070
###########################################
@@ -83,7 +83,7 @@ def draw_circle(ax, x, y, r, m, label):
8383
barnes_dist = dist_2(sim_gridx[1], sim_gridy[1], x2, y2)
8484
barnes_obs = zp[indices[1]]
8585

86-
kappa = calc_kappa(average_spacing(list(zip(xp, yp))))
86+
kappa = calc_kappa(average_spacing(list(zip(xp, yp, strict=False))))
8787

8888
barnes_val = barnes_point(barnes_dist, barnes_obs, kappa)
8989

@@ -121,7 +121,7 @@ def draw_circle(ax, x, y, r, m, label):
121121
mx, my = obs_tree.data[indices[0]].T
122122
mz = zp[indices[0]]
123123

124-
for x, y, z in zip(mx, my, mz):
124+
for x, y, z in zip(mx, my, mz, strict=False):
125125
d = np.sqrt((sim_gridx[0] - x)**2 + (y - sim_gridy[0])**2)
126126
ax.plot([sim_gridx[0], x], [sim_gridy[0], y], '--')
127127

@@ -160,7 +160,7 @@ def draw_circle(ax, x, y, r, m, label):
160160
mx, my = obs_tree.data[indices[1]].T
161161
mz = zp[indices[1]]
162162

163-
for x, y, z in zip(mx, my, mz):
163+
for x, y, z in zip(mx, my, mz, strict=False):
164164
d = np.sqrt((sim_gridx[1] - x)**2 + (y - sim_gridy[1])**2)
165165
ax.plot([sim_gridx[1], x], [sim_gridy[1], y], '--')
166166

examples/gridding/Natural_Neighbor_Verification.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
ax.set_title('Triangulation of observations and test grid cell '
9494
'natural neighbor interpolation values')
9595

96-
members, circumcenters = geometry.find_natural_neighbors(tri, list(zip(sim_gridx, sim_gridy)))
96+
members, circumcenters = geometry.find_natural_neighbors(tri, list(zip(sim_gridx, sim_gridy,
97+
strict=False)))
9798

9899
val = natural_neighbor_point(xp, yp, zp, (sim_gridx[0], sim_gridy[0]), tri, members[0],
99100
circumcenters)
@@ -164,7 +165,7 @@ def draw_circle(ax, x, y, r, m, label):
164165
# spatial data structure that we use here simply to show areal ratios.
165166
# Notice that the two natural neighbor triangle circumcenters are also vertices
166167
# in the Voronoi plot (green dots), and the observations are in the polygons (blue dots).
167-
vort = Voronoi(list(zip(xp, yp)))
168+
vort = Voronoi(list(zip(xp, yp, strict=False)))
168169

169170
fig, ax = plt.subplots(1, 1, figsize=(15, 10))
170171
ax.ishold = lambda: True # Work-around for Matplotlib 3.0.0 incompatibility
@@ -175,7 +176,7 @@ def draw_circle(ax, x, y, r, m, label):
175176
x_0 = xp[nn_ind]
176177
y_0 = yp[nn_ind]
177178

178-
for x, y, z in zip(x_0, y_0, z_0):
179+
for x, y, z in zip(x_0, y_0, z_0, strict=False):
179180
ax.annotate(f'{x}, {y}: {z:.3f} F', xy=(x, y))
180181

181182
ax.plot(sim_gridx[0], sim_gridy[0], 'k+', markersize=10)

examples/plots/Plotting_Surface_Analysis.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def plot_bulletin(ax, data):
4444
# Handle H/L points using MetPy's StationPlot class
4545
for field in ('HIGH', 'LOW'):
4646
rows = data[data.feature == field]
47-
x, y = zip(*((pt.x, pt.y) for pt in rows.geometry))
47+
x, y = zip(*((pt.x, pt.y) for pt in rows.geometry), strict=False)
4848
sp = StationPlot(ax, x, y, transform=ccrs.PlateCarree(), clip_on=True)
4949
sp.plot_text('C', [field[0]] * len(x), **complete_style[field])
5050
sp.plot_parameter('S', rows.strength, **complete_style[field])

examples/plots/US_Counties.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
ax2 = fig.add_subplot(1, 3, 2, projection=proj)
2323
ax3 = fig.add_subplot(1, 3, 3, projection=proj)
2424

25-
for scale, axis in zip(['20m', '5m', '500k'], [ax1, ax2, ax3]):
25+
for scale, axis in zip(['20m', '5m', '500k'], [ax1, ax2, ax3], strict=False):
2626
axis.set_extent([270.25, 270.9, 38.15, 38.75], ccrs.Geodetic())
2727
axis.add_feature(USCOUNTIES.with_scale(scale))

src/metpy/calc/basic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ def zoom_xarray(input_field, zoom, output=None, order=3, mode='constant', cval=0
11301130
if not np.iterable(zoom):
11311131
zoom = tuple(zoom for _ in input_field.dims)
11321132
zoomed_dim_coords = {}
1133-
for dim_name, dim_zoom in zip(input_field.dims, zoom):
1133+
for dim_name, dim_zoom in zip(input_field.dims, zoom, strict=False):
11341134
if dim_name in input_field.coords:
11351135
zoomed_dim_coords[dim_name] = scipy_zoom(
11361136
input_field[dim_name].data, dim_zoom, order=order, mode=mode, cval=cval,

src/metpy/calc/kinematics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def advection(
464464

465465
return -sum(
466466
wind * gradient
467-
for wind, gradient in zip(wind_vector.values(), gradient_vector)
467+
for wind, gradient in zip(wind_vector.values(), gradient_vector, strict=False)
468468
)
469469

470470

src/metpy/calc/thermo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ def _wide_option(intersect_type, p_list, t_list, pressure, parcel_temperature_pr
781781
lfc_p_list, _ = find_intersections(pressure, parcel_temperature_profile,
782782
temperature, direction='increasing',
783783
log_x=True)
784-
diff = [lfc_p.m - el_p.m for lfc_p, el_p in zip(lfc_p_list, el_p_list)]
784+
diff = [lfc_p.m - el_p.m for lfc_p, el_p in zip(lfc_p_list, el_p_list, strict=False)]
785785
return (p_list[np.where(diff == np.max(diff))][0],
786786
t_list[np.where(diff == np.max(diff))][0])
787787

src/metpy/interpolate/grid.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def natural_neighbor_to_grid(xp, yp, variable, grid_x, grid_y):
162162
163163
"""
164164
# Handle grid-to-points conversion, and use function from `interpolation`
165-
points_obs = list(zip(xp, yp))
165+
points_obs = list(zip(xp, yp, strict=False))
166166
points_grid = generate_grid_coords(grid_x, grid_y)
167167
img = natural_neighbor_to_points(points_obs, variable, points_grid)
168168
return img.reshape(grid_x.shape)
@@ -214,7 +214,7 @@ def inverse_distance_to_grid(xp, yp, variable, grid_x, grid_y, r, gamma=None, ka
214214
215215
"""
216216
# Handle grid-to-points conversion, and use function from `interpolation`
217-
points_obs = list(zip(xp, yp))
217+
points_obs = list(zip(xp, yp, strict=False))
218218
points_grid = generate_grid_coords(grid_x, grid_y)
219219
img = inverse_distance_to_points(points_obs, variable, points_grid, r, gamma=gamma,
220220
kappa=kappa, min_neighbors=min_neighbors, kind=kind)
@@ -296,7 +296,7 @@ def interpolate_to_grid(x, y, z, interp_type='linear', hres=50000,
296296
grid_x, grid_y = generate_grid(hres, boundary_coords)
297297

298298
# Handle grid-to-points conversion, and use function from `interpolation`
299-
points_obs = np.array(list(zip(x, y)))
299+
points_obs = np.array(list(zip(x, y, strict=False)))
300300
points_grid = generate_grid_coords(grid_x, grid_y)
301301
img = interpolate_to_points(points_obs, z, points_grid, interp_type=interp_type,
302302
minimum_neighbors=minimum_neighbors, gamma=gamma,

src/metpy/interpolate/points.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def cressman_point(sq_dist, values, radius):
4343
weights = tools.cressman_weights(sq_dist, radius)
4444
total_weights = np.sum(weights)
4545

46-
return sum(v * (w / total_weights) for (w, v) in zip(weights, values))
46+
return sum(v * (w / total_weights) for (w, v) in zip(weights, values, strict=False))
4747

4848

4949
def barnes_point(sq_dist, values, kappa, gamma=None):
@@ -82,7 +82,7 @@ def barnes_point(sq_dist, values, kappa, gamma=None):
8282
weights = tools.barnes_weights(sq_dist, kappa, gamma)
8383
total_weights = np.sum(weights)
8484

85-
return sum(v * (w / total_weights) for (w, v) in zip(weights, values))
85+
return sum(v * (w / total_weights) for (w, v) in zip(weights, values, strict=False))
8686

8787

8888
def natural_neighbor_point(xp, yp, variable, grid_loc, tri, neighbors, circumcenters):
@@ -271,7 +271,7 @@ def inverse_distance_to_points(points, values, xi, r, gamma=None, kappa=None, mi
271271

272272
img = np.asarray([interp_func(geometry.dist_2(*grid, *obs_tree.data[matches].T),
273273
values[matches]) if len(matches) >= min_neighbors else np.nan
274-
for matches, grid in zip(indices, xi)])
274+
for matches, grid in zip(indices, xi, strict=False)])
275275

276276
if org_units:
277277
img = units.Quantity(img, org_units)

src/metpy/interpolate/tools.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def remove_repeat_coordinates(x, y, z):
133133
coords = []
134134
variable = []
135135

136-
for (x_, y_, t_) in zip(x, y, z):
136+
for (x_, y_, t_) in zip(x, y, z, strict=False):
137137
if (x_, y_) not in coords:
138138
coords.append((x_, y_))
139139
variable.append(t_)

src/metpy/io/_tools.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(self, info, prefmt='', tuple_name=None):
6464
"""Initialize the NamedStruct."""
6565
if tuple_name is None:
6666
tuple_name = 'NamedStruct'
67-
names, fmts = zip(*info)
67+
names, fmts = zip(*info, strict=False)
6868
self.converters = {}
6969
conv_off = 0
7070
for ind, i in enumerate(info):
@@ -118,7 +118,7 @@ class DictStruct:
118118

119119
def __init__(self, info, prefmt=''):
120120
"""Initialize the DictStruct."""
121-
names, formats = zip(*info)
121+
names, formats = zip(*info, strict=False)
122122

123123
# Remove empty names
124124
self._names = [n for n in names if n]
@@ -131,7 +131,7 @@ def size(self):
131131
return self._struct.size
132132

133133
def _create(self, items):
134-
return dict(zip(self._names, items))
134+
return dict(zip(self._names, items, strict=False))
135135

136136
def unpack(self, s):
137137
"""Parse bytes and return a dict."""
@@ -151,7 +151,7 @@ def __init__(self, *args, **kwargs):
151151
self.val_map = dict(enumerate(args))
152152

153153
# Invert the kwargs dict so that we can map from value to name
154-
self.val_map.update(zip(kwargs.values(), kwargs.keys()))
154+
self.val_map.update(zip(kwargs.values(), kwargs.keys(), strict=False))
155155

156156
def __call__(self, val):
157157
"""Map an integer to the string representation."""

src/metpy/io/gempak.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ def __init__(self, file):
629629
fkey_prod = product(['header_name', 'header_length', 'header_type'],
630630
range(1, self.prod_desc.file_headers + 1))
631631
fkey_names = ['{}{}'.format(*x) for x in fkey_prod]
632-
fkey_info = list(zip(fkey_names, np.repeat(('4s', 'i', 'i'),
633-
self.prod_desc.file_headers)))
632+
fkey_info = list(zip(fkey_names,
633+
np.repeat(('4s', 'i', 'i'), self.prod_desc.file_headers),
634+
strict=False))
634635
self.file_keys_format = NamedStruct(fkey_info, self.prefmt, 'FileKeys')
635636

636637
self._buffer.jump_to(self._start, _word_to_position(self.prod_desc.file_keys_ptr))
@@ -1897,7 +1898,7 @@ def _merge_sounding(self, parts):
18971898
if num_man_levels >= 1:
18981899
for mp, mt, mz in zip(parts['TTAA']['PRES'],
18991900
parts['TTAA']['TEMP'],
1900-
parts['TTAA']['HGHT']):
1901+
parts['TTAA']['HGHT'], strict=False):
19011902
if self.prod_desc.missing_float not in [
19021903
mp,
19031904
mt,

src/metpy/io/gini.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _scaled_int(s):
4949

5050
def _name_lookup(names):
5151
r"""Create an io helper to convert an integer to a named value."""
52-
mapper = dict(zip(range(len(names)), names))
52+
mapper = dict(zip(range(len(names)), names, strict=False))
5353

5454
def lookup(val):
5555
return mapper.get(val, 'UnknownValue')

src/metpy/io/nexrad.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def _decode_msg15(self, msg_hdr):
518518
num_rng = data[offset]
519519
codes = data[offset + 1:offset + 1 + 2 * num_rng:2]
520520
ends = data[offset + 2:offset + 2 + 2 * num_rng:2]
521-
az_data.append(list(zip(ends, codes)))
521+
az_data.append(list(zip(ends, codes, strict=False)))
522522
offset += 2 * num_rng + 1
523523
self.clutter_filter_map['data'].append(az_data)
524524

@@ -1963,7 +1963,7 @@ def _unpack_packet_radial_data(self, code, in_sym_block):
19631963
rads.append((start_az, end_az,
19641964
self._unpack_rle_data(
19651965
self._buffer.read_binary(2 * rad.num_hwords))))
1966-
start, end, vals = zip(*rads)
1966+
start, end, vals = zip(*rads, strict=False)
19671967
return {'start_az': list(start), 'end_az': list(end), 'data': list(vals),
19681968
'center': (hdr.i_center * self.pos_scale(in_sym_block),
19691969
hdr.j_center * self.pos_scale(in_sym_block)),
@@ -1984,7 +1984,7 @@ def _unpack_packet_digital_radial(self, code, in_sym_block):
19841984
start_az = rad.start_angle * 0.1
19851985
end_az = start_az + rad.angle_delta * 0.1
19861986
rads.append((start_az, end_az, self._buffer.read_binary(rad.num_bytes)))
1987-
start, end, vals = zip(*rads)
1987+
start, end, vals = zip(*rads, strict=False)
19881988
return {'start_az': list(start), 'end_az': list(end), 'data': list(vals),
19891989
'center': (hdr.i_center * self.pos_scale(in_sym_block),
19901990
hdr.j_center * self.pos_scale(in_sym_block)),
@@ -2148,7 +2148,7 @@ def _unpack_packet_digital_precipitation(self, code, in_sym_block):
21482148
row = self._unpack_rle_data(row_bytes)
21492149
else:
21502150
row = []
2151-
for run, level in zip(row_bytes[::2], row_bytes[1::2]):
2151+
for run, level in zip(row_bytes[::2], row_bytes[1::2], strict=False):
21522152
row.extend([level] * run)
21532153
assert len(row) == lfm_boxes
21542154
rows.append(row)
@@ -2164,7 +2164,7 @@ def _unpack_packet_linked_vector(self, code, in_sym_block):
21642164
value = None
21652165
scale = self.pos_scale(in_sym_block)
21662166
pos = [b * scale for b in self._buffer.read_binary(num_bytes / 2, '>h')]
2167-
vectors = list(zip(pos[::2], pos[1::2]))
2167+
vectors = list(zip(pos[::2], pos[1::2], strict=False))
21682168
return {'vectors': vectors, 'color': value}
21692169

21702170
def _unpack_packet_vector(self, code, in_sym_block):
@@ -2176,7 +2176,7 @@ def _unpack_packet_vector(self, code, in_sym_block):
21762176
value = None
21772177
scale = self.pos_scale(in_sym_block)
21782178
pos = [p * scale for p in self._buffer.read_binary(num_bytes / 2, '>h')]
2179-
vectors = list(zip(pos[::4], pos[1::4], pos[2::4], pos[3::4]))
2179+
vectors = list(zip(pos[::4], pos[1::4], pos[2::4], pos[3::4], strict=False))
21802180
return {'vectors': vectors, 'color': value}
21812181

21822182
def _unpack_packet_contour_color(self, code, in_sym_block):
@@ -2196,7 +2196,7 @@ def _unpack_packet_linked_contour(self, code, in_sym_block):
21962196
vectors = [(startx, starty)]
21972197
num_bytes = self._buffer.read_int(2, 'big', signed=False)
21982198
pos = [b * scale for b in self._buffer.read_binary(num_bytes / 2, '>h')]
2199-
vectors.extend(zip(pos[::2], pos[1::2]))
2199+
vectors.extend(zip(pos[::2], pos[1::2], strict=False))
22002200
return {'vectors': vectors}
22012201

22022202
def _unpack_packet_wind_barbs(self, code, in_sym_block):

src/metpy/plots/_mpl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def draw(self, renderer):
196196

197197
angle = self.get_rotation()
198198

199-
for (posx, posy), t in zip(pts, self.text):
199+
for (posx, posy), t in zip(pts, self.text, strict=False):
200200
# Skip empty strings--not only is this a performance gain, but it fixes
201201
# rendering with path effects below.
202202
if not t:

src/metpy/plots/declarative.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ def _build(self):
13791379
# The order here needs to match the order of the tuple
13801380
if self.arrowkey is not None:
13811381
key_kwargs = {'U': 100, 'X': 0.85, 'Y': 1.02, 'labelpos': 'E', 'label': ''}
1382-
for name, val in zip(key_kwargs, self.arrowkey):
1382+
for name, val in zip(key_kwargs, self.arrowkey, strict=False):
13831383
if val is not None:
13841384
key_kwargs[name] = val
13851385
self.parent.ax.quiverkey(self.handle, labelcolor=self.color, **key_kwargs)
@@ -2247,7 +2247,7 @@ def _build(self):
22472247
# Each Shapely object is plotted separately with its corresponding strength
22482248
# and customizable parameters
22492249
for geo_obj, strengthvalues, feature in zip(
2250-
self.geometry, strengths, self.feature):
2250+
self.geometry, strengths, self.feature, strict=True):
22512251
kwargs = self.mpl_args.copy()
22522252
# Plot the Shapely object with the appropriate method and style
22532253
if isinstance(geo_obj, (LineString)):

0 commit comments

Comments
 (0)