44"""
55from __future__ import print_function
66
7+ from distutils .version import LooseVersion
78from pandas .compat import zip , range
89import numpy as np
910
@@ -72,7 +73,7 @@ def _list(item):
7273 return list (item )
7374 except TypeError :
7475 return []
75-
76+
7677 # For iris3, HairEyeColor, UCBAdmissions, Titanic
7778 dim = list (obj .dim )
7879 values = np .array (list (obj ))
@@ -101,9 +102,9 @@ def _convert_vector(obj):
101102 except AttributeError :
102103 return list (obj )
103104 if 'names' in attributes :
104- return pd .Series (list (obj ), index = r ['names' ](obj ))
105+ return pd .Series (list (obj ), index = r ['names' ](obj ))
105106 elif 'tsp' in attributes :
106- return pd .Series (list (obj ), index = r ['time' ](obj ))
107+ return pd .Series (list (obj ), index = r ['time' ](obj ))
107108 elif 'labels' in attributes :
108109 return pd .Series (list (obj ), index = r ['labels' ](obj ))
109110 if _rclass (obj ) == 'dist' :
@@ -268,6 +269,7 @@ def convert_to_r_posixct(obj):
268269 np .str : robj .StrVector ,
269270 np .bool : robj .BoolVector }
270271
272+
271273NA_TYPES = {np .float64 : robj .NA_Real ,
272274 np .float32 : robj .NA_Real ,
273275 np .float : robj .NA_Real ,
@@ -279,6 +281,16 @@ def convert_to_r_posixct(obj):
279281 np .bool : robj .NA_Logical }
280282
281283
284+ if LooseVersion (np .__version__ ) >= LooseVersion ('1.8' ):
285+ for dict_ in (VECTOR_TYPES , NA_TYPES ):
286+ dict_ .update ({
287+ np .bool_ : dict_ [np .bool ],
288+ np .int_ : dict_ [np .int ],
289+ np .float_ : dict_ [np .float ],
290+ np .string_ : dict_ [np .str ]
291+ })
292+
293+
282294def convert_to_r_dataframe (df , strings_as_factors = False ):
283295 """
284296 Convert a pandas DataFrame to a R data.frame.
0 commit comments