Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in network clustering: cannot insert bus1_s, already exists #531

Closed
1 task done
davide-f opened this issue Jan 2, 2023 · 1 comment · Fixed by #599
Closed
1 task done

Bug in network clustering: cannot insert bus1_s, already exists #531

davide-f opened this issue Jan 2, 2023 · 1 comment · Fixed by #599
Labels

Comments

@davide-f
Copy link

davide-f commented Jan 2, 2023

Checklist

  • I am using the current master branch or the latest release. Please indicate:

Describe the Bug

This problem arises in the function get_buses_linemap_and_lines in the following code when the lines dataframe is empty:

return (
        buses,
        linemap,
        linemap_p,
        linemap_n,
        lines.reset_index()
        .rename(columns={"bus0_s": "bus0", "bus1_s": "bus1"}, copy=False)
        .set_index("name"),
        lines_t,
    )

This seems to be due to the function aggregatelines called previously that does stuff on the lines dataframe including groupbys.
That should normally drop such columns but that does not happen when the dataframe is empty.
This is an error we experienced when running the pypsa-earth workflow on rwanda.

Error Message

If applicable, paste any terminal output to help illustrating your problem.
In some cases it may also be useful to share your list of installed packages: conda list.

Exception has occurred: ValueError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
cannot insert bus1_s, already exists
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/frame.py", line 4814, in insert
    raise ValueError(f"cannot insert {column}, already exists")
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/core/frame.py", line 6358, in reset_index
    new_obj.insert(
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pandas/util/_decorators.py", line 331, in wrapper
    return func(*args, **kwargs)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pypsa/networkclustering.py", line 351, in get_buses_linemap_and_lines
    lines.reset_index()
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/site-packages/pypsa/networkclustering.py", line 378, in get_clustering_from_busmap
    buses, linemap, linemap_p, linemap_n, lines, lines_t = get_buses_linemap_and_lines(
  File "/data/davidef/git_world/pypsa-earth/scripts/cluster_network.py", line 444, in clustering_for_n_clusters
    clustering = get_clustering_from_busmap(
  File "/data/davidef/git_world/pypsa-earth/scripts/cluster_network.py", line 577, in <module>
    clustering = clustering_for_n_clusters(
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/davidef/miniconda3/envs/pypsa-earth/lib/python3.10/runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants