Skip to content

Commit 003bc51

Browse files
committed
fix: type def in fs_em_class to appease mypy
1 parent 56700ce commit 003bc51

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/fs_em/fs_em_class.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def fit(
139139
def score(self, comparisons: pd.DataFrame) -> pd.Series:
140140
"""Return FS log2-likelihood ratio scores for each pair."""
141141
self._check_fitted()
142+
assert self.weights_ is not None # narrow Optional for type checker
142143
gamma = comparisons[self.variables_]
143144
w = self.weights_.set_index("variable")
144145

@@ -162,8 +163,12 @@ def predict_proba(
162163
) -> pd.Series:
163164
"""Return posterior P(match | comparisons)."""
164165
self._check_fitted()
165-
prior = float(self.prior_ if prior is None else prior)
166-
k = (1.0 - prior) / prior
166+
assert self.prior_ is not None # narrow Optional for type checker
167+
if prior is None:
168+
p_val = float(self.prior_)
169+
else:
170+
p_val = float(prior)
171+
k = (1.0 - p_val) / p_val
167172
s = self.score(comparisons).to_numpy(float)
168173
return pd.Series(1.0 / (1.0 + k * (2.0 ** (-s))), index=comparisons.index)
169174

0 commit comments

Comments
 (0)