Skip to content

Commit

Permalink
update highs tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed May 2, 2024
1 parent b3de89b commit 9e0914b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/otoole/results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,20 @@ def _convert_to_dataframe(self, file_path: Union[str, TextIO]) -> pd.DataFrame:
---------
file_path : str
"""

df = pd.read_csv(
file_path,
sep=r"\s+",
skiprows=1,
index_col=0,
dtype=str, # suppresses pandas warning
dtype=str,
)
df.index.name = "" # remove the name Index, as otoole uses that

var_types = ["Continuous", "Integer", "SemiContinuous", "SemiInteger"]
df = df[df.Type.isin(var_types)].copy()
df[["Variable", "Index"]] = df["Name"].str.split("(", expand=True).loc[:, 0:1]
df["Index"] = df["Index"].str.replace(")", "", regex=False)
df = df[~(df.Primal.astype(float).abs() < 1e-6)]
return (
df[["Variable", "Index", "Primal"]]
.rename(columns={"Primal": "Value"})
Expand Down
5 changes: 2 additions & 3 deletions tests/test_read_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,7 @@ class TestReadHighs:
"""Tests reading of HiGHS solution file"""

highs_data = dedent(
"""
Columns
"""Columns
Index Status Lower Upper Primal Dual Type Name
0 BS 0 inf 193.604 0 Continuous TotalDiscountedCost(SIMPLICITY,2014)
1 BS 0 inf 187.724 0 Continuous TotalDiscountedCost(SIMPLICITY,2015)
Expand Down Expand Up @@ -739,8 +738,8 @@ def test_convert_to_dataframe(self, user_config):
["TotalDiscountedCost", "SIMPLICITY,2016", 183.998],
["TotalDiscountedCost", "SIMPLICITY,2017", 181.728],
["RateOfActivity", "SIMPLICITY,WN,HYD1,1,2020", 0.353203],
["RateOfActivity", "SIMPLICITY,WN,HYD1,1,2021", 0.353203],
["RateOfTotalActivity", "SIMPLICITY,HYD1,WN,2020", 0.353203],
["RateOfActivity", "SIMPLICITY,WN,HYD1,1,2021", 0.353203],
],
columns=["Variable", "Index", "Value"],
).astype({"Variable": str, "Index": str, "Value": float})
Expand Down

0 comments on commit 9e0914b

Please sign in to comment.