Skip to content

Commit

Permalink
Merge pull request #88 from washingtonpost/release/2.0.2
Browse files Browse the repository at this point in the history
Release/2.0.2
  • Loading branch information
lennybronner authored Nov 2, 2023
2 parents 944ddf5 + b71bca7 commit 4aba500
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.2 (11/02/2023)
- fix: allow bootstrap model parameters to be of type int as well as float [#86](https://github.com/washingtonpost/elex-live-model/pull/86)
- fix: pass alpha to national summary client function [#87](https://github.com/washingtonpost/elex-live-model/pull/87)

## 2.0.1 (10/23/2023)
- chore: updating all required packages to their latest versions and addressing some warnings that surfaced during testing [#81](https://github.com/washingtonpost/elex-live-model/pull/81)
- fix: CLI no longer throws an error if `aggregates` are missing or specified with columns that don't exist in the data [#83](https://github.com/washingtonpost/elex-live-model/pull/83)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
LONG_DESCRIPTION = f.read()

# The full version, including alpha/beta/rc tags
RELEASE = "2.0.1"
RELEASE = "2.0.2"
# The short X.Y version
VERSION = ".".join(RELEASE.split(".")[:2])

Expand Down
26 changes: 13 additions & 13 deletions src/elexmodel/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ def _check_input_parameters(
):
raise ValueError("lambda is not valid. It has to be numeric and greater than zero.")
if "turnout_factor_lower" in model_parameters and not isinstance(
model_parameters["turnout_factor_lower"], float
model_parameters["turnout_factor_lower"], (float, int)
):
raise ValueError("turnout_factor_lower is not valid. Has to be a float.")
if "turnout_factor_upper" in model_parameters and not isinstance(
model_parameters["turnout_factor_upper"], float
model_parameters["turnout_factor_upper"], (float, int)
):
raise ValueError("turnout_factor_upper is not valid. Has to be a float.")
if pi_method == "gaussian":
Expand All @@ -130,32 +130,32 @@ def _check_input_parameters(
model_parameters["agg_model_hard_threshold"], bool
):
raise ValueError("agg_model_hard_threshold is not valid. Has to be a boolean.")
if "y_LB" in model_parameters and not isinstance(model_parameters["y_LB"], float):
if "y_LB" in model_parameters and not isinstance(model_parameters["y_LB"], (float, int)):
raise ValueError("y_LB is not valid. Has to be a float.")
if "y_UB" in model_parameters and not isinstance(model_parameters["y_UB"], float):
if "y_UB" in model_parameters and not isinstance(model_parameters["y_UB"], (float, int)):
raise ValueError("y_UB is not valid. Has to be a float.")
if "z_LB" in model_parameters and not isinstance(model_parameters["z_LB"], float):
if "z_LB" in model_parameters and not isinstance(model_parameters["z_LB"], (float, int)):
raise ValueError("z_LB is not valid. Has to be a float.")
if "z_UB" in model_parameters and not isinstance(model_parameters["z_UB"], float):
if "z_UB" in model_parameters and not isinstance(model_parameters["z_UB"], (float, int)):
raise ValueError("z_UB is not valid. Has to be a float.")
if "y_unobserved_upper_bound" in model_parameters and not isinstance(
model_parameters["y_unobserved_upper_bound"], float
model_parameters["y_unobserved_upper_bound"], (float, int)
):
raise ValueError("y_unobserved_upper_bound is not valid. Has to be a float.")
if "y_unobserved_lower_bound" in model_parameters and not isinstance(
model_parameters["y_unobserved_lower_bound"], float
model_parameters["y_unobserved_lower_bound"], (float, int)
):
raise ValueError("y_unobserved_lower_bound is not valid. Has to be a float.")
if "percent_expected_vote_error_bound" in model_parameters and not isinstance(
model_parameters["percent_expected_vote_error_bound"], float
model_parameters["percent_expected_vote_error_bound"], (float, int)
):
raise ValueError("z_UB is not valid. Has to be a float.")
if "z_unobserved_upper_bound" in model_parameters and not isinstance(
model_parameters["z_unobserved_upper_bound"], float
model_parameters["z_unobserved_upper_bound"], (float, int)
):
raise ValueError("z_unobserved_upper_bound is not valid. Has to be a float.")
if "z_unobserved_lower_bound" in model_parameters and not isinstance(
model_parameters["z_unobserved_lower_bound"], float
model_parameters["z_unobserved_lower_bound"], (float, int)
):
raise ValueError("z_unobserved_lower_bound is not valid. Has to be a float.")
if handle_unreporting not in {"drop", "zero"}:
Expand All @@ -169,8 +169,8 @@ def get_aggregate_list(self, office, aggregate):
raw_aggregate_list = base_aggregate + [aggregate]
return sorted(list(set(raw_aggregate_list)), key=lambda x: AGGREGATE_ORDER.index(x))

def get_national_summary_votes_estimates(self, nat_sum_data_dict=None, called_states={}, base_to_add=0):
return self.model.get_national_summary_estimates(nat_sum_data_dict, called_states, base_to_add)
def get_national_summary_votes_estimates(self, nat_sum_data_dict=None, called_states={}, base_to_add=0, alpha=0.99):
return self.model.get_national_summary_estimates(nat_sum_data_dict, called_states, base_to_add, alpha)

def get_estimates(
self,
Expand Down
45 changes: 39 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
aggregates = ["postal_code", "county_fips"]
fixed_effects = []
pi_method = "gaussian"
model_parameters = {
"beta": 3,
"winsorize": False,
"robust": True,
"lambda_": 0,
}
model_parameters = {"beta": 3, "winsorize": False, "robust": True, "lambda_": 0, "y_LB": 1.0, "y_UB": 4}
handle_unreporting = "drop"


Expand All @@ -47,6 +42,25 @@ def test_check_input_parameters(model_client, va_config):
)


def test_check_input_parameters_bootstrap(model_client, va_config):
# this is to test y_LB and y_UB
election_id = "2017-11-07_VA_G"
config_handler = ConfigHandler(election_id, config=va_config)

assert model_client._check_input_parameters(
config_handler,
office,
estimands,
geographic_unit_type,
features,
aggregates,
fixed_effects,
"bootstrap",
model_parameters,
handle_unreporting,
)


def test_check_input_parameters_office(model_client, va_config):
election_id = "2017-11-07_VA_G"
config_handler = ConfigHandler(election_id, config=va_config)
Expand Down Expand Up @@ -297,6 +311,25 @@ def test_check_input_parameters_lambda_(model_client, va_config):
)


def test_check_input_parameters_y_UB_LB(model_client, va_config):
election_id = "2017-11-07_VA_G"
config_handler = ConfigHandler(election_id, config=va_config)

with pytest.raises(ValueError):
model_client._check_input_parameters(
config_handler,
office,
estimands,
geographic_unit_type,
features,
aggregates,
fixed_effects,
"bootstrap",
{"beta": 3, "winsorize": False, "robust": True, "lambda_": -1, "y_LB": "break", "y_UB": 1},
handle_unreporting,
)


def test_check_input_parameters_handle_unreporting(model_client, va_config):
election_id = "2017-11-07_VA_G"
config_handler = ConfigHandler(election_id, config=va_config)
Expand Down

0 comments on commit 4aba500

Please sign in to comment.