Skip to content

Commit d6d2859

Browse files
fixing geodataframe issues
1 parent 5988922 commit d6d2859

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

climada/entity/exposures/test/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_error_geometry_fail(self):
280280
"""Wrong exposures definition"""
281281
expo = good_exposures()
282282
expo.set_geometry_points()
283-
expo.gdf.latitude.values[0] = 5
283+
expo.gdf.loc[0, 'latitude'] = 5
284284

285285
with self.assertRaises(ValueError):
286286
expo.check()

climada/util/coordinates.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,18 +2743,20 @@ def apply_point(df_exp):
27432743
return df_exp.apply(lambda row: Point(row.longitude, row.latitude), axis=1)
27442744

27452745
ddata = dd.from_pandas(df_val, npartitions=cpu_count())
2746-
df_val['geometry'] = ddata.map_partitions(
2746+
df_val['_-geometry-prov'] = ddata.map_partitions(
27472747
apply_point,
27482748
meta=('geometry', gpd.array.GeometryDtype)
27492749
).compute(scheduler=scheduler)
2750+
27502751
# single process
27512752
else:
2752-
df_val['geometry'] = gpd.GeoSeries(
2753-
gpd.points_from_xy(df_val.longitude, df_val.latitude), index=df_val.index, crs=crs)
2753+
df_val['_-geometry-prov'] = gpd.GeoSeries(
2754+
gpd.points_from_xy(df_val.longitude, df_val.latitude),
2755+
index=df_val.index)
27542756

2755-
# set crs
2756-
if crs:
2757-
df_val.set_crs(crs, inplace=True)
2757+
# A 'geometry' column must not be created in a GeoDataFrame except through the constructor
2758+
# or with set_geometry. That's why we first made a temporary columns with a weird name
2759+
df_val.set_geometry('_-geometry-prov', inplace=True, drop=True, crs=crs)
27582760

27592761

27602762
def fao_code_def():

0 commit comments

Comments
 (0)