Skip to content

Commit cca1aab

Browse files
committed
Merge pull request #8400 from benjschiller/master
add support for numpy 1.8+ data types for conversion to r dataframe
2 parents 0f83679 + 70f11e4 commit cca1aab

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

doc/source/v0.15.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ API changes
271271
- ``DataFrame.info()`` now ends its output with a newline character (:issue:`8114`)
272272
- add ``copy=True`` argument to ``pd.concat`` to enable pass thru of complete blocks (:issue:`8252`)
273273

274-
274+
- Added support for numpy 1.8+ data types (bool_, int_, float_, string_) for conversion to R dataframe (:issue:`8400`)
275275

276276
.. _whatsnew_0150.dt:
277277

pandas/rpy/common.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
from __future__ import print_function
66

7+
from distutils.version import LooseVersion
78
from pandas.compat import zip, range
89
import 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+
271273
NA_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+
282294
def convert_to_r_dataframe(df, strings_as_factors=False):
283295
"""
284296
Convert a pandas DataFrame to a R data.frame.

0 commit comments

Comments
 (0)