Skip to content

Commit 01cb440

Browse files
DOC: Removing rpy2 dependencies, and converting examples using it to regular code blocks (pandas-dev#23737)
1 parent f0b2ff3 commit 01cb440

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

ci/deps/travis-36-doc.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ name: pandas
22
channels:
33
- defaults
44
- conda-forge
5-
- r
65
dependencies:
76
- beautifulsoup4
87
- bottleneck
@@ -31,14 +30,11 @@ dependencies:
3130
- python-snappy
3231
- python=3.6*
3332
- pytz
34-
- r
35-
- rpy2
3633
- scipy
3734
- seaborn
3835
- sphinx
3936
- sqlalchemy
4037
- statsmodels
41-
- tzlocal
4238
- xarray
4339
- xlrd
4440
- xlsxwriter

doc/source/r_interface.rst

+25-12
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,28 @@ See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project:
3333

3434
In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated:
3535

36-
.. ipython:: python
36+
.. code-block:: python
3737
38-
from rpy2.robjects import r, pandas2ri
39-
pandas2ri.activate()
38+
>>> from rpy2.robjects import pandas2ri # doctest: +SKIP
39+
>>> pandas2ri.activate() # doctest: +SKIP
4040
4141
Transferring R data sets into Python
4242
------------------------------------
4343

4444
Once the pandas conversion is activated (``pandas2ri.activate()``), many conversions
4545
of R to pandas objects will be done automatically. For example, to obtain the 'iris' dataset as a pandas DataFrame:
4646

47-
.. ipython:: python
47+
.. code-block:: python
4848
49-
r.data('iris')
50-
r['iris'].head()
49+
>>> from rpy2.robjects import r # doctest: +SKIP
50+
>>> r.data('iris') # doctest: +SKIP
51+
>>> r['iris'].head() # doctest: +SKIP
52+
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
53+
0 5.1 3.5 1.4 0.2 setosa
54+
1 4.9 3.0 1.4 0.2 setosa
55+
2 4.7 3.2 1.3 0.2 setosa
56+
3 4.6 3.1 1.5 0.2 setosa
57+
4 5.0 3.6 1.4 0.2 setosa
5158
5259
If the pandas conversion was not activated, the above could also be accomplished
5360
by explicitly converting it with the ``pandas2ri.ri2py`` function
@@ -59,13 +66,19 @@ Converting DataFrames into R objects
5966
The ``pandas2ri.py2ri`` function support the reverse operation to convert
6067
DataFrames into the equivalent R object (that is, **data.frame**):
6168

62-
.. ipython:: python
69+
.. code-block:: python
70+
71+
>>> df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]},
72+
... index=["one", "two", "three"]) # doctest: +SKIP
73+
>>> r_dataframe = pandas2ri.py2ri(df) # doctest: +SKIP
74+
>>> print(type(r_dataframe)) # doctest: +SKIP
75+
<class 'rpy2.robjects.vectors.DataFrame'>
76+
>>> print(r_dataframe) # doctest: +SKIP
77+
A B C
78+
one 1 4 7
79+
two 2 5 8
80+
three 3 6 9
6381
64-
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]},
65-
index=["one", "two", "three"])
66-
r_dataframe = pandas2ri.py2ri(df)
67-
print(type(r_dataframe))
68-
print(r_dataframe)
6982
7083
The DataFrame's index is stored as the ``rownames`` attribute of the
7184
data.frame instance.

0 commit comments

Comments
 (0)