e2nIEE / pandapower

Convenient Power System Modelling and Analysis based on PYPOWER and pandas
https://www.pandapower.org
Other
847 stars 478 forks source link

Error while saving to excel #937

Open Davere opened 4 years ago

Davere commented 4 years ago

Hi, recently updated to the newest pp Version and now I have problems saving to excel with geodata.

The Error code is: File "C:/Users/name/Documents/scripte/multi_layer_opf/real_grid_opf.py", line 679, in pp.to_excel(net, "C:/Users/name/Documents/OPF/try" + ".xlsx") File "C:\Users\name\AppData\Local\Continuum\anaconda3\lib\site-packages\pandapower\file_io.py", line 70, in to_excel include_empty_tables=include_empty_tables) File "C:\Users\name\AppData\Local\Continuum\anaconda3\lib\site-packages\pandapower\io_utils.py", line 116, in to_dict_of_dfs geo = coords_to_df(value, geotype="bus") File "C:\Users\name\AppData\Local\Continuum\anaconda3\lib\site-packages\pandapower\io_utils.py", line 63, in coords_to_df k = max(len(v) for v in value.coords.values) File "C:\Users\name\AppData\Local\Continuum\anaconda3\lib\site-packages\pandapower\io_utils.py", line 63, in k = max(len(v) for v in value.coords.values) TypeError: object of type 'NoneType' has no len()

Process finished with exit code 1

The problem comes from buses, which have no coords. The default value is None and so line 63 in pandapower\io_utils.py is trying to get len(None). I got it working for me with adding an if statement and setting the len for not list elements to 0: k = max(len(v) if isinstance(v,list) else 0 for v in value.coords.values)

I also used a newly created grid to test this and altough the default parameter is None for coords is the result for buses without this parameter coords = nan, which results in an error in pandapower\io_utils.py line 69, where only None is continued in the for loop.

Here the grid creation example: import pandapower as pp net = pp.create_empty_network("test") coords = list([(1,2),(4,5)]) pp.create_bus(net,0.4, index = 1, geodata=[1,2], coords=[coords]) pp.create_bus(net,0.4, index = 2, geodata=[1,7]) pp.create_bus(net,0.4, index = 3, geodata=[1,7]) pp.create_bus(net,0.4, index = 4, geodata=[1,7])

rbolgaryn commented 3 years ago

Hi @Davere ,

thank you for the provided test example, we will take a look at the issue.

Roman