Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix test for rmagic + pandas DataFrame

  • Loading branch information...
commit 3a166bae29f3567f6b6bdf0eaade7660f4e12075 1 parent e2ca7dc
Thomas Kluyver authored

Showing 1 changed file with 14 additions and 2 deletions. Show diff stats Hide diff stats

  1. +14 2 IPython/extensions/tests/test_rmagic.py
16 IPython/extensions/tests/test_rmagic.py
... ... @@ -1,7 +1,10 @@
  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 @@ 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

0 comments on commit 3a166ba

Please sign in to comment.
Something went wrong with that request. Please try again.