nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ungarj/mapchete
Pull request #515 (2022-12-16 11:58:17)

adapt to Shapely 2.0


Patch:
diff --git a/mapchete/commons/clip.py b/mapchete/commons/clip.py
index fe44858..1eeee72 100644
--- a/mapchete/commons/clip.py
+++ b/mapchete/commons/clip.py
@@ -40,7 +40,9 @@ def clip_array_with_vector(
         if feature_geom.geom_type == "GeometryCollection":
             # for GeometryCollections apply buffer to every subgeometry
             # and make union
-            buffered_geom = unary_union([g.buffer(clip_buffer) for g in feature_geom])
+            buffered_geom = unary_union(
+                [g.buffer(clip_buffer) for g in feature_geom.geoms]
+            )
         else:
             buffered_geom = feature_geom.buffer(clip_buffer)
         if not buffered_geom.is_empty:
diff --git a/mapchete/io/_misc.py b/mapchete/io/_misc.py
index 2acef79..e28e3aa 100644
--- a/mapchete/io/_misc.py
+++ b/mapchete/io/_misc.py
@@ -122,11 +122,19 @@ def tile_to_zoom_level(tile, dst_pyramid=None, matching_method="gdal", precision
     """
 
     def width_height(bounds):
+        """
+        Determine with and height in destination pyramid CRS.
+
+        Raises a TopologicalError if bounds cannot be reprojected.
+        """
         try:
-            l, b, r, t = reproject_geometry(
+            geom = reproject_geometry(
                 box(*bounds), src_crs=tile.crs, dst_crs=dst_pyramid.crs
-            ).bounds
-        except ValueError:
+            )
+            if geom.is_empty:  # Shapely>=2.0
+                raise ValueError("geometry empty after reprojection")
+            l, b, r, t = geom.bounds
+        except ValueError:  # pragma: no cover
             raise TopologicalError("bounds cannot be translated into target CRS")
         return r - l, t - b
 
diff --git a/requirements.txt b/requirements.txt
index 983af9e..46bc74b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -23,6 +23,6 @@ retry>=0.9.2
 rasterio>1.2.10
 s3fs>=0.5.2
 Shapely>=1.7.1
-tilematrix>=2022.3.0
+tilematrix>=2022.12.0
 tqdm>=4.46.0
 werkzeug>=0.15
\ No newline at end of file


Test patch:
diff --git a/test/test_io.py b/test/test_io.py
index 513143c..73759cc 100644
--- a/test/test_io.py
+++ b/test/test_io.py
@@ -119,6 +119,13 @@ def test_tile_to_zoom_level():
         == 4
     )
 
+
+def test_tile_to_zoom_level_geodetic_from_mercator():
+    tp_merc = BufferedTilePyramid("mercator")
+    tp_geod = BufferedTilePyramid("geodetic")
+    zoom = 9
+    col = 0
+
     # geodetic from mercator
     # at Northern boundary
     # NOTE: using a newer proj version (8.2.0) will yield different results
Repository: ungarj/mapchete
Pull request #647 (2024-09-11 08:56:13)

add MPath.pretty_size()


Patch:
diff --git a/mapchete/cli/mpath.py b/mapchete/cli/mpath.py
index c7f92df..a32cfa4 100644
--- a/mapchete/cli/mpath.py
+++ b/mapchete/cli/mpath.py
@@ -6,7 +6,6 @@ import click
 from mapchete.cli import options
 from mapchete.io import copy
 from mapchete.path import MPath
-from mapchete.pretty import pretty_bytes
 
 opt_recursive = click.option("--recursive", "-r", is_flag=True)
 
@@ -79,9 +78,11 @@ def ls(
                     columns=[
                         "",
                         "",
-                        f"{str(subpath)}/"
-                        if absolute_paths
-                        else f"{subpath.relative_to(path)}/",
+                        (
+                            f"{str(subpath)}/"
+                            if absolute_paths
+                            else f"{subpath.relative_to(path)}/"
+                        ),
                     ],
                     widths=[last_modified_column_width, size_column_width, None],
                     spacing=spacing,
@@ -92,7 +93,7 @@ def ls(
                 _row(
                     columns=[
                         subpath.last_modified().strftime(date_format),
-                        pretty_bytes(subpath.size()),
+                        subpath.pretty_size(),
                         str(subpath) if absolute_paths else subpath.relative_to(path),
                     ],
                     widths=[last_modified_column_width, size_column_width, None],
diff --git a/mapchete/path.py b/mapchete/path.py
index f31d1d3..1d70568 100644
--- a/mapchete/path.py
+++ b/mapchete/path.py
@@ -22,6 +22,7 @@ from rasterio.session import Session as RioSession
 from retry import retry
 
 from mapchete.executor import Executor
+from mapchete.pretty import pretty_bytes
 from mapchete.settings import GDALHTTPOptions, IORetrySettings, mapchete_options
 from mapchete.tile import BufferedTile
 from mapchete.types import MPathLike
@@ -442,6 +443,9 @@ class MPath(os.PathLike):
     def size(self) -> int:
         return self.info().get("size", self.info().get("Size"))
 
+    def pretty_size(self) -> str:
+        return pretty_bytes(self.size())
+
     def last_modified(self) -> datetime:
         # for S3 objects
         last_modified = self.info().get("LastModified")


Test patch:
diff --git a/test/test_path.py b/test/test_path.py
index 2121b63..2a0b769 100644
--- a/test/test_path.py
+++ b/test/test_path.py
@@ -287,6 +287,16 @@ def test_size_remote(path):
     test_size(path)
 
 
+@pytest.mark.parametrize(
+    "path",
+    [
+        lazy_fixture("metadata_json"),
+    ],
+)
+def test_pretty_size(path):
+    assert path.pretty_size()
+
+
 @pytest.mark.parametrize(
     "path",
     [