Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
aarsilv committed Jul 19, 2024
1 parent 4b0ef38 commit 80470e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 7 additions & 5 deletions eppo_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ def get_bandit_action(
variation = default
action = None
try:
subject_attributes = convert_context_attributes_to_attributes(subject_context)
subject_attributes = convert_context_attributes_to_attributes(
subject_context
)

# first, get experiment assignment
variation = self.get_string_assignment(
Expand Down Expand Up @@ -365,7 +367,9 @@ def evaluate_bandit_action(
"action": evaluation.action_key if evaluation else None,
"actionProbability": evaluation.action_weight if evaluation else None,
"optimalityGap": evaluation.optimality_gap if evaluation else None,
"modelVersion": bandit_data.bandit_model_version if evaluation else None,
"modelVersion": (
bandit_data.bandit_model_version if evaluation else None
),
"timestamp": datetime.datetime.utcnow().isoformat(),
"subjectNumericAttributes": (
subject_context_attributes.numeric_attributes
Expand Down Expand Up @@ -486,6 +490,4 @@ def convert_attributes_to_context_attributes(
def convert_actions_to_action_contexts(
actions: Union[ActionContexts, ActionAttributes]
) -> ActionContexts:
return {
k: convert_attributes_to_context_attributes(v) for k, v in actions.items()
}
return {k: convert_attributes_to_context_attributes(v) for k, v in actions.items()}
14 changes: 11 additions & 3 deletions test/client_bandit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ def test_get_bandit_action_flag_not_exist():
def test_get_bandit_action_flag_has_no_bandit():
client = get_instance()
result = client.get_bandit_action(
"non_bandit_flag", "subject_key", DEFAULT_SUBJECT_ATTRIBUTES, {}, "default_variation"
"non_bandit_flag",
"subject_key",
DEFAULT_SUBJECT_ATTRIBUTES,
{},
"default_variation",
)
assert result == BanditResult("control", None)


@patch.object(BanditEvaluator, 'evaluate_bandit', side_effect=Exception("Mocked Exception"))
@patch.object(
BanditEvaluator, "evaluate_bandit", side_effect=Exception("Mocked Exception")
)
def test_get_bandit_action_bandit_error(mock_bandit_evaluator):
client = get_instance()
client.set_is_graceful_mode(True)
Expand Down Expand Up @@ -207,7 +213,9 @@ def test_get_bandit_action_with_subject_attributes():
)


@patch.object(MockAssignmentLogger, 'log_bandit_action', side_effect=Exception("Mocked Exception"))
@patch.object(
MockAssignmentLogger, "log_bandit_action", side_effect=Exception("Mocked Exception")
)
def test_get_bandit_action_bandit_logger_error(patched_mock_assignment_logger):
client = get_instance()
actions = {
Expand Down

0 comments on commit 80470e8

Please sign in to comment.