Repository: umitkaanusta/reddit-detective (language: python)

Issue:
Change Docstring at Relationships.py->Comments: COMMENTED to AUTHORED


https://github.com/umitkaanusta/reddit-detective/blob/0c8209df7910f61bb67d1bbfaaefe1f8abec5dd7/reddit_detective/relationships.py#L95


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 6d29b22..1181581 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@ how Redditors behave.
 Knowing Cypher dramatically increases what you can do with reddit-detective 
 [Click here to learn Cypher](https://neo4j.com/graphacademy/online-training/introduction-to-neo4j-40/)
 - Install reddit-detective with `pip install reddit_detective`
+    - **Note:** Version 0.1.2 is broken, any other version is fine
 
 
 ## Code Samples
diff --git a/docs/index.md b/docs/index.md
index 6d29b22..1181581 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -29,6 +29,7 @@ how Redditors behave.
 Knowing Cypher dramatically increases what you can do with reddit-detective 
 [Click here to learn Cypher](https://neo4j.com/graphacademy/online-training/introduction-to-neo4j-40/)
 - Install reddit-detective with `pip install reddit_detective`
+    - **Note:** Version 0.1.2 is broken, any other version is fine
 
 
 ## Code Samples
diff --git a/reddit_detective/__init__.py b/reddit_detective/__init__.py
index 0703953..ea52599 100644
--- a/reddit_detective/__init__.py
+++ b/reddit_detective/__init__.py
@@ -1,4 +1,4 @@
 from reddit_detective.network import RedditNetwork
 from reddit_detective.relationships import Comments, CommentsReplies, Submissions
 
-VERSION = "0.1.2"
+VERSION = "0.1.3"
diff --git a/reddit_detective/network.py b/reddit_detective/network.py
index ecbdabf..ca1f8b0 100644
--- a/reddit_detective/network.py
+++ b/reddit_detective/network.py
@@ -80,7 +80,10 @@ def _codes(self):
         """
         Get codes for every component
         """
-        return list(chain.from_iterable([point.code() for point in self.components]))
+        codes = list(chain.from_iterable([point.code() for point in self.components]))
+        # Remove duplicates without changing order
+        codes = sorted(set(codes), key=lambda x: codes.index(x))
+        return codes
 
     def cypher_code(self):
         """
diff --git a/reddit_detective/relationships.py b/reddit_detective/relationships.py
index 2309148..1074a9a 100644
--- a/reddit_detective/relationships.py
+++ b/reddit_detective/relationships.py
@@ -84,7 +84,7 @@ def _merge_and_link_submissions(self, submission_list):
 
     def code(self):
         merges, links = self._merge_and_link_submissions(self.start.submissions())
-        return list(set(merges + links))
+        return merges + links
 
 
 class Comments(Submissions):
@@ -92,7 +92,7 @@ class Comments(Submissions):
     Degree 2: Comments
     Starting points: Subreddit, Submission, Redditor
         All of Degree 1
-        Link redditors with subreddits via comments (COMMENTED)
+        Link redditors with submissions via comments (AUTHORED)
     """
     def __init__(self, starting_point: Union[Subreddit, Submission, Redditor]):
         if "comments" not in starting_point.available_degrees:
@@ -129,14 +129,14 @@ def _merge_and_link_comments(self, comment_list):
                 author_code = comment_instance.author.merge_code()
                 if author_code not in authors:
                     authors.append(author_code)
-
+                
                 author_links.append(_link_nodes(
                     comment_instance.author_id,
                     comment.id,
                     Relationships.authored,
                     props
                 ))
-
+            
             parent_links.append(_link_nodes(
                 comment.id,
                 comment.parent_id[3:],
@@ -144,14 +144,16 @@ def _merge_and_link_comments(self, comment_list):
                 props
             ))
 
-            submissions.append(Submission(self.start.api, comment.submission.id, limit=None))
-
-        return comment_codes + authors, parent_links + author_links, list(set(submissions))
+            sub = Submission(self.start.api, comment.submission.id, limit=None)
+            if sub not in submissions:
+                submissions.append(sub)
+        
+        return comment_codes + authors, parent_links + author_links, submissions
     
     def code(self):
         comment_merges, comment_links, submissions = self._merge_and_link_comments(self.comments())
         sub_merges, sub_links = self._merge_and_link_submissions(submissions)
-        return list(set(comment_merges + sub_merges + comment_links + sub_links))
+        return comment_merges + sub_merges + comment_links + sub_links
 
 
 class CommentsReplies(Comments):


Test patch:
diff --git a/tests/test_network.py b/tests/test_network.py
index 8823d05..302ae10 100644
--- a/tests/test_network.py
+++ b/tests/test_network.py
@@ -19,7 +19,6 @@ def test_network():
         ]
     )
     assert net
-    assert len(set(net._codes())) == len(net._codes())
     assert net.cypher_code()
     net.run_cypher_code()
 
diff --git a/tests/test_relationships.py b/tests/test_relationships.py
index 5a38ab9..c294361 100644
--- a/tests/test_relationships.py
+++ b/tests/test_relationships.py
@@ -6,16 +6,13 @@
     Constraint codes to be run when manually testing in Neo4j:
     
     CREATE CONSTRAINT UniqueRedditor
-        ON (r:Redditor) ASSERT (r.id) IS UNIQUE;
+    ON (r:Redditor) ASSERT (r.id) IS UNIQUE
     
     CREATE CONSTRAINT UniqueSubmission
-        ON (sm:Submission) ASSERT (sm.id) IS UNIQUE;
+    ON (sm:Submission) ASSERT (sm.id) IS UNIQUE
     
     CREATE CONSTRAINT UniqueSubreddit
-        ON (sr:Subreddit) ASSERT (sr.id) IS UNIQUE;
-    
-    CREATE CONSTRAINT UniqueComment
-        ON (c:Comment) ASSERT (c.id) IS UNIQUE;
+    ON (sr:Subreddit) ASSERT (sr.id) IS UNIQUE
 """
 
 
@@ -24,26 +21,22 @@ def test_submissions():
     submissions_red = Submissions(red)
     sub = Subreddit(api_, "learnpython", limit=2)
     submissions_sub = Submissions(sub)
-    red_code = submissions_red.code()
-    sub_code = submissions_sub.code()
-    assert len(set(red_code)) == len(red_code)
-    assert len(set(sub_code)) == len(sub_code)
+    assert submissions_red.code()
+    assert submissions_sub.code()
 
 
 def test_comments():
     red = Redditor(api_, "Anub_Rekhan", limit=2, indexing="new")
     comments_red = Comments(red)
     assert comments_red.comments()
-    comm_code = comments_red.code()
-    assert len(set(comm_code)) == len(comm_code)
+    assert comments_red.code()
 
 
 def test_replies():
-    sub = Subreddit(api_, "learnpython", limit=2, indexing="new")
+    sub = Subreddit(api_, "learnpython", limit=2, indexing="hot")
     replies_sub = CommentsReplies(sub)
     assert replies_sub.comments()
-    repl_code = replies_sub.code()
-    assert len(set(repl_code)) == len(repl_code)
+    assert replies_sub.code()
 
 
 def run():