From 999f39f2a64b49e2fb1199b3c6a78916c499c74f Mon Sep 17 00:00:00 2001 From: Will Usher Date: Thu, 1 Feb 2024 10:57:12 +0100 Subject: [PATCH] Read in zero values from cplex --- src/otoole/results/results.py | 4 ++-- tests/test_read_strategies.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/otoole/results/results.py b/src/otoole/results/results.py index ae45d737..547678e5 100644 --- a/src/otoole/results/results.py +++ b/src/otoole/results/results.py @@ -179,7 +179,7 @@ def rename_duplicate_column(index: List) -> List: class ReadCplex(ReadWideResults): - """Read a CPLEX solution file into memeory""" + """Read a CPLEX solution file into memory""" def _convert_to_dataframe(self, file_path: Union[str, TextIO]) -> pd.DataFrame: """Reads a Cplex solution file into a pandas DataFrame @@ -193,7 +193,7 @@ def _convert_to_dataframe(self, file_path: Union[str, TextIO]) -> pd.DataFrame: df[["Variable", "Index"]] = df["name"].str.split("(", expand=True) df["Index"] = df["Index"].str.replace(")", "", regex=False) LOGGER.debug(df) - df = df[(df["value"] != 0)].reset_index().rename(columns={"value": "Value"}) + df = df.reset_index().rename(columns={"value": "Value"}) return df[["Variable", "Index", "Value"]].astype({"Value": float}) diff --git a/tests/test_read_strategies.py b/tests/test_read_strategies.py index 574fcee8..8726e4f1 100644 --- a/tests/test_read_strategies.py +++ b/tests/test_read_strategies.py @@ -83,8 +83,11 @@ def test_convert_to_dataframe(self, user_config): # print(actual) expected = pd.DataFrame( [ + ["NewCapacity", "SIMPLICITY,ETHPLANT,2014", 0], ["NewCapacity", "SIMPLICITY,ETHPLANT,2015", 0.030000000000000027], ["NewCapacity", "SIMPLICITY,ETHPLANT,2016", 0.030999999999999917], + ["RateOfActivity", "SIMPLICITY,ID,GRID_EXP,1,2014", 0], + ["RateOfActivity", "SIMPLICITY,ID,GRID_EXP,2,2014", 0], ["RateOfActivity", "SIMPLICITY,ID,HYD1,1,2020", 0.25228800000000001], ["RateOfActivity", "SIMPLICITY,ID,HYD1,1,2021", 0.25228800000000001], ["RateOfActivity", "SIMPLICITY,ID,HYD1,1,2022", 0.25228800000000001], @@ -103,6 +106,7 @@ def test_solution_to_dataframe(self, user_config): expected = ( pd.DataFrame( [ + ["SIMPLICITY", "ETHPLANT", 2014, 0], ["SIMPLICITY", "ETHPLANT", 2015, 0.030000000000000027], ["SIMPLICITY", "ETHPLANT", 2016, 0.030999999999999917], ], @@ -117,6 +121,8 @@ def test_solution_to_dataframe(self, user_config): expected = ( pd.DataFrame( [ + ["SIMPLICITY", "ID", "GRID_EXP", 1, 2014, 0], + ["SIMPLICITY", "ID", "GRID_EXP", 2, 2014, 0], ["SIMPLICITY", "ID", "HYD1", 1, 2020, 0.25228800000000001], ["SIMPLICITY", "ID", "HYD1", 1, 2021, 0.25228800000000001], ["SIMPLICITY", "ID", "HYD1", 1, 2022, 0.25228800000000001],