4
4
"""
5
5
from __future__ import print_function
6
6
7
+ from distutils .version import LooseVersion
7
8
from pandas .compat import zip , range
8
9
import numpy as np
9
10
@@ -72,7 +73,7 @@ def _list(item):
72
73
return list (item )
73
74
except TypeError :
74
75
return []
75
-
76
+
76
77
# For iris3, HairEyeColor, UCBAdmissions, Titanic
77
78
dim = list (obj .dim )
78
79
values = np .array (list (obj ))
@@ -101,9 +102,9 @@ def _convert_vector(obj):
101
102
except AttributeError :
102
103
return list (obj )
103
104
if 'names' in attributes :
104
- return pd .Series (list (obj ), index = r ['names' ](obj ))
105
+ return pd .Series (list (obj ), index = r ['names' ](obj ))
105
106
elif 'tsp' in attributes :
106
- return pd .Series (list (obj ), index = r ['time' ](obj ))
107
+ return pd .Series (list (obj ), index = r ['time' ](obj ))
107
108
elif 'labels' in attributes :
108
109
return pd .Series (list (obj ), index = r ['labels' ](obj ))
109
110
if _rclass (obj ) == 'dist' :
@@ -268,6 +269,7 @@ def convert_to_r_posixct(obj):
268
269
np .str : robj .StrVector ,
269
270
np .bool : robj .BoolVector }
270
271
272
+
271
273
NA_TYPES = {np .float64 : robj .NA_Real ,
272
274
np .float32 : robj .NA_Real ,
273
275
np .float : robj .NA_Real ,
@@ -279,6 +281,16 @@ def convert_to_r_posixct(obj):
279
281
np .bool : robj .NA_Logical }
280
282
281
283
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
+
282
294
def convert_to_r_dataframe (df , strings_as_factors = False ):
283
295
"""
284
296
Convert a pandas DataFrame to a R data.frame.
0 commit comments