Skip to content

Commit

Permalink
fix InvalidIndexError
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalluri committed Oct 25, 2024
1 parent 849ebc4 commit f55855a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def summarize_networks(file_paths: Iterable[Union[str, PathLike]]) -> pd.DataFra
str(tup[0]): 1,
}, index=tup[1]
)
dataframe = dataframe[~dataframe.index.duplicated(keep='first')]
edge_dataframes.append(dataframe)

# concatenating all the algorithm-specific dataframes together
Expand Down
32 changes: 16 additions & 16 deletions test/ml/expected/expected-dataframe.csv
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
,test-data-s1,test-data-s2,test-data-s3,test-data-longName,test-data-longName2,test-data-empty,test-data-spaces,test-data-mixed-direction
A---B,1,1,0,0,0,0,0,0
C---D,1,1,0,0,0,0,0,1
E---F,1,1,0,0,0,0,0,1
L---M,0,1,1,0,0,0,1,0
M---N,0,0,1,0,0,0,0,0
O---P,0,0,1,0,0,0,1,0
P---Q,0,0,1,0,0,0,0,0
node1---node2,0,0,0,1,0,0,0,0
node1---node3,0,0,0,1,1,0,0,0
node4---node5,0,0,0,1,1,0,0,0
LONGERNAMES---TEST,0,0,0,1,1,0,0,0
node2---node3,0,0,0,0,1,0,0,0
nodes with---spaces in name,0,0,0,0,0,0,1,0
A-->B,0,0,0,0,0,0,0,1
B-->A,0,0,0,0,0,0,0,1
,test-data-s1,test-data-s2,test-data-s3,test-data-longName,test-data-longName2,test-data-empty,test-data-spaces,test-data-mixed-direction,test-repeat-edges
A---B,1,1,0,0,0,0,0,0,1
C---D,1,1,0,0,0,0,0,1,1
E---F,1,1,0,0,0,0,0,1,1
L---M,0,1,1,0,0,0,1,0,0
M---N,0,0,1,0,0,0,0,0,0
O---P,0,0,1,0,0,0,1,0,0
P---Q,0,0,1,0,0,0,0,0,0
node1---node2,0,0,0,1,0,0,0,0,0
node1---node3,0,0,0,1,1,0,0,0,0
node4---node5,0,0,0,1,1,0,0,0,0
LONGERNAMES---TEST,0,0,0,1,1,0,0,0,0
node2---node3,0,0,0,0,1,0,0,0,0
nodes with---spaces in name,0,0,0,0,0,0,1,0,0
A-->B,0,0,0,0,0,0,0,1,0
B-->A,0,0,0,0,0,0,0,1,0
5 changes: 1 addition & 4 deletions test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setup_class(cls):
def test_summarize_networks(self):
dataframe = ml.summarize_networks([INPUT_DIR + 'test-data-s1/s1.txt', INPUT_DIR + 'test-data-s2/s2.txt', INPUT_DIR + 'test-data-s3/s3.txt',
INPUT_DIR + 'test-data-longName/longName.txt', INPUT_DIR + 'test-data-longName2/longName2.txt',
INPUT_DIR + 'test-data-empty/empty.txt', INPUT_DIR + 'test-data-spaces/spaces.txt', INPUT_DIR + 'test-data-mixed-direction/mixed-direction.txt'])
INPUT_DIR + 'test-data-empty/empty.txt', INPUT_DIR + 'test-data-spaces/spaces.txt', INPUT_DIR + 'test-data-mixed-direction/mixed-direction.txt', INPUT_DIR + 'test-repeat-edges/repeat.txt'])
dataframe.to_csv(OUT_DIR + 'dataframe.csv')
assert filecmp.cmp(OUT_DIR + 'dataframe.csv', EXPECT_DIR + 'expected-dataframe.csv', shallow=False)

Expand All @@ -42,9 +42,6 @@ def test_summarize_networks_wrong_direction(self):
with pytest.raises(ValueError):
ml.summarize_networks([INPUT_DIR + 'test-data-wrong-direction/wrong-direction.txt'])

def test_repeat_edges(self):
ml.summarize_networks([INPUT_DIR + 'test-data-s1/s1.txt', INPUT_DIR + 'test-repeat-edges/repeat.txt'])

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

0 comments on commit f55855a

Please sign in to comment.