Skip to content

Commit e1592a8

Browse files
committed
Handle null pointers in rpy2py
Resolves #46 Change-Id: Iae4ad6d272d39d0caebd8173794b3b203c1075c0
1 parent 8f82b12 commit e1592a8

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
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 NULL warning in fetch functions
4+
35
## 1.0.0
46

57
- Simplified authorization process for accessing restricted data via the new `auth()` function

KorAPClient/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ def _rpy2py_robject(listObject):
3535

3636
robjects.conversion.set_conversion(robjects.default_converter + pandas2ri.converter + korapclient_converter)
3737

38-
fix_lists_in_dataframes = robjects.default_converter
38+
fix_null_types = robjects.default_converter
39+
40+
@fix_null_types.rpy2py.register(NULLType)
41+
def to_str(obj):
42+
return ""
3943

44+
fix_lists_in_dataframes = robjects.default_converter
4045

4146
@fix_lists_in_dataframes.rpy2py.register(StrSexpVector)
4247
def to_str(obj):

KorAPClient/tests/test_korapclient.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,17 @@ def test_unchained_fetch_matches(self):
160160
self.assertEqual(len(q.slots['collectedMatches']), 220)
161161
self.assertIsInstance(q.slots['collectedMatches']['tokens.match'].iloc[0], str)
162162

163+
def test_null_strings_are_handled(self):
164+
q = self.kcon.corpusQuery("Der", vc="corpusSigle=WPD17", metadataOnly=False).fetchNext()
165+
matches = q.slots['collectedMatches']
166+
self.assertFalse(
167+
matches['tokens.left'].str.contains("rpy2.rinterface_lib.sexp.NULLType", na=False).any(),
168+
"The string 'rpy2.rinterface_lib.sexp.NULLType' was found in tokens.left!"
169+
)
170+
self.assertFalse(
171+
matches['tokens.right'].str.contains("rpy2.rinterface_lib.sexp.NULLType", na=False).any(),
172+
"The string 'rpy2.rinterface_lib.sexp.NULLType' was found in tokens.right!"
173+
)
174+
163175
if __name__ == '__main__':
164176
unittest.main()

0 commit comments

Comments
 (0)