Skip to content

Commit

Permalink
Merge pull request #132 from washingtonpost/release/2.2.2
Browse files Browse the repository at this point in the history
Release/2.2.2 🎉
  • Loading branch information
dmnapolitano authored Nov 5, 2024
2 parents e93515e + 838fd12 commit ebc3a40
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

# 2.2.2 (11/5/2024)
- fix: missing `est_correction` column in `VersionedResults` `DataFrame` in the event of bad data [#131](https://github.com/washingtonpost/elex-live-model/pull/131)

# 2.2.1 (11/1/2024)
- chore: downgrade botocore and s3transfer as per live team dependency [#128](https://github.com/washingtonpost/elex-live-model/pull/128)

Expand Down
11 changes: 11 additions & 0 deletions src/elexmodel/handlers/data/VersionedData.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def compute_estimated_margin(df):
"percent_expected_vote": np.arange(101),
"nearest_observed_vote": np.nan * np.ones(101),
"est_margin": np.nan * np.ones(101),
"est_correction": np.nan * np.ones(101),
"error_type": "non-monotone percent expected vote",
}
)

Expand All @@ -152,6 +154,8 @@ def compute_estimated_margin(df):
"percent_expected_vote": np.arange(101),
"nearest_observed_vote": np.nan * np.ones(101),
"est_margin": np.nan * np.ones(101),
"est_correction": np.nan * np.ones(101),
"error_type": "batch_margin",
}
)

Expand Down Expand Up @@ -196,10 +200,17 @@ def compute_estimated_margin(df):
"nearest_observed_vote": percent_vote[np.clip(obs_indices + 1, 0, len(percent_vote) - 1)],
"est_margin": est_margins,
"est_correction": norm_margin[-1] - est_margins,
"error_type": "none",
}
)

results = results.groupby("geographic_unit_fips").apply(compute_estimated_margin).reset_index()

for error_type in sorted(set(results["error_type"])):
if error_type == "none":
continue
category_error_type = results[results["error_type"] == error_type].geographic_unit_fips.unique()
LOG.info(f"# of versioned units with {error_type} error: {len(category_error_type)}")
return results

def get_versioned_predictions(self, filepath=None):
Expand Down

0 comments on commit ebc3a40

Please sign in to comment.