Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

summarize_networks InvalidIndexError #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 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')]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataframe = dataframe[~dataframe.index.duplicated(keep='first')]
# Mark the first occurrence of a duplicate as True and all others as False
# Non-duplicates are also marked as True
dataframe = dataframe[~dataframe.index.duplicated(keep='first')]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a warning that edges are being dropped from a file

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is hard to do here, we can think about whether it should be handled somewhere else. For instance, should the parse_output functions check for duplicate edges and raise a warning or error?

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: 5 additions & 0 deletions test/ml/input/test-repeat-edges/repeat.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Node1 Node2 Rank Direction
A B 1 U
C D 1 U
E F 1 U
A B 1 U
2 changes: 1 addition & 1 deletion 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 Down
Loading