1
1
import geopandas
2
2
import maup
3
3
from maup .repair import count_overlaps , autorepair , quick_repair
4
+ from maup .assign import AssigmentWarning
4
5
import pytest
5
6
6
7
# These tests are losely based off the test_example_case in test_prorate.py
@@ -66,7 +67,13 @@ def test_crop_to():
66
67
67
68
# Calculate without cropping
68
69
pieces = maup .intersections (old_precincts , new_precincts , area_cutoff = 0 )
69
- weights = blocks ["TOTPOP" ].groupby (maup .assign (blocks , pieces )).sum ()
70
+
71
+ with pytest .warns (
72
+ AssigmentWarning , match = "Some units in the source geometry were unassigned."
73
+ ):
74
+ # Weight by prorated population from blocks
75
+ weights = blocks ["TOTPOP" ].groupby (maup .assign (blocks , pieces )).sum ()
76
+
70
77
weights = maup .normalize (weights , level = 0 )
71
78
new_precincts [columns ] = maup .prorate (
72
79
pieces , old_precincts [columns ], weights = weights
@@ -76,7 +83,13 @@ def test_crop_to():
76
83
old_precincts ["geometries" ] = maup .crop_to (old_precincts , new_precincts )
77
84
new_precincts_cropped = new_precincts .copy ()
78
85
pieces = maup .intersections (old_precincts , new_precincts_cropped , area_cutoff = 0 )
79
- weights = blocks ["TOTPOP" ].groupby (maup .assign (blocks , pieces )).sum ()
86
+
87
+ with pytest .warns (
88
+ AssigmentWarning , match = "Some units in the source geometry were unassigned."
89
+ ):
90
+ # Weight by prorated population from blocks
91
+ weights = blocks ["TOTPOP" ].groupby (maup .assign (blocks , pieces )).sum ()
92
+
80
93
weights = maup .normalize (weights , level = 0 )
81
94
new_precincts_cropped [columns ] = maup .prorate (
82
95
pieces , old_precincts [columns ], weights = weights
0 commit comments