@@ -95,16 +95,37 @@ def test_from_hazard(lead_time, member, hazard, haz_kwargs):
9595 assert_hazard_kwargs (haz_fc_from_haz , ** haz_kwargs )
9696
9797
98- @pytest .mark .skip ("Concat from base class does not work" )
99- def test_hazard_forecast_concat (haz_fc , lead_time , member ):
100- haz_fc1 = haz_fc .select (event_id = [1 , 2 ])
101- haz_fc2 = haz_fc .select (event_id = [3 , 4 ])
102- haz_fc_concat = HazardForecast .concat ([haz_fc1 , haz_fc2 ])
103- assert isinstance (haz_fc_concat , HazardForecast )
104- npt .assert_array_equal (
105- haz_fc_concat .lead_time , np .concatenate ([lead_time , lead_time ])
106- )
107- npt .assert_array_equal (haz_fc_concat .member , np .concatenate ([member , member ]))
98+ class TestHazardForecastConcat :
99+
100+ def test_concat (self , haz_fc , lead_time , member , haz_kwargs ):
101+ haz_fc1 = haz_fc .select (event_id = [3 ])
102+ haz_fc2 = HazardForecast (
103+ haz_type = haz_kwargs ["haz_type" ], frequency_unit = haz_kwargs ["frequency_unit" ]
104+ ) # Empty hazard
105+ haz_fc3 = haz_fc .select (event_id = [1 , 2 ])
106+ haz_fc_concat = HazardForecast .concat ([haz_fc1 , haz_fc2 , haz_fc3 ])
107+ assert isinstance (haz_fc_concat , HazardForecast )
108+ assert haz_fc_concat .size == 3
109+ npt .assert_array_equal (
110+ haz_fc_concat .lead_time , np .concatenate ((lead_time [2 :3 ], lead_time [0 :2 ]))
111+ )
112+ npt .assert_array_equal (
113+ haz_fc_concat .member , np .concatenate ((member [2 :3 ], member [0 :2 ]))
114+ )
115+ npt .assert_array_equal (haz_fc_concat .event_id , [3 , 1 , 2 ])
116+
117+ def test_empty_list (self ):
118+ haz_concat = HazardForecast .concat ([])
119+ assert isinstance (haz_concat , HazardForecast )
120+ assert haz_concat .size == 0
121+ npt .assert_array_equal (haz_concat .lead_time , [])
122+ npt .assert_array_equal (haz_concat .event_id , [])
123+
124+ def test_type_fail (self , haz_fc , hazard ):
125+ with pytest .raises (TypeError , match = "different classes" ):
126+ HazardForecast .concat ([haz_fc , hazard ])
127+ with pytest .raises (TypeError , match = "different classes" ):
128+ Hazard .concat ([haz_fc , hazard ])
108129
109130
110131class TestSelect :
0 commit comments