From 9e0914bc70959dd37072f7c4f371f954b0ec7f20 Mon Sep 17 00:00:00 2001 From: trevorb1 Date: Thu, 2 May 2024 16:44:57 -0700 Subject: [PATCH] update highs tests --- src/otoole/results/results.py | 4 ++-- tests/test_read_strategies.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/otoole/results/results.py b/src/otoole/results/results.py index c6ae07d..e3297cd 100644 --- a/src/otoole/results/results.py +++ b/src/otoole/results/results.py @@ -266,13 +266,12 @@ 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 @@ -280,6 +279,7 @@ def _convert_to_dataframe(self, file_path: Union[str, TextIO]) -> pd.DataFrame: 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"}) diff --git a/tests/test_read_strategies.py b/tests/test_read_strategies.py index 45a6954..19a6a07 100644 --- a/tests/test_read_strategies.py +++ b/tests/test_read_strategies.py @@ -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) @@ -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})