Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
lennybronner committed Oct 23, 2024
1 parent 67016c3 commit 4e00552
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
38 changes: 24 additions & 14 deletions tests/handlers/test_combined_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
)
assert len(unexpected_data[unexpected_data["unit_category"] == "non-modeled: strange margin change modeled"]) == 2
8 changes: 6 additions & 2 deletions tests/models/test_bootstrap_election_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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

Expand Down

0 comments on commit 4e00552

Please sign in to comment.