Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions biolearn/imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def impute_from_standard(dnam, cpg_source, cpgs_to_impute=None):
pd.DataFrame: DataFrame with missing values filled.
"""
if cpgs_to_impute:
dnam = dnam.reindex(dnam.index.union(cpgs_to_impute))
impute_rows = dnam.loc[cpgs_to_impute]
impute_rows = impute_rows.apply(lambda col: col.fillna(cpg_source))
df_filled = dnam.combine_first(impute_rows)
Expand Down
9 changes: 9 additions & 0 deletions biolearn/test/test_imputation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ def test_impute_from_standard():
assert df_filled.loc["cpg2", "Sample1"] == 2.5


def test_impute_from_standard_adds_missing_cpgs():
cpgs_with_missing = ["cpg1", "cpg5"]
df_filled = impute_from_standard(
df_test, cpg_averages_test, cpgs_to_impute=cpgs_with_missing
)
assert "cpg5" in df_filled.index
assert df_filled.loc["cpg5", "Sample1"] == 5.5


def test_impute_from_standard_specific_cpgs():
specific_cpgs = ["cpg1", "cpg3"]
df_filled = impute_from_standard(
Expand Down