Show More
@@ -1,7 +1,10 b'' | |||
|
1 | from StringIO import StringIO | |
|
2 | ||
|
1 | 3 | import numpy as np |
|
2 | 4 | from IPython.core.interactiveshell import InteractiveShell |
|
3 | 5 | from IPython.testing.decorators import skip_without |
|
4 | 6 | from IPython.extensions import rmagic |
|
7 | from rpy2 import rinterface | |
|
5 | 8 | import nose.tools as nt |
|
6 | 9 | |
|
7 | 10 | ip = get_ipython() |
@@ -36,10 +39,19 b' def test_push_dataframe():' | |||
|
36 | 39 | df = DataFrame([{'a': 1, 'b': 'bar'}, {'a': 5, 'b': 'foo', 'c': 20}]) |
|
37 | 40 | ip.push({'df':df}) |
|
38 | 41 | ip.run_line_magic('Rpush', 'df') |
|
42 | ||
|
43 | # This is converted to factors, which are currently converted back to Python | |
|
44 | # as integers, so for now we test its representation in R. | |
|
45 | sio = StringIO() | |
|
46 | rinterface.set_writeconsole(sio.write) | |
|
47 | try: | |
|
48 | rm.r('print(df$b[1])') | |
|
49 | nt.assert_in('[1] bar', sio.getvalue()) | |
|
50 | finally: | |
|
51 | rinterface.set_writeconsole(None) | |
|
52 | ||
|
39 | 53 | # Values come packaged in arrays, so we unbox them to test. |
|
40 | nt.assert_equal(rm.r('df$b[1]')[0], 'bar') | |
|
41 | 54 | nt.assert_equal(rm.r('df$a[2]')[0], 5) |
|
42 | ||
|
43 | 55 | missing = rm.r('df$c[1]')[0] |
|
44 | 56 | assert np.isnan(missing), missing |
|
45 | 57 |
General Comments 0
You need to be logged in to leave comments.
Login now