CLIMADA-project / climada_python

Python (3.8+) version of CLIMADA
GNU General Public License v3.0
321 stars 125 forks source link

util.coordinates functions add 'geometry' column to GeoDataFrame #888

Closed emanuel-schmid closed 3 months ago

emanuel-schmid commented 5 months ago

Describe the bug Whenever climada.util.coordinates.points_to_raster or climada.util.coordinates.set_df_geometry_points are executed a warning is raised:

FutureWarning: You are adding a column named 'geometry' to a GeoDataFrame constructed without an active
geometry column. Currently, this automatically sets the active geometry column to 'geometry' but in the
future that will no longer happen.
Instead, either provide geometry to the GeoDataFrame constructor (GeoDataFrame(... geometry=GeoSeries())
or use `set_geometry('geometry')` to explicitly set the active geometry column.

To Reproduce Steps to reproduce the behavior/error:

  1. Create an Exposures object without a proper geometry column.
  2. Run set_geometry_points on it.
  3. Run plot_raster on it.

Code example:

import pandas as pd
from shapely.geometry import Point
from climada.entity.exposures import Exposures

exp = Exposures(data=pd.DataFrame(
    dict(
        latitude = [1,2,3]*3,
        longitude = [1]*3+[2]*3+[3]*3,
        value = range(9)
    )
), crs='EPSG:4326')
exp.set_geometry_points()
exp.plot_raster()

Expected behavior Silent plotting.

Climada Version:

System Information (please complete the following information):

Additional context

emanuel-schmid commented 3 months ago

fixed by #889