diff --git a/climada/engine/calibration_opt.py b/climada/engine/calibration_opt.py index 5f174b5f77..a443f00a09 100644 --- a/climada/engine/calibration_opt.py +++ b/climada/engine/calibration_opt.py @@ -91,7 +91,7 @@ def calib_instance( years_in_common = df_out.loc[ df_out["year"].isin(np.sort(list((iys.keys())))), "year" ] - for cnt_, year in years_in_common.iteritems(): + for cnt_, year in years_in_common.items(): df_out.loc[df_out["year"] == year, "impact_CLIMADA"] = iys[year] else: # impact per event @@ -403,7 +403,7 @@ def calib_all( if df_result is None: df_result = copy.deepcopy(df_out) else: - df_result = df_result.append(df_out, input) + df_result = pd.concat([df_result, df_out], ignore_index=True) return df_result diff --git a/climada/engine/impact_data.py b/climada/engine/impact_data.py index c5e48c21d4..56f16a84ad 100644 --- a/climada/engine/impact_data.py +++ b/climada/engine/impact_data.py @@ -410,7 +410,7 @@ def hit_country_per_hazard(intensity_path, names_path, reg_id_path, date_path): all_hits.append(hits) # create data frame for output - hit_countries = pd.DataFrame(columns=["hit_country", "Date_start", "ibtracsID"]) + hit_countries = [] for track, _ in enumerate(names): # Check if track has hit any country else go to the next track if len(all_hits[track]) > 0: @@ -419,16 +419,17 @@ def hit_country_per_hazard(intensity_path, names_path, reg_id_path, date_path): # Hit country ISO ctry_iso = u_coord.country_to_iso(all_hits[track][hit], "alpha3") # create entry for each country a hazard has hit - hit_countries = hit_countries.append( + hit_countries.append( { "hit_country": ctry_iso, "Date_start": date[track], "ibtracsID": names[track], - }, - ignore_index=True, + } ) # retrun data frame with all hit countries per hazard - return hit_countries + return pd.DataFrame( + hit_countries, columns=["hit_country", "Date_start", "ibtracsID"] + ) def create_lookup(emdat_data, start, end, disaster_subtype="Tropical cyclone"): diff --git a/climada/entity/exposures/litpop/litpop.py b/climada/entity/exposures/litpop/litpop.py index c267d8817e..ef28b3ba5d 100644 --- a/climada/entity/exposures/litpop/litpop.py +++ b/climada/entity/exposures/litpop/litpop.py @@ -632,17 +632,18 @@ def from_shape_and_countries( # works if shape is Polygon or MultiPolygon gdf = exp.gdf.loc[exp.gdf.geometry.within(shape)] elif isinstance(shape, (geopandas.GeoSeries, list)): - gdf = geopandas.GeoDataFrame(columns=exp.gdf.columns) + idx = np.array([False] * exp.gdf.shape[0], dtype=bool) for shp in shape: if isinstance( shp, (shapely.geometry.MultiPolygon, shapely.geometry.Polygon) ): - gdf = gdf.append(exp.gdf.loc[exp.gdf.geometry.within(shp)]) + idx |= exp.gdf.geometry.within(shp) else: raise NotImplementedError( "Not implemented for list or GeoSeries containing " f"objects of type {type(shp)} as `shape`" ) + gdf = exp.gdf.loc[idx] else: raise NotImplementedError( "Not implemented for `shape` of type {type(shape)}" diff --git a/climada/test/test_litpop_integr.py b/climada/test/test_litpop_integr.py index 3403d847c7..912d9c0277 100644 --- a/climada/test/test_litpop_integr.py +++ b/climada/test/test_litpop_integr.py @@ -195,7 +195,7 @@ def test_from_shape_and_countries_zurich_pass(self): with from_shape_and_countries()""" ent = lp.LitPop.from_shape_and_countries( - shape, "Switzerland", res_arcsec=30, reference_year=2016 + [shape, shape], "Switzerland", res_arcsec=30, reference_year=2016 ) self.assertEqual(ent.value.min(), 0.0) self.assertEqual(ent.region_id.min(), 756) @@ -217,6 +217,8 @@ def test_from_shape_and_countries_zurich_pass(self): ], 8.529166666666658, ) + # must be the same as for shape=`shape` or shape=`[shape]` + self.assertEqual(ent.gdf.shape, (1050, 5)) def test_Liechtenstein_15_lit_pass(self): """Create Nightlights entity for Liechtenstein 2016:"""