Skip to content

Commit 12bee08

Browse files
committed
Fix zip calls not being strict
1 parent 0fe1a14 commit 12bee08

File tree

9 files changed

+27
-24
lines changed

9 files changed

+27
-24
lines changed

pyresample/_formatting_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def plot_area_def(area: Union['geom.AreaDefinition', 'geom.SwathDefinition'], #
104104
crs = cartopy.crs.Mercator()
105105
fig, ax = plt.subplots(subplot_kw=dict(projection=crs))
106106

107-
poly = Polygon(list(zip(lx[::-1], ly[::-1]))) # make lat/lon counterclockwise for shapely
107+
poly = Polygon(list(zip(lx[::-1], ly[::-1], strict=True))) # make lat/lon counterclockwise for shapely
108108
ax.add_geometries([poly], crs=cartopy.crs.CRS(area.crs), facecolor="none", edgecolor="red")
109109
bounds = poly.buffer(5).bounds
110110
ax.set_extent([bounds[0], bounds[2], bounds[1], bounds[3]], crs=cartopy.crs.CRS(area.crs))

pyresample/boundary/legacy_boundary.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, *sides):
6767
if len(sides) != 4:
6868
raise ValueError("AreaBoundary expects 4 sides.")
6969
# Retrieve sides
70-
self.sides_lons, self.sides_lats = zip(*sides)
70+
self.sides_lons, self.sides_lats = zip(*sides, strict=True)
7171
self.sides_lons = list(self.sides_lons)
7272
self.sides_lats = list(self.sides_lats)
7373

@@ -82,7 +82,7 @@ def from_lonlat_sides(cls, lon_sides, lat_sides):
8282
np.array([vmn, ..., vm1, vm0]),
8383
np.array([vm0, ... ,v10, v00])]
8484
"""
85-
boundary = cls(*zip(lon_sides, lat_sides))
85+
boundary = cls(*zip(lon_sides, lat_sides, strict=True))
8686
return boundary
8787

8888
def contour(self):
@@ -126,7 +126,7 @@ def __init__(self, area, frequency=1):
126126
"Use the Swath/AreaDefinition 'boundary' method instead!.",
127127
PendingDeprecationWarning, stacklevel=2)
128128
AreaBoundary.__init__(self,
129-
*zip(lons, lats))
129+
*zip(lons, lats, strict=True))
130130

131131
if frequency != 1:
132132
self.decimate(frequency)

pyresample/geometry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def _get_sides(self, coord_fun, vertices_per_side) -> tuple[list[np.ndarray], li
348348
sides_dim1, sides_dim2 = zip(*[(top_dim1.squeeze(), top_dim2.squeeze()),
349349
(right_dim1.squeeze(), right_dim2.squeeze()),
350350
(bottom_dim1.squeeze(), bottom_dim2.squeeze()),
351-
(left_dim1.squeeze(), left_dim2.squeeze())])
351+
(left_dim1.squeeze(), left_dim2.squeeze())],
352+
strict=True)
352353
if hasattr(sides_dim1[0], 'compute') and da is not None:
353354
sides_dim1, sides_dim2 = da.compute(sides_dim1, sides_dim2)
354355
return self._filter_sides_nans(sides_dim1, sides_dim2)
@@ -361,7 +362,7 @@ def _filter_sides_nans(
361362
"""Remove nan and inf values present in each side."""
362363
new_dim1_sides = []
363364
new_dim2_sides = []
364-
for dim1_side, dim2_side in zip(dim1_sides, dim2_sides):
365+
for dim1_side, dim2_side in zip(dim1_sides, dim2_sides, strict=True):
365366
# FIXME: ~(~np.isfinite(dim1_side) | ~np.isfinite(dim1_side))
366367
is_valid_mask = ~(np.isnan(dim1_side) | np.isnan(dim2_side))
367368
if not is_valid_mask.any():

pyresample/resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def crop_source_area(source_geo_def, target_geo_def):
355355
def _enumerate_dst_area_chunks(dst_area, dst_chunks):
356356
"""Enumerate the chunks in function of the dst_area."""
357357
for position, slices in _enumerate_chunk_slices(dst_chunks):
358-
chunk_shape = tuple(chunk[pos] for pos, chunk in zip(position, dst_chunks))
358+
chunk_shape = tuple(chunk[pos] for pos, chunk in zip(position, dst_chunks, strict=True))
359359
target_geo_def = dst_area[slices[-2:]]
360360
block_info = {"num-chunks": [len(chunk) for chunk in dst_chunks],
361361
"chunk-location": position,

pyresample/slicer.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_polygon_to_contain(self):
105105
from shapely.geometry import Polygon
106106

107107
x, y = self.area_to_contain.get_edge_bbox_in_projection_coordinates(10)
108-
poly = Polygon(zip(*self._source_transformer.transform(x, y)))
108+
poly = Polygon(zip(*self._source_transformer.transform(x, y), strict=True))
109109
return poly
110110

111111
def get_slices_from_polygon(self, poly):
@@ -121,7 +121,7 @@ def get_slices_from_polygon(self, poly):
121121
@staticmethod
122122
def _assemble_slices(chunk_slices):
123123
"""Assemble slices to one slice per dimension."""
124-
lines, cols = zip(*chunk_slices)
124+
lines, cols = zip(*chunk_slices, strict=True)
125125
line_slice = slice(min(slc.start for slc in lines), max(slc.stop for slc in lines))
126126
col_slice = slice(min(slc.start for slc in cols), max(slc.stop for slc in cols))
127127
slices = col_slice, line_slice
@@ -132,7 +132,7 @@ def _get_chunk_polygons_for_swath_to_crop(self, swath_to_crop):
132132
from shapely.geometry import Polygon
133133

134134
for (lons, lats), (line_slice, col_slice) in _get_chunk_bboxes_for_swath_to_crop(swath_to_crop):
135-
smaller_poly = Polygon(zip(*self._target_transformer.transform(lons, lats)))
135+
smaller_poly = Polygon(zip(*self._target_transformer.transform(lons, lats), strict=True))
136136
yield (smaller_poly, (line_slice, col_slice))
137137

138138

@@ -176,14 +176,14 @@ def get_polygon_to_contain(self):
176176
if self.area_to_crop.is_geostationary:
177177
x_geos, y_geos = get_geostationary_bounding_box_in_proj_coords(self.area_to_crop, 360)
178178
x_geos, y_geos = self._source_transformer.transform(x_geos, y_geos, direction=TransformDirection.INVERSE)
179-
geos_poly = Polygon(zip(x_geos, y_geos))
180-
poly = Polygon(zip(x, y))
179+
geos_poly = Polygon(zip(x_geos, y_geos, strict=True))
180+
poly = Polygon(zip(x, y, strict=True))
181181
poly = poly.intersection(geos_poly)
182182
if poly.is_empty:
183183
raise IncompatibleAreas("No slice on area.")
184-
x, y = zip(*poly.exterior.coords)
184+
x, y = zip(*poly.exterior.coords, strict=True)
185185

186-
return Polygon(zip(*self._source_transformer.transform(x, y)))
186+
return Polygon(zip(*self._source_transformer.transform(x, y), strict=True))
187187

188188
def get_slices_from_polygon(self, poly_to_contain):
189189
"""Get the slices based on the polygon."""
@@ -201,7 +201,9 @@ def get_slices_from_polygon(self, poly_to_contain):
201201
raise InvalidArea("Invalid area") from err
202202
from shapely.geometry import Polygon
203203

204-
poly_to_crop = Polygon(zip(*self.area_to_crop.get_edge_bbox_in_projection_coordinates(frequency=10)))
204+
poly_to_crop = Polygon(zip(
205+
*self.area_to_crop.get_edge_bbox_in_projection_coordinates(frequency=10),
206+
strict=True))
205207
if not poly_to_crop.intersects(buffered_poly):
206208
raise IncompatibleAreas("Areas not overlapping.")
207209
bounds = self._sanitize_polygon_bounds(bounds)
@@ -238,7 +240,7 @@ def _enumerate_chunk_slices(chunks):
238240
"""Enumerate chunks with slices."""
239241
for position in np.ndindex(tuple(map(len, (chunks)))):
240242
slices = []
241-
for pos, chunk in zip(position, chunks):
243+
for pos, chunk in zip(position, chunks, strict=True):
242244
chunk_size = chunk[pos]
243245
offset = sum(chunk[:pos])
244246
slices.append(slice(offset, offset + chunk_size))

pyresample/spherical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __repr__(self):
229229

230230
def __iter__(self):
231231
"""Get iterator over lon/lat pairs."""
232-
return zip([self.lon, self.lat]).__iter__()
232+
return zip([self.lon, self.lat], strict=True).__iter__()
233233

234234
def plot(self, ax=None,
235235
projection_crs=None,

pyresample/spherical_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _find_union_pair(self, geoms):
8282
return None
8383

8484
for id_, komb_pair in zip(itertools.combinations(geoms.keys(), 2),
85-
itertools.combinations(geoms.values(), 2)):
85+
itertools.combinations(geoms.values(), 2), strict=True):
8686
if self._overlaps(komb_pair[0], komb_pair[1]):
8787
return id_, komb_pair[0].union(komb_pair[1])
8888

pyresample/test/test_boundary/test_legacy_boundary.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def test_creation_from_lonlat_sides(self):
4242
boundary = AreaBoundary.from_lonlat_sides(lon_sides, lat_sides)
4343

4444
# Assert sides coincides
45-
for b_lon, src_lon in zip(boundary.sides_lons, lon_sides):
45+
for b_lon, src_lon in zip(boundary.sides_lons, lon_sides, strict=True):
4646
assert np.allclose(b_lon, src_lon)
4747

48-
for b_lat, src_lat in zip(boundary.sides_lats, lat_sides):
48+
for b_lat, src_lat in zip(boundary.sides_lats, lat_sides, strict=True):
4949
assert np.allclose(b_lat, src_lat)
5050

5151
def test_creation(self):
@@ -61,10 +61,10 @@ def test_creation(self):
6161
boundary = AreaBoundary(*list_sides)
6262

6363
# Assert sides coincides
64-
for b_lon, src_lon in zip(boundary.sides_lons, lon_sides):
64+
for b_lon, src_lon in zip(boundary.sides_lons, lon_sides, strict=True):
6565
assert np.allclose(b_lon, src_lon)
6666

67-
for b_lat, src_lat in zip(boundary.sides_lats, lat_sides):
67+
for b_lat, src_lat in zip(boundary.sides_lats, lat_sides, strict=True):
6868
assert np.allclose(b_lat, src_lat)
6969

7070
def test_number_sides_required(self):

pyresample/test/test_geometry/test_swath_boundary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def _check_bbox_structure_and_values(bbox_lons, bbox_lats):
138138
assert not any(np.isnan(side_lat).any() for side_lat in bbox_lats)
139139
assert len(bbox_lons) == len(bbox_lats)
140140
assert len(bbox_lons) == 4
141-
for side_lons, side_lats in zip(bbox_lons, bbox_lats):
141+
for side_lons, side_lats in zip(bbox_lons, bbox_lats, strict=True):
142142
assert isinstance(side_lons, np.ndarray)
143143
assert isinstance(side_lats, np.ndarray)
144144
assert side_lons.shape == side_lats.shape
@@ -163,7 +163,7 @@ def _is_clockwise(lons, lats):
163163
# https://stackoverflow.com/a/1165943/433202
164164
prev_point = (lons[0], lats[0])
165165
edge_sum = 0
166-
for point in zip(lons[1:], lats[1:]):
166+
for point in zip(lons[1:], lats[1:], strict=True):
167167
xdiff = point[0] - prev_point[0]
168168
ysum = point[1] + prev_point[1]
169169
edge_sum += xdiff * ysum

0 commit comments

Comments
 (0)