n.lpf_contingency() returns AttributeError: 'DataFrame' object has no attribute 'to_frame'

未关闭 适合新手
#2,082 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

@Blizzeq 已经在做这个了。

开始于 2026年11月3日。

  • #2088 来自 @Blizzeq —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
pandas, python
领域
backend

调研方向

traceback 指向 pypsa/network/power_flow.py 第 1003 行附近,位于 lpf_contingency 内部,此处假定 p0_base 是 Series,但实际上它是 DataFrame。请先检查该位置 p0_base 的类型,以及它在函数前面是如何构建的。当复现脚本(ac_dc_meshed()、optimize()、lpf_contingency()、passive_branches_i())运行时不再出现 AttributeError,且现有的潮流计算测试仍然通过,即视为完成。

由索引模型根据 Issue 内容生成。

描述

needs triage
Version Checks (indicate both or one)
  • I have confirmed this bug exists on the lastest release of PyPSA.

  • I have confirmed this bug exists on the current master branch of PyPSA.

Issue Description

Running n.lpf_contingency() shows the following error:

Traceback (most recent call last):
  File "/home/markus/PyPSA/z.py", line 5, in <module>
    n.lpf_contingency()
    ~~~~~~~~~~~~~~~~~^^
  File "/home/markus/PyPSA/pypsa/common.py", line 849, in wrapper
    return func(self, *args, **kwargs)
  File "/home/markus/PyPSA/pypsa/network/power_flow.py", line 1003, in lpf_contingency
    p0 = p0_base.to_frame("base")
         ^^^^^^^^^^^^^^^^
  File "/home/markus/PyPSA/.venv/lib/python3.13/site-packages/pandas/core/generic.py", line 6206, in __getattr__
    return object.__getattribute__(self, name)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AttributeError: 'DataFrame' object has no attribute 'to_frame'
Reproducible Example
import pypsa
n = pypsa.examples.ac_dc_meshed()
n.optimize()
n.lpf_contingency()
n.passive_branches_i()
Expected Behavior

No error message.

Installed Versions
GitHub clone from 3.11.2026, 9:30
主要语言
Python
星标
2.2k
派生
732
平均合并
3 天 59 分钟
30 天内合并 PR
58

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PyPSA/PyPSA 的其他 Issue

查看 PyPSA/PyPSA 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。