Skip to content

Commit

Permalink
Read in zero values from cplex
Browse files Browse the repository at this point in the history
  • Loading branch information
willu47 committed Feb 1, 2024
1 parent 15bdc0b commit 999f39f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/otoole/results/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})


Expand Down
6 changes: 6 additions & 0 deletions tests/test_read_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
],
Expand All @@ -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],
Expand Down

0 comments on commit 999f39f

Please sign in to comment.