diff --git a/assume/common/outputs.py b/assume/common/outputs.py index 9d34b4efb..392644f86 100644 --- a/assume/common/outputs.py +++ b/assume/common/outputs.py @@ -318,8 +318,8 @@ def write_market_dispatch(self, data): :type data: any """ df = pd.DataFrame(data, columns=["datetime", "power", "market_id", "unit_id"]) - df["simulation"] = self.simulation_id if not df.empty: + df["simulation"] = self.simulation_id self.write_dfs["market_dispatch"].append(df) def write_unit_dispatch(self, data): diff --git a/tests/test_outputs.py b/tests/test_outputs.py index 34ac755af..4c8a3ba33 100644 --- a/tests/test_outputs.py +++ b/tests/test_outputs.py @@ -114,6 +114,15 @@ def test_output_market_dispatch(): meta = {"sender_id": None} content = {"context": "write_results", "type": "market_dispatch", "data": []} output_writer.handle_message(content, meta) + # empty dfs are discarded + assert len(output_writer.write_dfs["market_dispatch"]) == 0, "market_dispatch" + + content = { + "context": "write_results", + "type": "market_dispatch", + "data": [[start, 90, "EOM", "TestUnit"]], + } + output_writer.handle_message(content, meta) assert len(output_writer.write_dfs["market_dispatch"]) == 1, "market_dispatch"