From 023277cfa15eea2bb2ad529b779a63d7a06a7660 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Fri, 11 Sep 2020 15:14:26 -0700 Subject: [PATCH] refactor: expect datetime indices in tests with mock scenarios --- .../analyze/generation/tests/test_binding.py | 26 +++++++------------ .../generation/tests/test_curtailment.py | 2 ++ .../tests/test_congestion_surplus.py | 10 +++++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/postreise/analyze/generation/tests/test_binding.py b/postreise/analyze/generation/tests/test_binding.py index 7c4a2a1a..a2e20797 100644 --- a/postreise/analyze/generation/tests/test_binding.py +++ b/postreise/analyze/generation/tests/test_binding.py @@ -63,18 +63,16 @@ def setUp(self): grid_attrs = {"plant": mock_plant} mock_pg = pd.DataFrame( { - "UTC": ["t1", "t2", "t3", "t4"], "A": [100, 104, (99 + 1e-4), (104 + 1e-4 - 1e-7)], "B": [50, 45, 50, 45], "C": [20, 40, 60, 80], "D": [200, 150, 100, 50], } ) - mock_pg.set_index("UTC", inplace=True) self.mock_scenario = MockScenario(grid_attrs, pg=mock_pg) self.default_expected = pd.DataFrame( { - "UTC": ["t1", "t2", "t3", "t4"], + "UTC": pd.date_range(start="2016-01-01", periods=4, freq="H"), "A": [False, False, True, True], "B": [False, False, False, False], "C": [False, True, True, True], @@ -101,7 +99,7 @@ def test_ramp_constraints_spec_epsilon2(self): # One differece from test_ramp_constraints_default: ('A', 't3') binding_ramps = ramp_constraints(self.mock_scenario, epsilon=1e-6) expected = self.get_default_expected() - expected.loc["t3", "A"] = False + expected.loc["2016-01-01 02:00:00", "A"] = False assert binding_ramps.equals(expected) def test_ramp_constraints_spec_epsilon3(self): @@ -121,18 +119,16 @@ def setUp(self): grid_attrs = {"plant": mock_plant} mock_pg = pd.DataFrame( { - "UTC": ["t1", "t2"], "A": [0, 0], "B": [(10 + 1e-4), 15], "C": [25, (20 + 1e-7)], "D": [35, 40], } ) - mock_pg.set_index("UTC", inplace=True) self.mock_scenario = MockScenario(grid_attrs, pg=mock_pg) self.default_expected = pd.DataFrame( { - "UTC": ["t1", "t2"], + "UTC": pd.date_range(start="2016-01-01", periods=2, freq="H"), "A": [True, True], "B": [True, False], "C": [False, True], @@ -157,14 +153,14 @@ def test_pmin_constraints_default_spec_epsilon1(self): def test_pmin_constraints_default_spec_epsilon2(self): binding_pmins = pmin_constraints(self.mock_scenario, epsilon=1e-6) expected = self.get_default_expected() - expected.loc["t1", "B"] = False + expected.loc["2016-01-01 00:00:00", "B"] = False assert binding_pmins.equals(expected) def test_pmin_constraints_default_spec_epsilon3(self): binding_pmins = pmin_constraints(self.mock_scenario, epsilon=1e-9) expected = self.get_default_expected() - expected.loc["t1", "B"] = False - expected.loc["t2", "C"] = False + expected.loc["2016-01-01 00:00:00", "B"] = False + expected.loc["2016-01-01 01:00:00", "C"] = False assert binding_pmins.equals(expected) @@ -177,18 +173,16 @@ def setUp(self): grid_attrs = {"plant": mock_plant} mock_pg = pd.DataFrame( { - "UTC": ["t1", "t2"], "A": [50, 50], "B": [(75 - 1e-4), 70], "C": [90, (100 - 1e-7)], "D": [150, 175], } ) - mock_pg.set_index("UTC", inplace=True) self.mock_scenario = MockScenario(grid_attrs, pg=mock_pg) self.default_expected = pd.DataFrame( { - "UTC": ["t1", "t2"], + "UTC": pd.date_range(start="2016-01-01", periods=2, freq="H"), "A": [True, True], "B": [True, False], "C": [False, True], @@ -213,12 +207,12 @@ def test_pmax_constraints_default_sepc_epsilon1(self): def test_pmax_constraints_default_sepc_epsilon2(self): binding_pmaxs = pmax_constraints(self.mock_scenario, epsilon=1e-6) expected = self.get_default_expected() - expected.loc["t1", "B"] = False + expected.loc["2016-01-01 00:00:00", "B"] = False assert binding_pmaxs.equals(expected) def test_pmax_constraints_default_sepc_epsilon3(self): binding_pmaxs = pmax_constraints(self.mock_scenario, epsilon=1e-9) expected = self.get_default_expected() - expected.loc["t1", "B"] = False - expected.loc["t2", "C"] = False + expected.loc["2016-01-01 00:00:00", "B"] = False + expected.loc["2016-01-01 01:00:00", "C"] = False assert binding_pmaxs.equals(expected) diff --git a/postreise/analyze/generation/tests/test_curtailment.py b/postreise/analyze/generation/tests/test_curtailment.py index c7d3c443..edb7f348 100644 --- a/postreise/analyze/generation/tests/test_curtailment.py +++ b/postreise/analyze/generation/tests/test_curtailment.py @@ -52,6 +52,8 @@ "D": [0, 0, 1, 1.5], } ) +mock_curtailment_data["UTC"] = pd.date_range(start="2016-01-01", periods=4, freq="H") +mock_curtailment_data.set_index("UTC", inplace=True) mock_curtailment = { "solar": mock_curtailment_data[["A", "B"]], diff --git a/postreise/analyze/transmission/tests/test_congestion_surplus.py b/postreise/analyze/transmission/tests/test_congestion_surplus.py index 629deda1..1b3b7d55 100644 --- a/postreise/analyze/transmission/tests/test_congestion_surplus.py +++ b/postreise/analyze/transmission/tests/test_congestion_surplus.py @@ -43,7 +43,10 @@ def test_calculate_congestion_surplus_single_time(self): df.set_index("UTC", inplace=True) mock_scenario = MockScenario(grid_attrs, demand=demand, lmp=lmp, pg=pg) - expected_return = pd.Series(data=[787.5], index=["t1"]) + expected_return = pd.Series( + data=[787.5], + index=pd.date_range(start="2016-01-01", periods=1, freq="H"), + ) expected_return.rename_axis("UTC") surplus = calculate_congestion_surplus(mock_scenario) @@ -74,7 +77,10 @@ def test_calculate_congestion_surplus_three_times(self): df.set_index("UTC", inplace=True) mock_scenario = MockScenario(grid_attrs, demand=demand, lmp=lmp, pg=pg) - expected_return = pd.Series(data=[787.5, 0, 0], index=time_indices) + expected_return = pd.Series( + data=[787.5, 0, 0], + index=pd.date_range(start="2016-01-01", periods=3, freq="H"), + ) expected_return.rename_axis("UTC") surplus = calculate_congestion_surplus(mock_scenario)