12
12
import numpy
13
13
import pandas as pd
14
14
from packaging .version import Version
15
- from packaging import version
16
15
import sys
17
16
try :
18
17
import xlsxwriter
25
24
except ImportError :
26
25
openpyxl_INSTALLED = False
27
26
27
+ from pandapower ._version import __version__ as pp_version
28
28
from pandapower .auxiliary import soft_dependency_error , _preserve_dtypes
29
29
from pandapower .auxiliary import pandapowerNet
30
30
from pandapower .std_types import basic_std_types
@@ -101,7 +101,7 @@ def to_excel(net, filename, include_empty_tables=False, include_results=True):
101
101
writer ._save ()
102
102
103
103
104
- def to_json (net , filename = None , encryption_key = None , store_index_names = False ):
104
+ def to_json (net , filename = None , encryption_key = None , store_index_names = None ):
105
105
"""
106
106
Saves a pandapower Network in JSON format. The index columns of all pandas DataFrames will
107
107
be saved in ascending order. net elements which name begins with "_" (internal elements)
@@ -116,38 +116,23 @@ def to_json(net, filename=None, encryption_key=None, store_index_names=False):
116
116
**encrytion_key** (string, None) - If given, the pandapower network is stored as an
117
117
encrypted json string
118
118
119
- **store_index_names** (bool, False) - If True, an additional dict "index_names" is
120
- stored into the json string which includes the index names of the dataframes within the
121
- net.
122
- Since pandapower does usually not use net[elm].index.name, the default is False.
123
-
124
-
125
119
EXAMPLE:
126
120
127
121
>>> pp.to_json(net, "example.json")
128
122
129
123
"""
130
124
# --- store index names
131
- if store_index_names :
132
- # To ensure correct index names (see https://github.com/e2nIEE/pandapower/issues/1410),
133
- # these are additionally stored to the json file as a dict.
134
- if "index_names" in net .keys ():
135
- raise ValueError ("To store DataFrame index names, 'index_names' "
136
- "is used and thus should not be a key of net." )
137
- net ["index_names" ] = {
138
- key : net [key ].index .name for key in net .keys () if isinstance (
139
- net [key ], pd .DataFrame ) and isinstance (net [key ].index .name , str ) and \
140
- net [key ].index .name != ""
141
- }
125
+ if store_index_names is not None :
126
+ msg = "The input parameter 'store_index_names' of function 'to_json()' is deprecated."
127
+ if Version (pp_version ) < Version ("2.15" ):
128
+ warn (msg )
129
+ else :
130
+ raise DeprecationWarning (msg )
142
131
143
132
json_string = json .dumps (net , cls = io_utils .PPJSONEncoder , indent = 2 )
144
133
if encryption_key is not None :
145
134
json_string = io_utils .encrypt_string (json_string , encryption_key )
146
135
147
- if store_index_names :
148
- # remove the key "index_names" to not change net
149
- del net ["index_names" ]
150
-
151
136
if filename is None :
152
137
return json_string
153
138
0 commit comments