From 46c0a29d2fc54ca628e241f6f398cd733e1fba2c Mon Sep 17 00:00:00 2001 From: Jonas Hoersch Date: Tue, 19 Dec 2017 00:21:18 +0100 Subject: [PATCH] io: import_components_from_dataframe preserves types of foreign columns Fixes #27. --- pypsa/io.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pypsa/io.py b/pypsa/io.py index 06ec9bb73..5ae00909a 100644 --- a/pypsa/io.py +++ b/pypsa/io.py @@ -620,7 +620,10 @@ def import_components_from_dataframe(network, dataframe, cls_name): cls_name, missing) non_static_attrs_in_df = non_static_attrs.index.intersection(dataframe.columns) - new_df = pd.concat((network.df(cls_name), dataframe.drop(non_static_attrs_in_df, axis=1))) + old_df = network.df(cls_name) + new_df = dataframe.drop(non_static_attrs_in_df, axis=1) + if not old_df.empty: + new_df = pd.concat((old_df, new_df)) if not new_df.index.is_unique: logger.error("Error, new components for {} are not unique".format(cls_name))