Skip to content

Commit

Permalink
patched pandas 2.2.0 bug (#129)
Browse files Browse the repository at this point in the history
Closes #128
  • Loading branch information
jgallowa07 authored Jan 30, 2024
1 parent 9558fe2 commit 06200f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
4 changes: 1 addition & 3 deletions multidms/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,7 @@ def get_nis_from_site_map(site_map):
times_seen = times_seen.astype(int)
times_seen.index.name = "mutation"
times_seen.name = f"times_seen_{condition}"
mut_df = mut_df.merge(
times_seen, left_on="mutation", right_on="mutation", how="outer"
).fillna(0)
mut_df = mut_df.merge(times_seen, on="mutation", how="left").fillna(0)

self._mutations_df = mut_df
self._name = name if isinstance(name, str) else f"Data-{Data.counter}"
Expand Down
12 changes: 12 additions & 0 deletions multidms/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,18 @@ def get_mutations_df(
inplace=True,
)

# make sure the mutations_df matches the binarymaps
for condition in self.data.conditions:
assert onp.all(
mutations_df.index.values == self.data.binarymaps[condition].all_subs
), f"mutations_df does not match binarymaps for condition {condition}"

# make sure the indices into the bmap are ordered 0-n
for i, sub in enumerate(mutations_df.index.values):
assert sub == self.data.binarymaps[self.data.reference].i_to_sub(
i
), f"mutation {sub} df index does not match binarymaps respective index"

# for effect calculation
if phenotype_as_effect:
wildtype_df = self.wildtype_df
Expand Down
5 changes: 3 additions & 2 deletions multidms/model_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def fit_one_model(
del fit_attributes["dataset"]
del fit_attributes["verbose"]

fit_attributes["step_loss"] = onp.zeros(num_training_steps)
fit_attributes["step_loss"] = onp.zeros(num_training_steps + 1)
fit_attributes["step_loss"][0] = float(imodel.loss)
fit_attributes["dataset_name"] = dataset.name
fit_attributes["model"] = imodel

Expand Down Expand Up @@ -199,7 +200,7 @@ def fit_one_model(
if onp.isnan(float(imodel.loss)):
break

fit_attributes["step_loss"][training_step] = float(imodel.loss)
fit_attributes["step_loss"][training_step + 1] = float(imodel.loss)

if verbose:
print(
Expand Down
10 changes: 5 additions & 5 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_site_integrity():
def test_bmap_mut_df_order():
"""
Assert that the binarymap rows and columns match
mutations_df indicies exactly.
mutations_df indices exactly.
"""
mut_df = data.mutations_df
for condition in data.conditions:
Expand Down Expand Up @@ -124,14 +124,14 @@ def test_invalid_non_identical_sites():
assert data.reference_sequence_conditions == ["a", "b"]


def test_converstion_from_subs():
def test_conversion_from_subs():
"""Make sure that the conversion from each reference choice is correct"""
for ref, bundle in zip(["a", "b"], ["G3P", "P3G"]):
data = multidms.Data(TEST_FUNC_SCORES, reference=ref)
assert data.convert_subs_wrt_ref_seq(("b" if ref == "a" else "a"), "") == bundle


def test_wildtype_mutatant_predictions():
def test_wildtype_mutant_predictions():
"""
test that the wildtype predictions are correct
by comparing them to a "by-hand" calculation on the parameters.
Expand Down Expand Up @@ -244,7 +244,7 @@ def test_non_identical_conversion():

def test_model_PRNGKey():
"""
Simply test the instatiation of a model with different PNRG keys
Simply test the instantiation of a model with different PRNG keys
to make sure the seed structure truly ensures the same parameter
initialization values
"""
Expand All @@ -257,7 +257,7 @@ def test_model_PRNGKey():
def test_lower_bound():
"""
Make sure that the softplus lower bound is correct
by initializing a sofplus activation models and asserting
by initializing a softplus activation models and asserting
predictions never go below the specified lower bound.
even if that lower bound is high!
Expand Down

0 comments on commit 06200f6

Please sign in to comment.