From 4e00552b558b222276e872156c23fb0bab82a5da Mon Sep 17 00:00:00 2001 From: lennybronner Date: Tue, 22 Oct 2024 22:10:25 -0400 Subject: [PATCH] linter --- tests/handlers/test_combined_data.py | 38 ++++++++++++------- tests/models/test_bootstrap_election_model.py | 8 +++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/handlers/test_combined_data.py b/tests/handlers/test_combined_data.py index 2f56982f..5cd37e84 100644 --- a/tests/handlers/test_combined_data.py +++ b/tests/handlers/test_combined_data.py @@ -415,6 +415,7 @@ def test_postal_code_blocklist(va_governor_county_data): assert reporting_data.shape[0] == 0 assert nonreporting_data.shape[0] == 0 + def test_turnout_factor_outlier_model(va_governor_county_data): election_id = "2017-11-07_VA_G" office = "G" @@ -425,16 +426,22 @@ def test_turnout_factor_outlier_model(va_governor_county_data): election_id, office, geographic_unit_type, estimands, data=va_governor_county_data ) current_data = live_data_handler.get_n_fully_reported(n=133) - + current_data.loc[0, "results_turnout"] = 100000 current_data.loc[0, "results_weights"] = 100000 current_data.loc[1, "results_turnout"] = 5 current_data.loc[1, "results_weights"] = 5 va_governor_county_data["baseline_weights"] = va_governor_county_data.baseline_turnout - va_governor_county_data["last_election_results_margin"] = va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop - va_governor_county_data["baseline_margin"] = va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop - va_governor_county_data["baseline_normalized_margin"] = va_governor_county_data.baseline_margin / va_governor_county_data.baseline_weights + va_governor_county_data["last_election_results_margin"] = ( + va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop + ) + va_governor_county_data["baseline_margin"] = ( + va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop + ) + va_governor_county_data["baseline_normalized_margin"] = ( + va_governor_county_data.baseline_margin / va_governor_county_data.baseline_weights + ) combined_data_handler = CombinedDataHandler(va_governor_county_data, current_data, estimands, geographic_unit_type) turnout_factor_lower = -np.inf @@ -443,9 +450,8 @@ def test_turnout_factor_outlier_model(va_governor_county_data): 100, turnout_factor_lower, turnout_factor_upper, [], [], False, True, 1.2, ["county_fips"] ) assert unexpected_data.shape[0] == 2 - assert ( - len(unexpected_data[unexpected_data["unit_category"] == "non-modeled: strange turnout factor modeled"]) == 2 - ) + assert len(unexpected_data[unexpected_data["unit_category"] == "non-modeled: strange turnout factor modeled"]) == 2 + def test_margin_outlier_model(va_governor_county_data): election_id = "2017-11-07_VA_G" @@ -457,14 +463,20 @@ def test_margin_outlier_model(va_governor_county_data): election_id, office, geographic_unit_type, estimands, data=va_governor_county_data ) current_data = live_data_handler.get_n_fully_reported(n=133) - + current_data.loc[0, "results_normalized_margin"] = 1.0 current_data.loc[1, "results_normalized_margin"] = -1.0 va_governor_county_data["baseline_weights"] = va_governor_county_data.baseline_turnout - va_governor_county_data["last_election_results_margin"] = va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop - va_governor_county_data["baseline_margin"] = va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop - va_governor_county_data["baseline_normalized_margin"] = va_governor_county_data.baseline_margin / va_governor_county_data.baseline_weights + va_governor_county_data["last_election_results_margin"] = ( + va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop + ) + va_governor_county_data["baseline_margin"] = ( + va_governor_county_data.baseline_dem - va_governor_county_data.baseline_gop + ) + va_governor_county_data["baseline_normalized_margin"] = ( + va_governor_county_data.baseline_margin / va_governor_county_data.baseline_weights + ) combined_data_handler = CombinedDataHandler(va_governor_county_data, current_data, estimands, geographic_unit_type) turnout_factor_lower = -np.inf @@ -473,6 +485,4 @@ def test_margin_outlier_model(va_governor_county_data): 100, turnout_factor_lower, turnout_factor_upper, [], [], True, False, 2, ["county_fips"] ) assert unexpected_data.shape[0] == 2 - assert ( - len(unexpected_data[unexpected_data["unit_category"] == "non-modeled: strange margin change modeled"]) == 2 - ) \ No newline at end of file + assert len(unexpected_data[unexpected_data["unit_category"] == "non-modeled: strange margin change modeled"]) == 2 diff --git a/tests/models/test_bootstrap_election_model.py b/tests/models/test_bootstrap_election_model.py index 454b5d72..7ee2958b 100644 --- a/tests/models/test_bootstrap_election_model.py +++ b/tests/models/test_bootstrap_election_model.py @@ -1124,7 +1124,9 @@ def test_get_national_summary_estimates(bootstrap_election_model, rng): nat_sum_estimates["margin"][0] == 4 or nat_sum_estimates["margin"][0] == 5 ) # the 3 called ones plus the third one where we stop a call from happening assert nat_sum_estimates["margin"][1] == 3 # the 3 called ones - assert nat_sum_estimates["margin"][2] == 5 or nat_sum_estimates["margin"][2] == 6 # all of them except the first one + assert ( + nat_sum_estimates["margin"][2] == 5 or nat_sum_estimates["margin"][2] == 6 + ) # all of them except the first one rhs_called_contests = ["c", "d", "e", "f"] lhs_called_contests = ["a"] @@ -1149,7 +1151,9 @@ def test_get_national_summary_estimates(bootstrap_election_model, rng): rhs_called_contests=rhs_called_contests, ) nat_sum_estimates = bootstrap_election_model.get_national_summary_estimates(None, 0, 0.95) - assert nat_sum_estimates["margin"][0] == 1 or nat_sum_estimates["margin"][0] == 2 # the first one which is called for lhs + assert ( + nat_sum_estimates["margin"][0] == 1 or nat_sum_estimates["margin"][0] == 2 + ) # the first one which is called for lhs assert nat_sum_estimates["margin"][1] == 1 # the first one which is called for lhs assert nat_sum_estimates["margin"][2] == 2 # 2nd and first