Skip to content

Commit f9be0c5

Browse files
committed
Fix chaining of fetch methods
Change-Id: I344bd4697a5a28bae6149063a7cb67c22b0a589a
1 parent 66e8d74 commit f9be0c5

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Version history
22

3+
- Fixed chainability of fetch methods in `corpusQuery`
4+
35
## 0.9.0
46

57
- Updates recommended RKorAPClient version to 0.9.0

KorAPClient/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ def fetchNext(self, *args, **kwargs):
312312
with localconverter(fix_lists_in_dataframes):
313313
df = res.slots['collectedMatches']
314314
res.slots['collectedMatches'] = df
315-
return res
315+
super().__init__(res)
316+
return self
316317

317318
def fetchRest(self, *args, **kwargs):
318319
"""Fetch remaining query results
@@ -326,7 +327,8 @@ def fetchRest(self, *args, **kwargs):
326327
with localconverter(fix_lists_in_dataframes):
327328
df = res.slots['collectedMatches']
328329
res.slots['collectedMatches'] = df
329-
return res
330+
super().__init__(res)
331+
return self
330332

331333
def fetchAll(self, *args, **kwargs):
332334
"""Fetch all query results
@@ -343,5 +345,6 @@ def fetchAll(self, *args, **kwargs):
343345
with localconverter(fix_lists_in_dataframes):
344346
df = res.slots['collectedMatches']
345347
res.slots['collectedMatches'] = df
346-
return res
348+
super().__init__(res)
349+
return self
347350

KorAPClient/tests/test_korapclient.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,29 @@ def test_extended_metadata_fields_ked(self):
136136
self.assertGreater(min(df['KED.rcpnt'].str.len()), 5)
137137

138138

139+
# def test_authorization(self):
140+
# kcon = KorAPConnection(accessToken=NULL, verbose=True).auth()
141+
# self.assertIsNotNone(kcon.slots['accessToken'])
142+
143+
def test_chained_fetch_matches(self):
144+
q = (
145+
self.kcon.corpusQuery("Test", metadataOnly=False)
146+
.fetchNext(maxFetch=120)
147+
.fetchNext()
148+
.fetchNext()
149+
)
150+
self.assertIn('collectedMatches', q.slots)
151+
self.assertEqual(len(q.slots['collectedMatches']), 220)
152+
self.assertIsInstance(q.slots['collectedMatches']['tokens.match'].iloc[0], str)
153+
154+
def test_unchained_fetch_matches(self):
155+
q = self.kcon.corpusQuery("Test", metadataOnly=False)
156+
q.fetchNext(maxFetch=120)
157+
q.fetchNext()
158+
q.fetchNext()
159+
self.assertIn('collectedMatches', q.slots)
160+
self.assertEqual(len(q.slots['collectedMatches']), 220)
161+
self.assertIsInstance(q.slots['collectedMatches']['tokens.match'].iloc[0], str)
139162

140163
if __name__ == '__main__':
141164
unittest.main()

0 commit comments

Comments
 (0)