Skip to content

Commit

Permalink
add support for r list with no names r_to_python
Browse files Browse the repository at this point in the history
  • Loading branch information
DE0CH committed Dec 12, 2022
1 parent 1a0eb26 commit 28cfb2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/irace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def r_to_python(data):
with localconverter(irace_converter):
return ro.conversion.rpy2py(data)
elif data.rclass[0] == 'list':
return OrderedDict(zip(data.names, [r_to_python(elt) for elt in data]))
if isinstance(data.names, ri.NULLType):
keys = range(len(data))
else:
keys = data.names
return OrderedDict(zip(keys, [r_to_python(elt) for elt in data]))
elif data.rclass[0] in ['numeric','logical','integer','RTYPES.INTSXP','array','RTYPES.LGLSXP']:
if len(data) == 1:
return data[0]
Expand Down
7 changes: 7 additions & 0 deletions tests/test_r_to_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rpy2.robjects import r
from irace import r_to_python
from collections import OrderedDict

def test_no_name_list():
s = r('list(1, 2, "b", 3)')
assert r_to_python(s) == OrderedDict(zip((0, 1, 2, 3), (1, 2, 'b', 3)))

0 comments on commit 28cfb2a

Please sign in to comment.