Skip to content

Commit 7c6b73e

Browse files
jorisvandenbosscheAnkurDedania
authored andcommitted
CLN/DEPR: remove deprecated pandas.rpy module (GH9602)
1 parent 4394e0e commit 7c6b73e

File tree

12 files changed

+27
-766
lines changed

12 files changed

+27
-766
lines changed

ci/lint.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ RET=0
88

99
if [ "$LINT" ]; then
1010

11-
# pandas/rpy is deprecated and will be removed.
1211
# pandas/src is C code, so no need to search there.
1312
echo "Linting *.py"
14-
flake8 pandas --filename=*.py --exclude pandas/rpy,pandas/src
13+
flake8 pandas --filename=*.py --exclude pandas/src
1514
if [ $? -ne "0" ]; then
1615
RET=1
1716
fi

doc/source/r_interface.rst

+22-118
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.. currentmodule:: pandas.rpy
2-
31
.. _rpy:
42

53
.. ipython:: python
@@ -15,157 +13,63 @@ rpy2 / R interface
1513

1614
.. warning::
1715

18-
In v0.16.0, the ``pandas.rpy`` interface has been **deprecated and will be
19-
removed in a future version**. Similar functionality can be accessed
20-
through the `rpy2 <https://rpy2.readthedocs.io/>`__ project.
21-
See the :ref:`updating <rpy.updating>` section for a guide to port your
22-
code from the ``pandas.rpy`` to ``rpy2`` functions.
23-
24-
25-
.. _rpy.updating:
26-
27-
Updating your code to use rpy2 functions
28-
----------------------------------------
29-
30-
In v0.16.0, the ``pandas.rpy`` module has been **deprecated** and users are
31-
pointed to the similar functionality in ``rpy2`` itself (rpy2 >= 2.4).
16+
Up to pandas 0.19, a ``pandas.rpy`` module existed with functionality to
17+
convert between pandas and ``rpy2`` objects. This functionality now lives in
18+
the `rpy2 <https://rpy2.readthedocs.io/>`__ project itself.
19+
See the `updating section <http://pandas.pydata.org/pandas-docs/version/0.19.0/r_interface.html#updating-your-code-to-use-rpy2-functions>`__
20+
of the previous documentation for a guide to port your code from the
21+
removed ``pandas.rpy`` to ``rpy2`` functions.
3222

33-
Instead of importing ``import pandas.rpy.common as com``, the following imports
34-
should be done to activate the pandas conversion support in rpy2::
35-
36-
from rpy2.robjects import pandas2ri
37-
pandas2ri.activate()
3823

24+
`rpy2 <http://rpy2.bitbucket.org/>`__ is an interface to R running embedded in a Python process, and also includes functionality to deal with pandas DataFrames.
3925
Converting data frames back and forth between rpy2 and pandas should be largely
4026
automated (no need to convert explicitly, it will be done on the fly in most
4127
rpy2 functions).
42-
4328
To convert explicitly, the functions are ``pandas2ri.py2ri()`` and
44-
``pandas2ri.ri2py()``. So these functions can be used to replace the existing
45-
functions in pandas:
46-
47-
- ``com.convert_to_r_dataframe(df)`` should be replaced with ``pandas2ri.py2ri(df)``
48-
- ``com.convert_robj(rdf)`` should be replaced with ``pandas2ri.ri2py(rdf)``
49-
50-
Note: these functions are for the latest version (rpy2 2.5.x) and were called
51-
``pandas2ri.pandas2ri()`` and ``pandas2ri.ri2pandas()`` previously.
52-
53-
Some of the other functionality in `pandas.rpy` can be replaced easily as well.
54-
For example to load R data as done with the ``load_data`` function, the
55-
current method::
56-
57-
df_iris = com.load_data('iris')
58-
59-
can be replaced with::
60-
61-
from rpy2.robjects import r
62-
r.data('iris')
63-
df_iris = pandas2ri.ri2py(r[name])
64-
65-
The ``convert_to_r_matrix`` function can be replaced by the normal
66-
``pandas2ri.py2ri`` to convert dataframes, with a subsequent call to R
67-
``as.matrix`` function.
68-
69-
.. warning::
70-
71-
Not all conversion functions in rpy2 are working exactly the same as the
72-
current methods in pandas. If you experience problems or limitations in
73-
comparison to the ones in pandas, please report this at the
74-
`issue tracker <https://github.com/pandas-dev/pandas/issues>`_.
75-
76-
See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project.
77-
29+
``pandas2ri.ri2py()``.
7830

79-
R interface with rpy2
80-
---------------------
8131

82-
If your computer has R and rpy2 (> 2.2) installed (which will be left to the
83-
reader), you will be able to leverage the below functionality. On Windows,
84-
doing this is quite an ordeal at the moment, but users on Unix-like systems
85-
should find it quite easy. rpy2 evolves in time, and is currently reaching
86-
its release 2.3, while the current interface is
87-
designed for the 2.2.x series. We recommend to use 2.2.x over other series
88-
unless you are prepared to fix parts of the code, yet the rpy2-2.3.0
89-
introduces improvements such as a better R-Python bridge memory management
90-
layer so it might be a good idea to bite the bullet and submit patches for
91-
the few minor differences that need to be fixed.
32+
See also the documentation of the `rpy2 <http://rpy2.bitbucket.org/>`__ project: https://rpy2.readthedocs.io.
9233

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

94-
::
95-
96-
# if installing for the first time
97-
hg clone http://bitbucket.org/lgautier/rpy2
98-
99-
cd rpy2
100-
hg pull
101-
hg update version_2.2.x
102-
sudo python setup.py install
103-
104-
.. note::
105-
106-
To use R packages with this interface, you will need to install
107-
them inside R yourself. At the moment it cannot install them for
108-
you.
36+
.. ipython:: python
10937
110-
Once you have done installed R and rpy2, you should be able to import
111-
``pandas.rpy.common`` without a hitch.
38+
from rpy2.robjects import r, pandas2ri
39+
pandas2ri.activate()
11240
11341
Transferring R data sets into Python
11442
------------------------------------
11543

116-
The **load_data** function retrieves an R data set and converts it to the
44+
The ``pandas2ri.ri2py`` function retrieves an R data set and converts it to the
11745
appropriate pandas object (most likely a DataFrame):
11846

119-
12047
.. ipython:: python
121-
:okwarning:
122-
123-
import pandas.rpy.common as com
124-
infert = com.load_data('infert')
12548
126-
infert.head()
49+
r.data('iris')
50+
df_iris = pandas2ri.ri2py(r['iris'])
51+
df_iris.head()
12752
12853
12954
Converting DataFrames into R objects
13055
------------------------------------
13156

132-
.. versionadded:: 0.8
133-
134-
Starting from pandas 0.8, there is **experimental** support to convert
57+
The ``pandas2ri.py2ri`` function support the reverse operation to convert
13558
DataFrames into the equivalent R object (that is, **data.frame**):
13659

13760
.. ipython:: python
13861
139-
import pandas.rpy.common as com
14062
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]},
14163
index=["one", "two", "three"])
142-
r_dataframe = com.convert_to_r_dataframe(df)
143-
64+
r_dataframe = pandas2ri.py2ri(df)
14465
print(type(r_dataframe))
14566
print(r_dataframe)
14667
14768
14869
The DataFrame's index is stored as the ``rownames`` attribute of the
14970
data.frame instance.
15071

151-
You can also use **convert_to_r_matrix** to obtain a ``Matrix`` instance, but
152-
bear in mind that it will only work with homogeneously-typed DataFrames (as
153-
R matrices bear no information on the data type):
15472

155-
156-
.. ipython:: python
157-
158-
import pandas.rpy.common as com
159-
r_matrix = com.convert_to_r_matrix(df)
160-
161-
print(type(r_matrix))
162-
print(r_matrix)
163-
164-
165-
Calling R functions with pandas objects
166-
---------------------------------------
167-
168-
169-
170-
High-level interface to R estimators
171-
------------------------------------
73+
..
74+
Calling R functions with pandas objects
75+
High-level interface to R estimators

doc/source/whatsnew/v0.20.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@ Deprecations
343343
Removal of prior version deprecations/changes
344344
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
345345

346+
- The ``pandas.rpy`` module is removed. Similar functionality can be accessed
347+
through the `rpy2 <https://rpy2.readthedocs.io/>`__ project.
348+
See the :ref:`R interfacing docs <rpy>` for more details.
346349
- ``pd.to_datetime`` and ``pd.to_timedelta`` have dropped the ``coerce`` parameter in favor of ``errors`` (:issue:`13602`)
347350

348351

pandas/api/tests/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class TestPDApi(Base, tm.TestCase):
3030

3131
# these are optionally imported based on testing
3232
# & need to be ignored
33-
ignored = ['tests', 'rpy', 'locale']
33+
ignored = ['tests', 'locale']
3434

3535
# top-level sub-packages
3636
lib = ['api', 'compat', 'computation', 'core',

pandas/rpy/__init__.py

-18
This file was deleted.

pandas/rpy/base.py

-14
This file was deleted.

0 commit comments

Comments
 (0)