diff --git a/scripts/build_industrial_distribution_key.py b/scripts/build_industrial_distribution_key.py index 909268ff..835445da 100644 --- a/scripts/build_industrial_distribution_key.py +++ b/scripts/build_industrial_distribution_key.py @@ -5,9 +5,7 @@ import pandas as pd import geopandas as gpd from itertools import product -from distutils.version import StrictVersion - -gpd_version = StrictVersion(gpd.__version__) +from packaging.version import Version, parse def locate_missing_industrial_sites(df): @@ -73,7 +71,7 @@ def prepare_hotmaps_database(regions): 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.rename(columns={"index_right": "bus"}, inplace=True) diff --git a/scripts/cluster_gas_network.py b/scripts/cluster_gas_network.py index 4a74dff1..0169181e 100755 --- a/scripts/cluster_gas_network.py +++ b/scripts/cluster_gas_network.py @@ -8,9 +8,8 @@ import geopandas as gpd from shapely import wkt 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'): """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") - 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 = bus_mapping.groupby(bus_mapping.index).first()