Merge pull request #252 from PyPSA/gpd-version-check

use packaging.version instead of deprecated distutils.StrictVersion
This commit is contained in:
Fabian Neumann 2022-07-25 15:10:46 +02:00 committed by GitHub
commit 07296b02e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 7 deletions

View File

@ -5,9 +5,7 @@ import pandas as pd
import geopandas as gpd import geopandas as gpd
from itertools import product from itertools import product
from distutils.version import StrictVersion from packaging.version import Version, parse
gpd_version = StrictVersion(gpd.__version__)
def locate_missing_industrial_sites(df): def locate_missing_industrial_sites(df):
@ -73,7 +71,7 @@ def prepare_hotmaps_database(regions):
gdf = gpd.GeoDataFrame(df, geometry='coordinates', crs="EPSG:4326") gdf = gpd.GeoDataFrame(df, geometry='coordinates', crs="EPSG:4326")
kws = dict(op="within") if gpd_version < '0.10' else dict(predicate="within") kws = dict(op="within") if parse(gpd.__version__) < Version('0.10') else dict(predicate="within")
gdf = gpd.sjoin(gdf, regions, how="inner", **kws) gdf = gpd.sjoin(gdf, regions, how="inner", **kws)
gdf.rename(columns={"index_right": "bus"}, inplace=True) gdf.rename(columns={"index_right": "bus"}, inplace=True)

View File

@ -8,9 +8,8 @@ import geopandas as gpd
from shapely import wkt from shapely import wkt
from pypsa.geo import haversine_pts from pypsa.geo import haversine_pts
from distutils.version import StrictVersion from packaging.version import Version, parse
gpd_version = StrictVersion(gpd.__version__)
def concat_gdf(gdf_list, crs='EPSG:4326'): def concat_gdf(gdf_list, crs='EPSG:4326'):
"""Concatenate multiple geopandas dataframes with common coordinate reference system (crs).""" """Concatenate multiple geopandas dataframes with common coordinate reference system (crs)."""
@ -34,7 +33,7 @@ def build_clustered_gas_network(df, bus_regions, length_factor=1.25):
gdf = gpd.GeoDataFrame(geometry=df[f"point{i}"], crs="EPSG:4326") gdf = gpd.GeoDataFrame(geometry=df[f"point{i}"], crs="EPSG:4326")
kws = dict(op="within") if gpd_version < '0.10' else dict(predicate="within") kws = dict(op="within") if parse(gpd.__version__) < Version('0.10') else dict(predicate="within")
bus_mapping = gpd.sjoin(gdf, bus_regions, how="left", **kws).index_right bus_mapping = gpd.sjoin(gdf, bus_regions, how="left", **kws).index_right
bus_mapping = bus_mapping.groupby(bus_mapping.index).first() bus_mapping = bus_mapping.groupby(bus_mapping.index).first()