Skip to content

Commit

Permalink
Merge pull request #613 from SteffenMeinecke/develop
Browse files Browse the repository at this point in the history
close #606 - add feature saving and loading nets with a profiles dict
  • Loading branch information
SteffenMeinecke authored Jan 16, 2020
2 parents 77c8d9d + 2e16a9c commit 56a1cf7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pandapower/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def from_excel(filename, convert=True):
INPUT:
**filename** (string) - The absolute or relative path to the input file.
**convert** (bool, True) - If True, converts the format of the net loaded from excel from
the older version of pandapower to the newer version format
**convert** (bool, True) - If True, converts the format of the net loaded from excel from
the older version of pandapower to the newer version format
OUTPUT:
**net** (dict) - The pandapower format network
Expand Down Expand Up @@ -296,7 +296,7 @@ def from_json(filename, convert=True):
INPUT:
**filename** (string or file) - The absolute or relative path to the input file or file-like object
**convert** (bool, True) - If True, converts the format of the net loaded from json from the older
**convert** (bool, True) - If True, converts the format of the net loaded from json from the older
version of pandapower to the newer version format
OUTPUT:
Expand Down
22 changes: 16 additions & 6 deletions pandapower/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def to_dict_of_dfs(net, include_results=False, fallback_to_pickle=True, include_
if net.std_types[t]: # avoid empty excel sheets for std_types if empty
dodfs["%s_std_types" % t] = pd.DataFrame(net.std_types[t]).T
continue
elif item == "profiles":
for t in net.profiles.keys(): # which could be e.g. "sgen", "gen", "load", ...
if net.profiles[t].shape[0]: # avoid empty excel sheets for std_types if empty
dodfs["%s_profiles" % t] = pd.DataFrame(net.profiles[t])
continue
elif item == "user_pf_options":
if len(value) > 0:
dodfs["user_pf_options"] = pd.DataFrame(value, index=[0])
Expand Down Expand Up @@ -112,7 +117,7 @@ def to_dict_of_dfs(net, include_results=False, fallback_to_pickle=True, include_
dodfs[item] = geo
else:
dodfs[item] = value
# save dtypes
# save dtypes
for column, dtype in value.dtypes.iteritems():
dtypes.append((item, column, str(dtype)))
dodfs["dtypes"] = pd.DataFrame(dtypes, columns=["element", "column", "dtype"])
Expand Down Expand Up @@ -166,6 +171,11 @@ def from_dict_of_dfs(dodfs):
elif item.endswith("_std_types"):
net["std_types"][item[:-10]] = table.T.to_dict()
continue # don't go into try..except
elif item.endswith("_profiles"):
if "profiles" not in net.keys():
net["profiles"] = dict()
net["profiles"][item[:-9]] = table
continue # don't go into try..except
elif item == "user_pf_options":
net['user_pf_options'] = {c: v for c, v in zip(table.columns, table.values[0])}
continue # don't go into try..except
Expand Down Expand Up @@ -402,16 +412,16 @@ def check_equality(obj1, obj2):
elif not isinstance(obj2, type(obj1)):
raise UnequalityFound
elif isinstance(obj1, pandapowerNet):
pass
pass
elif isinstance(obj1, pd.DataFrame):
if len(obj1) > 0:
try:
try:
assert_frame_equal(obj1, obj2)
except:
raise UnequalityFound
elif isinstance(obj2, pd.Series):
if len(obj1) > 0:
try:
try:
assert_series_equal(obj1, obj2)
except:
raise UnequalityFound
Expand All @@ -427,7 +437,7 @@ def check_equality(obj1, obj2):
raise UnequalityFound
except:
raise UnequalityFound

def check_dictionary_equality(obj1, obj2):
if set(obj1.keys()) != set(obj2.keys()):
raise UnequalityFound
Expand All @@ -438,7 +448,7 @@ def check_dictionary_equality(obj1, obj2):
def check_callable_equality(obj1, obj2):
if str(obj1) != str(obj2):
raise UnequalityFound

if isinstance(other, self.__class__):
try:
check_equality(self.__dict__, other.__dict__)
Expand Down

0 comments on commit 56a1cf7

Please sign in to comment.