Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: expect datetime indices in tests with mock scenarios #166

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions postreise/analyze/generation/tests/test_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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):
Expand All @@ -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],
Expand All @@ -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)


Expand All @@ -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],
Expand All @@ -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)
2 changes: 2 additions & 0 deletions postreise/analyze/generation/tests/test_curtailment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
Expand Down
10 changes: 8 additions & 2 deletions postreise/analyze/transmission/tests/test_congestion_surplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down