Skip to content

Commit

Permalink
Switch error type and raise error when file missing
Browse files Browse the repository at this point in the history
  • Loading branch information
agitter committed Jun 14, 2024
1 parent ee10817 commit 1841f65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra
p = PurePath(file)
edge_tuples.append((p.parts[-2], edges))

except FileNotFoundError:
print(file, ' not found during ML analysis') # should not hit this
continue
except FileNotFoundError as exc:
raise FileNotFoundError(str(file) + ' not found during ML analysis') from exc

# initially construct separate dataframes per algorithm
edge_dataframes = []
Expand All @@ -84,10 +83,10 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra

# don't do ml post-processing if there is an empty dataframe or the number of samples is <= 1
if concated_df.empty:
raise OSError("ML post-processing cannot proceed because the summarize network dataframe is empty.\nWe "
raise ValueError("ML post-processing cannot proceed because the summarize network dataframe is empty.\nWe "
"suggest setting ml include: false in the configuration file to avoid this error.")
if min(concated_df.shape) <= 1:
raise OSError(f"ML post-processing cannot proceed because the available number of pathways is insufficient. "
raise ValueError(f"ML post-processing cannot proceed because the available number of pathways is insufficient. "
f"The ml post-processing requires more than one pathway, but currently "
f"there are only {min(concated_df.shape)} pathways.")

Expand Down
6 changes: 3 additions & 3 deletions test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def test_summarize_networks(self):
assert filecmp.cmp(OUT_DIR + 'dataframe.csv', EXPECT_DIR + 'expected-dataframe.csv', shallow=False)

def test_summarize_networks_empty(self):
with pytest.raises(OSError): #raises error if empty dataframe is used for post processing
ml.summarize_networks([INPUT_DIR + 'test-data-empty/empty.txt'])
with pytest.raises(ValueError): #raises error if empty dataframe is used for post processing
ml.summarize_networks([INPUT_DIR + 'test-data-empty/emptya.txt'])

def test_single_line(self):
with pytest.raises(OSError): #raises error if single line in file s.t. single row in dataframe is used for post processing
with pytest.raises(ValueError): #raises error if single line in file s.t. single row in dataframe is used for post processing
ml.summarize_networks([INPUT_DIR + 'test-data-single/single.txt'])

def test_pca(self):
Expand Down

0 comments on commit 1841f65

Please sign in to comment.