Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions matpowercaseframes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,12 @@ def _update_index(self, allow_any_keys=False):
# gencost is optional
# NOTE: try except is better than checking hasattr for common possitive
try:
if "gen_name" in self._attributes:
gencost_len = len(self.gencost)
if gencost_len == len(self.gen) and "gen_name" in self._attributes:
self.gencost.set_index(self.gen_name, drop=False, inplace=True)
else:
self.gencost.set_index(
pd.RangeIndex(1, len(self.gen.index) + 1, name="gen"),
pd.RangeIndex(1, len(self.gencost.index) + 1, name="gen"),
drop=False,
inplace=True,
)
Expand Down
953 changes: 953 additions & 0 deletions notebooks/load_cases.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions requirements-all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ openpyxl==3.1.5
oct2py==5.8.0
matpower==8.1.0.2.3.0

itables==2.7.1

pre-commit==4.5.1
ruff==0.15.5
setuptools==82.0.0
Expand Down
11 changes: 11 additions & 0 deletions tests/test_read_matpower_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
pytest -n auto -rA --cov-report term --cov=matpowercaseframes tests/

case9 : default MATPOWER case, polynomial gencost (TYPE=2)
case9Q : case with Q gencost
case4_dist : small distribution network case
case118 : medium-scale IEEE case, tests all three loading methods
case_RTS_GMLC : piecewise linear gencost (TYPE=1) and contains bus_name
Expand All @@ -41,6 +42,16 @@ def test_case9():
assert cf.gencost.columns.equals(cols)


def test_case9Q():
"""
Default MATPOWER 9-bus case, polynomial gencost columns:
MODEL, STARTUP, SHUTDOWN, NCOST, C2, C1, C0.
"""
CASE_NAME = "case9Q.m"
cf = CaseFrames(CASE_NAME)
assert len(cf.gencost) // len(cf.gen) == 2


def test_case4_dist():
"""Small 4-bus radial distribution network case."""
CASE_NAME = "case4_dist.m"
Expand Down