File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -273,9 +273,13 @@ def _return_empty(self, save_mat):
273273 Impact or ImpactForecast
274274 Empty impact object with correct array sizes.
275275 """
276+ if isinstance (self .hazard , HazardForecast ):
277+ eai_exp = np .nan * np .ones (self .n_exp_pnt )
278+ aai_agg = np .nan
279+ else :
280+ eai_exp = np .zeros (self .n_exp_pnt )
281+ aai_agg = 0.0
276282 at_event = np .zeros (self .n_events )
277- eai_exp = np .zeros (self .n_exp_pnt )
278- aai_agg = 0.0
279283 if save_mat :
280284 imp_mat = sparse .csr_matrix (
281285 (self .n_events , self .n_exp_pnt ), dtype = np .float64
Original file line number Diff line number Diff line change 5151
5252
5353@pytest .fixture (autouse = True )
54- def exposure_fixture ():
55- n_exp = 50
54+ def exposure_fixture (n_exp = 50 ):
5655 lats = np .linspace (- 10 , 10 , n_exp )
5756 lons = np .linspace (- 10 , 10 , n_exp )
5857 data = gpd .GeoDataFrame (
@@ -749,6 +748,15 @@ def test_impact_forecast_blocked_nonsense_attrs(
749748 assert np .all (np .isnan (impact .eai_exp ))
750749 assert impact .eai_exp .shape == (len (exposure_fixture .gdf ),)
751750
751+ # test that aai_agg and eai_exp are also nan when 0-size exp
752+ empty_exp = exposure_fixture (n_exp = 0 )
753+ impact_empty = ImpactCalc (
754+ exposure_fixture , impact_func_set_fixture , hazard_forecast_fixture
755+ ).impact (assign_centroids = True , save_mat = True )
756+ assert np .isnan (impact_empty .aai_agg )
757+ assert np .all (np .isnan (impact_empty .eai_exp ))
758+ assert impact_empty .eai_exp .shape == (len (empty_exp .gdf ),)
759+
752760
753761class TestImpactMatrixCalc (unittest .TestCase ):
754762 """Verify the computation of the impact matrix"""
You can’t perform that action at this time.
0 commit comments