Show More
@@ -1,7 +1,10 b'' | |||||
|
1 | from StringIO import StringIO | |||
|
2 | ||||
1 | import numpy as np |
|
3 | import numpy as np | |
2 | from IPython.core.interactiveshell import InteractiveShell |
|
4 | from IPython.core.interactiveshell import InteractiveShell | |
3 | from IPython.testing.decorators import skip_without |
|
5 | from IPython.testing.decorators import skip_without | |
4 | from IPython.extensions import rmagic |
|
6 | from IPython.extensions import rmagic | |
|
7 | from rpy2 import rinterface | |||
5 | import nose.tools as nt |
|
8 | import nose.tools as nt | |
6 |
|
9 | |||
7 | ip = get_ipython() |
|
10 | ip = get_ipython() | |
@@ -36,10 +39,19 b' def test_push_dataframe():' | |||||
36 | df = DataFrame([{'a': 1, 'b': 'bar'}, {'a': 5, 'b': 'foo', 'c': 20}]) |
|
39 | df = DataFrame([{'a': 1, 'b': 'bar'}, {'a': 5, 'b': 'foo', 'c': 20}]) | |
37 | ip.push({'df':df}) |
|
40 | ip.push({'df':df}) | |
38 | ip.run_line_magic('Rpush', 'df') |
|
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 | # Values come packaged in arrays, so we unbox them to test. |
|
53 | # Values come packaged in arrays, so we unbox them to test. | |
40 | nt.assert_equal(rm.r('df$b[1]')[0], 'bar') |
|
|||
41 | nt.assert_equal(rm.r('df$a[2]')[0], 5) |
|
54 | nt.assert_equal(rm.r('df$a[2]')[0], 5) | |
42 |
|
||||
43 | missing = rm.r('df$c[1]')[0] |
|
55 | missing = rm.r('df$c[1]')[0] | |
44 | assert np.isnan(missing), missing |
|
56 | assert np.isnan(missing), missing | |
45 |
|
57 |
General Comments 0
You need to be logged in to leave comments.
Login now