Fix chaining of fetch methods
Change-Id: I344bd4697a5a28bae6149063a7cb67c22b0a589a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bab23fc..c09271e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
# Version history
+- Fixed chainability of fetch methods in `corpusQuery`
+
## 0.9.0
- Updates recommended RKorAPClient version to 0.9.0
diff --git a/KorAPClient/__init__.py b/KorAPClient/__init__.py
index 35c4c3a..82f0501 100644
--- a/KorAPClient/__init__.py
+++ b/KorAPClient/__init__.py
@@ -312,7 +312,8 @@
with localconverter(fix_lists_in_dataframes):
df = res.slots['collectedMatches']
res.slots['collectedMatches'] = df
- return res
+ super().__init__(res)
+ return self
def fetchRest(self, *args, **kwargs):
"""Fetch remaining query results
@@ -326,7 +327,8 @@
with localconverter(fix_lists_in_dataframes):
df = res.slots['collectedMatches']
res.slots['collectedMatches'] = df
- return res
+ super().__init__(res)
+ return self
def fetchAll(self, *args, **kwargs):
"""Fetch all query results
@@ -343,5 +345,6 @@
with localconverter(fix_lists_in_dataframes):
df = res.slots['collectedMatches']
res.slots['collectedMatches'] = df
- return res
+ super().__init__(res)
+ return self
diff --git a/KorAPClient/tests/test_korapclient.py b/KorAPClient/tests/test_korapclient.py
index d4673b3..c5a36a6 100644
--- a/KorAPClient/tests/test_korapclient.py
+++ b/KorAPClient/tests/test_korapclient.py
@@ -136,6 +136,29 @@
self.assertGreater(min(df['KED.rcpnt'].str.len()), 5)
+# def test_authorization(self):
+# kcon = KorAPConnection(accessToken=NULL, verbose=True).auth()
+# self.assertIsNotNone(kcon.slots['accessToken'])
+
+ def test_chained_fetch_matches(self):
+ q = (
+ self.kcon.corpusQuery("Test", metadataOnly=False)
+ .fetchNext(maxFetch=120)
+ .fetchNext()
+ .fetchNext()
+ )
+ self.assertIn('collectedMatches', q.slots)
+ self.assertEqual(len(q.slots['collectedMatches']), 220)
+ self.assertIsInstance(q.slots['collectedMatches']['tokens.match'].iloc[0], str)
+
+ def test_unchained_fetch_matches(self):
+ q = self.kcon.corpusQuery("Test", metadataOnly=False)
+ q.fetchNext(maxFetch=120)
+ q.fetchNext()
+ q.fetchNext()
+ self.assertIn('collectedMatches', q.slots)
+ self.assertEqual(len(q.slots['collectedMatches']), 220)
+ self.assertIsInstance(q.slots['collectedMatches']['tokens.match'].iloc[0], str)
if __name__ == '__main__':
unittest.main()