Skip to content

Commit 9920a9f

Browse files
authored
fix: compatibility of build_gas_* rules with pyogrio >=0.12.0 (#1955)
* fix: compatibility of build_gas_* rules with pyogrio >=0.12.0 pyogrio >=0.12.0 returns JSON fields directly as dicts/lists, so that loading them again as json fails. refer to https://github.com/geopandas/pyogrio/releases/tag/v0.12.0 . * Update release_notes.rst
1 parent 73fb005 commit 9920a9f

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

doc/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Release Notes
99
Upcoming Release
1010
================
1111

12+
* Fix compatibility of rules `build_gas_input_locations` and `build_gas_network` with pyogrio >=0.12.0 (https://github.com/PyPSA/pypsa-eur/pull/1955).
13+
1214
* Added interactive (html) balance maps `results/maps/interactive/` (https://github.com/PyPSA/pypsa-eur/pull/1935) based on https://docs.pypsa.org/latest/user-guide/plotting/explore/. Settings for interactive maps can be found in `plotting.default.yaml` under `plotting["balance_map_interactive"]`.
1315

1416
* Relocated and modified static (pdf) balance maps to `results/maps/static/` (https://github.com/PyPSA/pypsa-eur/pull/1935) for better organization.

scripts/build_gas_input_locations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
production sites with data from SciGRID_gas and Global Energy Monitor.
77
"""
88

9-
import json
109
import logging
1110

1211
import geopandas as gpd
1312
import pandas as pd
1413

1514
from scripts._helpers import configure_logging, set_scenario_config
15+
from scripts.build_gas_network import unnest_struct
1616
from scripts.cluster_gas_network import load_bus_regions
1717

1818
logger = logging.getLogger(__name__)
1919

2020

2121
def read_scigrid_gas(fn):
2222
df = gpd.read_file(fn)
23-
expanded_param = df.param.apply(json.loads).apply(pd.Series)
23+
expanded_param = unnest_struct(df.param)
2424
df = pd.concat([df, expanded_param], axis=1)
2525
df.drop(["param", "uncertainty", "method"], axis=1, inplace=True)
2626
df = df.loc[:, ~df.columns.duplicated()] # duplicated country_code column

scripts/build_gas_network.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ def diameter_to_capacity(pipe_diameter_mm):
5353
return a3 + m3 * pipe_diameter_mm
5454

5555

56+
def unnest_struct(s):
57+
if isinstance(s.iloc[0], str):
58+
s = s.apply(json.loads)
59+
return s.apply(pd.Series)
60+
61+
5662
def load_dataset(fn):
5763
df = gpd.read_file(fn)
58-
param = df.param.apply(json.loads).apply(pd.Series)
59-
cols = ["diameter_mm", "max_cap_M_m3_per_d"]
60-
method = df.method.apply(json.loads).apply(pd.Series)[cols]
64+
param = unnest_struct(df.param)
65+
method = unnest_struct(df.method)[["diameter_mm", "max_cap_M_m3_per_d"]]
6166
method.columns = method.columns + "_method"
6267
df = pd.concat([df, param, method], axis=1)
6368
to_drop = ["param", "uncertainty", "method", "tags"]

0 commit comments

Comments
 (0)