From 2caf314a29029563354221a594663f1fe188d7d9 Mon Sep 17 00:00:00 2001 From: marimeireles Date: Fri, 18 Aug 2023 14:49:32 -0400 Subject: [PATCH] Fixes /delayed_impact/fico.py bug --- whynot/simulators/delayed_impact/fico.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/whynot/simulators/delayed_impact/fico.py b/whynot/simulators/delayed_impact/fico.py index bc40205..41e5c2b 100644 --- a/whynot/simulators/delayed_impact/fico.py +++ b/whynot/simulators/delayed_impact/fico.py @@ -118,15 +118,17 @@ def _get_pmf(cdf): def _loan_repaid_probs_factory( repay_df: DataFrame, scores: Index ) -> Iterable[Callable[[Array], Array]]: - """Given performance pd.DataFrame, construct mapping from X to p(Y|X).""" def repaid_probs_fn(query_scores: Array) -> Array: if isinstance(query_scores, np.ndarray): nearest_scores = _find_nearest_indices(scores, query_scores) - return repay_df[nearest_scores].values + return repay_df.iloc[nearest_scores].values query_score = query_scores - nearest_score = scores[scores.get_loc(query_score, method="nearest")] + nearest_score_idx = scores.get_indexer([query_score], method="nearest")[0] + if nearest_score_idx == -1: + raise ValueError(f"Query score {query_score} has no nearest value in scores.") + nearest_score = scores[nearest_score_idx] return repay_df[nearest_score] return repaid_probs_fn