Repository: kraina-ai/srai (language: python)

Issue:
Move assert after filtering seeds that aren't empty
https://github.com/srai-lab/srai/blob/8e35488e852eb98f001ca8b3b870488b4e72354b/srai/regionizers/voronoi_regionizer.py#L58-L59


Discussion / hints:

Fix patch:
diff --git a/srai/regionizers/voronoi_regionizer.py b/srai/regionizers/voronoi_regionizer.py
index 9f408cd9..39fff890 100644
--- a/srai/regionizers/voronoi_regionizer.py
+++ b/srai/regionizers/voronoi_regionizer.py
@@ -55,9 +55,6 @@ def __init__(
             ValueError: If provided seeds geodataframe has no crs defined.
 
         """
-        if len(seeds.index) < 4:
-            raise ValueError("Minimum 4 seeds are required.")
-
         seeds_wgs84 = seeds.to_crs(epsg=4326)
         self.region_ids = []
         self.seeds = []
@@ -72,6 +69,9 @@ def __init__(
         if self._check_duplicate_points():
             raise ValueError("Duplicate seeds present.")
 
+        if len(self.seeds) < 4:
+            raise ValueError("Minimum 4 seeds are required.")
+
     def transform(self, gdf: Optional[gpd.GeoDataFrame] = None) -> gpd.GeoDataFrame:
         """
         Regionize a given GeoDataFrame.


Test patch:
diff --git a/tests/regionizers/test_voronoi_regionizer.py b/tests/regionizers/test_voronoi_regionizer.py
index 0833285b..05bee3e7 100644
--- a/tests/regionizers/test_voronoi_regionizer.py
+++ b/tests/regionizers/test_voronoi_regionizer.py
@@ -9,9 +9,9 @@
 from srai.utils import _merge_disjointed_gdf_geometries
 
 
-def test_empty_gdf_value_error(gdf_empty) -> None:  # type: ignore
+def test_empty_gdf_attribute_error(gdf_empty) -> None:  # type: ignore
     """Test checks if empty GeoDataFrames are disallowed."""
-    with pytest.raises(ValueError):
+    with pytest.raises(AttributeError):
         VoronoiRegionizer(seeds=gdf_empty)