Skip to content

Commit

Permalink
change 'Invalid feature' error to warning
Browse files Browse the repository at this point in the history
  • Loading branch information
andrefaure committed Aug 6, 2024
1 parent fdc1a10 commit 2db313c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
16 changes: 10 additions & 6 deletions pymochi/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,9 +966,11 @@ def one_hot_encode_interactions(
all_features_flat = list(itertools.chain(*list(all_features.values())))

#Check if all interaction features exist (i.e. with mutation order>1)
if len([i for i in features if (i not in all_features_flat) and (len(i.split('_'))>1)]) != 0:
print("Error: Invalid feature names.")
raise ValueError
invalid_features = [i for i in features if (i not in all_features_flat) and (len(i.split('_'))>1)]
if len(invalid_features) != 0:
# print("Error: Invalid feature names.")
print("Warning: Invalid feature names: "+",".join(invalid_features))
# raise ValueError

#Select interactions
int_list = []
Expand Down Expand Up @@ -1059,9 +1061,11 @@ def filter_features(
:returns: filtered DataFrame.
"""
#Check if all features exist
if len([i for i in features if i not in input_df.columns]) != 0:
print("Error: Invalid feature names.")
raise ValueError
invalid_features = [i for i in features if i not in input_df.columns]
if len(invalid_features) != 0:
# print("Error: Invalid feature names.")
print("Warning: Invalid feature names: "+",".join(invalid_features))
# raise ValueError
#Filter features
features_order = [i for i in input_df.columns if i in features]
return input_df.loc[:,features_order]
Expand Down
34 changes: 17 additions & 17 deletions pymochi/tests/test_pymochi.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,23 @@ def test_MochiData_invalid_features_argument_trait_names(capsys):
captured = capsys.readouterr()
assert captured.out == "Error: One or more invalid trait names in 'features' argument.\n" and e_info

def test_MochiData_invalid_features_argument_features(capsys):
"""Test MochiData initialization with invalid features argument features"""
model_design = pd.read_csv(Path(__file__).parent.parent / "data/model_design.txt", sep = "\t", index_col = False)
model_design['file'] = [
str(Path(__file__).parent.parent / "data/fitness_abundance.txt"),
str(Path(__file__).parent.parent / "data/fitness_binding.txt")]
#Create a problematic features dict
features = {
'Folding': ["WT"],
'Binding': ["WT", "Hello World!"]}
with pytest.raises(ValueError) as e_info:
MochiData(
model_design = model_design,
features = features)
captured = capsys.readouterr()
print(captured.out)
assert captured.out.split("\n")[-2] == "Error: Invalid feature names." and e_info
# def test_MochiData_invalid_features_argument_features(capsys):
# """Test MochiData initialization with invalid features argument features"""
# model_design = pd.read_csv(Path(__file__).parent.parent / "data/model_design.txt", sep = "\t", index_col = False)
# model_design['file'] = [
# str(Path(__file__).parent.parent / "data/fitness_abundance.txt"),
# str(Path(__file__).parent.parent / "data/fitness_binding.txt")]
# #Create a problematic features dict
# features = {
# 'Folding': ["WT"],
# 'Binding': ["WT", "Hello World!"]}
# with pytest.raises(ValueError) as e_info:
# MochiData(
# model_design = model_design,
# features = features)
# captured = capsys.readouterr()
# print(captured.out)
# assert captured.out.split("\n")[-2] == "Warning: Invalid feature names: Hello World!" and e_info

def test_MochiData_invalid_features_argument_missingWT(capsys):
"""Test MochiData initialization with invalid features argument missing WT"""
Expand Down

0 comments on commit 2db313c

Please sign in to comment.