Skip to content

Commit

Permalink
io: import_components_from_dataframe preserves types of foreign columns
Browse files Browse the repository at this point in the history
Fixes PyPSA#27.
  • Loading branch information
coroa committed Dec 18, 2017
1 parent 352598b commit 46c0a29
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pypsa/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 46c0a29

Please sign in to comment.