From e9d2d109161ae79ed518a78c19890bcdeaa4238a Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Mon, 16 Jan 2017 16:44:07 +0100 Subject: [PATCH] CLN/DEPR: remove deprecated pandas.rpy module (GH9602) --- ci/lint.sh | 3 +- doc/source/r_interface.rst | 140 ++---------- doc/source/whatsnew/v0.20.0.txt | 3 + pandas/api/tests/test_api.py | 2 +- pandas/rpy/__init__.py | 18 -- pandas/rpy/base.py | 14 -- pandas/rpy/common.py | 372 -------------------------------- pandas/rpy/mass.py | 2 - pandas/rpy/tests/__init__.py | 0 pandas/rpy/tests/test_common.py | 216 ------------------- pandas/rpy/vars.py | 22 -- setup.py | 1 - 12 files changed, 27 insertions(+), 766 deletions(-) delete mode 100644 pandas/rpy/__init__.py delete mode 100644 pandas/rpy/base.py delete mode 100644 pandas/rpy/common.py delete mode 100644 pandas/rpy/mass.py delete mode 100644 pandas/rpy/tests/__init__.py delete mode 100644 pandas/rpy/tests/test_common.py delete mode 100644 pandas/rpy/vars.py diff --git a/ci/lint.sh b/ci/lint.sh index 5c4613f88649e..2cbfdadf486b8 100755 --- a/ci/lint.sh +++ b/ci/lint.sh @@ -8,10 +8,9 @@ RET=0 if [ "$LINT" ]; then - # pandas/rpy is deprecated and will be removed. # pandas/src is C code, so no need to search there. echo "Linting *.py" - flake8 pandas --filename=*.py --exclude pandas/rpy,pandas/src + flake8 pandas --filename=*.py --exclude pandas/src if [ $? -ne "0" ]; then RET=1 fi diff --git a/doc/source/r_interface.rst b/doc/source/r_interface.rst index f2a8668bbda91..b5d699cad69d5 100644 --- a/doc/source/r_interface.rst +++ b/doc/source/r_interface.rst @@ -1,5 +1,3 @@ -.. currentmodule:: pandas.rpy - .. _rpy: .. ipython:: python @@ -15,132 +13,55 @@ rpy2 / R interface .. warning:: - In v0.16.0, the ``pandas.rpy`` interface has been **deprecated and will be - removed in a future version**. Similar functionality can be accessed - through the `rpy2 `__ project. - See the :ref:`updating ` section for a guide to port your - code from the ``pandas.rpy`` to ``rpy2`` functions. - - -.. _rpy.updating: - -Updating your code to use rpy2 functions ----------------------------------------- - -In v0.16.0, the ``pandas.rpy`` module has been **deprecated** and users are -pointed to the similar functionality in ``rpy2`` itself (rpy2 >= 2.4). + Up to pandas 0.19, a ``pandas.rpy`` module existed with functionality to + convert between pandas and ``rpy2`` objects. This functionality now lives in + the `rpy2 `__ project itself. + See the `updating section `__ + of the previous documentation for a guide to port your code from the + removed ``pandas.rpy`` to ``rpy2`` functions. -Instead of importing ``import pandas.rpy.common as com``, the following imports -should be done to activate the pandas conversion support in rpy2:: - - from rpy2.robjects import pandas2ri - pandas2ri.activate() +`rpy2 `__ is an interface to R running embedded in a Python process, and also includes functionality to deal with pandas DataFrames. Converting data frames back and forth between rpy2 and pandas should be largely automated (no need to convert explicitly, it will be done on the fly in most rpy2 functions). - To convert explicitly, the functions are ``pandas2ri.py2ri()`` and -``pandas2ri.ri2py()``. So these functions can be used to replace the existing -functions in pandas: - -- ``com.convert_to_r_dataframe(df)`` should be replaced with ``pandas2ri.py2ri(df)`` -- ``com.convert_robj(rdf)`` should be replaced with ``pandas2ri.ri2py(rdf)`` - -Note: these functions are for the latest version (rpy2 2.5.x) and were called -``pandas2ri.pandas2ri()`` and ``pandas2ri.ri2pandas()`` previously. - -Some of the other functionality in `pandas.rpy` can be replaced easily as well. -For example to load R data as done with the ``load_data`` function, the -current method:: - - df_iris = com.load_data('iris') - -can be replaced with:: - - from rpy2.robjects import r - r.data('iris') - df_iris = pandas2ri.ri2py(r[name]) - -The ``convert_to_r_matrix`` function can be replaced by the normal -``pandas2ri.py2ri`` to convert dataframes, with a subsequent call to R -``as.matrix`` function. - -.. warning:: - - Not all conversion functions in rpy2 are working exactly the same as the - current methods in pandas. If you experience problems or limitations in - comparison to the ones in pandas, please report this at the - `issue tracker `_. - -See also the documentation of the `rpy2 `__ project. - +``pandas2ri.ri2py()``. -R interface with rpy2 ---------------------- -If your computer has R and rpy2 (> 2.2) installed (which will be left to the -reader), you will be able to leverage the below functionality. On Windows, -doing this is quite an ordeal at the moment, but users on Unix-like systems -should find it quite easy. rpy2 evolves in time, and is currently reaching -its release 2.3, while the current interface is -designed for the 2.2.x series. We recommend to use 2.2.x over other series -unless you are prepared to fix parts of the code, yet the rpy2-2.3.0 -introduces improvements such as a better R-Python bridge memory management -layer so it might be a good idea to bite the bullet and submit patches for -the few minor differences that need to be fixed. +See also the documentation of the `rpy2 `__ project: https://rpy2.readthedocs.io. +In the remainder of this page, a few examples of explicit conversion is given. The pandas conversion of rpy2 needs first to be activated: -:: - - # if installing for the first time - hg clone http://bitbucket.org/lgautier/rpy2 - - cd rpy2 - hg pull - hg update version_2.2.x - sudo python setup.py install - -.. note:: - - To use R packages with this interface, you will need to install - them inside R yourself. At the moment it cannot install them for - you. +.. ipython:: python -Once you have done installed R and rpy2, you should be able to import -``pandas.rpy.common`` without a hitch. + from rpy2.robjects import r, pandas2ri + pandas2ri.activate() Transferring R data sets into Python ------------------------------------ -The **load_data** function retrieves an R data set and converts it to the +The ``pandas2ri.ri2py`` function retrieves an R data set and converts it to the appropriate pandas object (most likely a DataFrame): - .. ipython:: python - :okwarning: - - import pandas.rpy.common as com - infert = com.load_data('infert') - infert.head() + r.data('iris') + df_iris = pandas2ri.ri2py(r['iris']) + df_iris.head() Converting DataFrames into R objects ------------------------------------ -.. versionadded:: 0.8 - -Starting from pandas 0.8, there is **experimental** support to convert +The ``pandas2ri.py2ri`` function support the reverse operation to convert DataFrames into the equivalent R object (that is, **data.frame**): .. ipython:: python - import pandas.rpy.common as com df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C':[7,8,9]}, index=["one", "two", "three"]) - r_dataframe = com.convert_to_r_dataframe(df) - + r_dataframe = pandas2ri.py2ri(df) print(type(r_dataframe)) print(r_dataframe) @@ -148,24 +69,7 @@ DataFrames into the equivalent R object (that is, **data.frame**): The DataFrame's index is stored as the ``rownames`` attribute of the data.frame instance. -You can also use **convert_to_r_matrix** to obtain a ``Matrix`` instance, but -bear in mind that it will only work with homogeneously-typed DataFrames (as -R matrices bear no information on the data type): - -.. ipython:: python - - import pandas.rpy.common as com - r_matrix = com.convert_to_r_matrix(df) - - print(type(r_matrix)) - print(r_matrix) - - -Calling R functions with pandas objects ---------------------------------------- - - - -High-level interface to R estimators ------------------------------------- +.. + Calling R functions with pandas objects + High-level interface to R estimators diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index 2a825edd0e98a..c93f8b310ebc0 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -271,6 +271,9 @@ Deprecations Removal of prior version deprecations/changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- The ``pandas.rpy`` module is removed. Similar functionality can be accessed + through the `rpy2 `__ project. + See the :ref:`R interfacing docs ` for more details. - ``pd.to_datetime`` and ``pd.to_timedelta`` have dropped the ``coerce`` parameter in favor of ``errors`` (:issue:`13602`) diff --git a/pandas/api/tests/test_api.py b/pandas/api/tests/test_api.py index b13b4d7de60ca..f6b765fbf7418 100644 --- a/pandas/api/tests/test_api.py +++ b/pandas/api/tests/test_api.py @@ -30,7 +30,7 @@ class TestPDApi(Base, tm.TestCase): # these are optionally imported based on testing # & need to be ignored - ignored = ['tests', 'rpy', 'locale'] + ignored = ['tests', 'locale'] # top-level sub-packages lib = ['api', 'compat', 'computation', 'core', diff --git a/pandas/rpy/__init__.py b/pandas/rpy/__init__.py deleted file mode 100644 index b771a3d8374a3..0000000000000 --- a/pandas/rpy/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ - -# GH9602 -# deprecate rpy to instead directly use rpy2 - -# flake8: noqa - -import warnings -warnings.warn("The pandas.rpy module is deprecated and will be " - "removed in a future version. We refer to external packages " - "like rpy2. " - "\nSee here for a guide on how to port your code to rpy2: " - "http://pandas.pydata.org/pandas-docs/stable/r_interface.html", - FutureWarning, stacklevel=2) - -try: - from .common import importr, r, load_data -except ImportError: - pass diff --git a/pandas/rpy/base.py b/pandas/rpy/base.py deleted file mode 100644 index ac339dd366b0b..0000000000000 --- a/pandas/rpy/base.py +++ /dev/null @@ -1,14 +0,0 @@ -# flake8: noqa - -import pandas.rpy.util as util - - -class lm(object): - """ - Examples - -------- - >>> model = lm('x ~ y + z', data) - >>> model.coef - """ - def __init__(self, formula, data): - pass diff --git a/pandas/rpy/common.py b/pandas/rpy/common.py deleted file mode 100644 index 95a072154dc68..0000000000000 --- a/pandas/rpy/common.py +++ /dev/null @@ -1,372 +0,0 @@ -""" -Utilities for making working with rpy2 more user- and -developer-friendly. -""" - -# flake8: noqa - -from __future__ import print_function - -from distutils.version import LooseVersion -from pandas.compat import zip, range -import numpy as np - -import pandas as pd -import pandas.core.common as com -import pandas.util.testing as _test - -from rpy2.robjects.packages import importr -from rpy2.robjects import r -import rpy2.robjects as robj - -import itertools as IT - - -__all__ = ['convert_robj', 'load_data', 'convert_to_r_dataframe', - 'convert_to_r_matrix'] - - -def load_data(name, package=None, convert=True): - if package: - importr(package) - - r.data(name) - - robj = r[name] - - if convert: - return convert_robj(robj) - else: - return robj - - -def _rclass(obj): - """ - Return R class name for input object - """ - return r['class'](obj)[0] - - -def _is_null(obj): - return _rclass(obj) == 'NULL' - - -def _convert_list(obj): - """ - Convert named Vector to dict, factors to list - """ - try: - values = [convert_robj(x) for x in obj] - keys = r['names'](obj) - return dict(zip(keys, values)) - except TypeError: - # For state.division and state.region - factors = list(r['factor'](obj)) - level = list(r['levels'](obj)) - result = [level[index-1] for index in factors] - return result - - -def _convert_array(obj): - """ - Convert Array to DataFrame - """ - def _list(item): - try: - return list(item) - except TypeError: - return [] - - # For iris3, HairEyeColor, UCBAdmissions, Titanic - dim = list(obj.dim) - values = np.array(list(obj)) - names = r['dimnames'](obj) - try: - columns = list(r['names'](names))[::-1] - except TypeError: - columns = ['X{:d}'.format(i) for i in range(len(names))][::-1] - columns.append('value') - name_list = [(_list(x) or range(d)) for x, d in zip(names, dim)][::-1] - arr = np.array(list(IT.product(*name_list))) - arr = np.column_stack([arr,values]) - df = pd.DataFrame(arr, columns=columns) - return df - - -def _convert_vector(obj): - if isinstance(obj, robj.IntVector): - return _convert_int_vector(obj) - elif isinstance(obj, robj.StrVector): - return _convert_str_vector(obj) - # Check if the vector has extra information attached to it that can be used - # as an index - try: - attributes = set(r['attributes'](obj).names) - except AttributeError: - return list(obj) - if 'names' in attributes: - return pd.Series(list(obj), index=r['names'](obj)) - elif 'tsp' in attributes: - return pd.Series(list(obj), index=r['time'](obj)) - elif 'labels' in attributes: - return pd.Series(list(obj), index=r['labels'](obj)) - if _rclass(obj) == 'dist': - # For 'eurodist'. WARNING: This results in a DataFrame, not a Series or list. - matrix = r['as.matrix'](obj) - return convert_robj(matrix) - else: - return list(obj) - -NA_INTEGER = -2147483648 - - -def _convert_int_vector(obj): - arr = np.asarray(obj) - mask = arr == NA_INTEGER - if mask.any(): - arr = arr.astype(float) - arr[mask] = np.nan - return arr - - -def _convert_str_vector(obj): - arr = np.asarray(obj, dtype=object) - mask = arr == robj.NA_Character - if mask.any(): - arr[mask] = np.nan - return arr - - -def _convert_DataFrame(rdf): - columns = list(rdf.colnames) - rows = np.array(rdf.rownames) - - data = {} - for i, col in enumerate(columns): - vec = rdf.rx2(i + 1) - values = _convert_vector(vec) - - if isinstance(vec, robj.FactorVector): - levels = np.asarray(vec.levels) - if com.is_float_dtype(values): - mask = np.isnan(values) - notmask = -mask - result = np.empty(len(values), dtype=object) - result[mask] = np.nan - - locs = (values[notmask] - 1).astype(np.int_) - result[notmask] = levels.take(locs) - values = result - else: - values = np.asarray(vec.levels).take(values - 1) - - data[col] = values - - return pd.DataFrame(data, index=_check_int(rows), columns=columns) - - -def _convert_Matrix(mat): - columns = mat.colnames - rows = mat.rownames - - columns = None if _is_null(columns) else list(columns) - index = r['time'](mat) if _is_null(rows) else list(rows) - return pd.DataFrame(np.array(mat), index=_check_int(index), - columns=columns) - - -def _check_int(vec): - try: - # R observation numbers come through as strings - vec = vec.astype(int) - except Exception: - pass - - return vec - -_pandas_converters = [ - (robj.DataFrame, _convert_DataFrame), - (robj.Matrix, _convert_Matrix), - (robj.StrVector, _convert_vector), - (robj.FloatVector, _convert_vector), - (robj.Array, _convert_array), - (robj.Vector, _convert_list), -] - -_converters = [ - (robj.DataFrame, lambda x: _convert_DataFrame(x).toRecords(index=False)), - (robj.Matrix, lambda x: _convert_Matrix(x).toRecords(index=False)), - (robj.IntVector, _convert_vector), - (robj.StrVector, _convert_vector), - (robj.FloatVector, _convert_vector), - (robj.Array, _convert_array), - (robj.Vector, _convert_list), -] - - -def convert_robj(obj, use_pandas=True): - """ - Convert rpy2 object to a pandas-friendly form - - Parameters - ---------- - obj : rpy2 object - - Returns - ------- - Non-rpy data structure, mix of NumPy and pandas objects - """ - if not isinstance(obj, robj.RObjectMixin): - return obj - - converters = _pandas_converters if use_pandas else _converters - - for rpy_type, converter in converters: - if isinstance(obj, rpy_type): - return converter(obj) - - raise TypeError('Do not know what to do with %s object' % type(obj)) - - -def convert_to_r_posixct(obj): - """ - Convert DatetimeIndex or np.datetime array to R POSIXct using - m8[s] format. - - Parameters - ---------- - obj : source pandas object (one of [DatetimeIndex, np.datetime]) - - Returns - ------- - An R POSIXct vector (rpy2.robjects.vectors.POSIXct) - - """ - import time - from rpy2.rinterface import StrSexpVector - - # convert m8[ns] to m8[s] - vals = robj.vectors.FloatSexpVector(obj.values.view('i8') / 1E9) - as_posixct = robj.baseenv.get('as.POSIXct') - origin = StrSexpVector([time.strftime("%Y-%m-%d", - time.gmtime(0)), ]) - - # We will be sending ints as UTC - tz = obj.tz.zone if hasattr( - obj, 'tz') and hasattr(obj.tz, 'zone') else 'UTC' - tz = StrSexpVector([tz]) - utc_tz = StrSexpVector(['UTC']) - - posixct = as_posixct(vals, origin=origin, tz=utc_tz) - posixct.do_slot_assign('tzone', tz) - return posixct - - -VECTOR_TYPES = {np.float64: robj.FloatVector, - np.float32: robj.FloatVector, - np.float: robj.FloatVector, - np.int: robj.IntVector, - np.int32: robj.IntVector, - np.int64: robj.IntVector, - np.object_: robj.StrVector, - np.str: robj.StrVector, - np.bool: robj.BoolVector} - - -NA_TYPES = {np.float64: robj.NA_Real, - np.float32: robj.NA_Real, - np.float: robj.NA_Real, - np.int: robj.NA_Integer, - np.int32: robj.NA_Integer, - np.int64: robj.NA_Integer, - np.object_: robj.NA_Character, - np.str: robj.NA_Character, - np.bool: robj.NA_Logical} - - -if LooseVersion(np.__version__) >= LooseVersion('1.8'): - for dict_ in (VECTOR_TYPES, NA_TYPES): - dict_.update({ - np.bool_: dict_[np.bool], - np.int_: dict_[np.int], - np.float_: dict_[np.float], - np.string_: dict_[np.str] - }) - - -def convert_to_r_dataframe(df, strings_as_factors=False): - """ - Convert a pandas DataFrame to a R data.frame. - - Parameters - ---------- - df: The DataFrame being converted - strings_as_factors: Whether to turn strings into R factors (default: False) - - Returns - ------- - A R data.frame - - """ - - import rpy2.rlike.container as rlc - - columns = rlc.OrdDict() - - # FIXME: This doesn't handle MultiIndex - - for column in df: - value = df[column] - value_type = value.dtype.type - - if value_type == np.datetime64: - value = convert_to_r_posixct(value) - else: - value = [item if pd.notnull(item) else NA_TYPES[value_type] - for item in value] - - value = VECTOR_TYPES[value_type](value) - - if not strings_as_factors: - I = robj.baseenv.get("I") - value = I(value) - - columns[column] = value - - r_dataframe = robj.DataFrame(columns) - - del columns - - r_dataframe.rownames = robj.StrVector(df.index) - - return r_dataframe - - -def convert_to_r_matrix(df, strings_as_factors=False): - - """ - Convert a pandas DataFrame to a R matrix. - - Parameters - ---------- - df: The DataFrame being converted - strings_as_factors: Whether to turn strings into R factors (default: False) - - Returns - ------- - A R matrix - - """ - - if df._is_mixed_type: - raise TypeError("Conversion to matrix only possible with non-mixed " - "type DataFrames") - - r_dataframe = convert_to_r_dataframe(df, strings_as_factors) - as_matrix = robj.baseenv.get("as.matrix") - r_matrix = as_matrix(r_dataframe) - - return r_matrix - -if __name__ == '__main__': - pass diff --git a/pandas/rpy/mass.py b/pandas/rpy/mass.py deleted file mode 100644 index 12fbbdfa4dc98..0000000000000 --- a/pandas/rpy/mass.py +++ /dev/null @@ -1,2 +0,0 @@ -class rlm(object): - pass diff --git a/pandas/rpy/tests/__init__.py b/pandas/rpy/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d..0000000000000 diff --git a/pandas/rpy/tests/test_common.py b/pandas/rpy/tests/test_common.py deleted file mode 100644 index c3f09e21b1545..0000000000000 --- a/pandas/rpy/tests/test_common.py +++ /dev/null @@ -1,216 +0,0 @@ -""" -Testing that functions from rpy work as expected -""" - -# flake8: noqa - -import pandas as pd -import numpy as np -import unittest -import nose -import warnings -import pandas.util.testing as tm - -try: - import pandas.rpy.common as com - from rpy2.robjects import r - import rpy2.robjects as robj -except ImportError: - raise nose.SkipTest('R not installed') - - -class TestCommon(unittest.TestCase): - def test_convert_list(self): - obj = r('list(a=1, b=2, c=3)') - - converted = com.convert_robj(obj) - expected = {'a': [1], 'b': [2], 'c': [3]} - - tm.assert_dict_equal(converted, expected) - - def test_convert_nested_list(self): - obj = r('list(a=list(foo=1, bar=2))') - - converted = com.convert_robj(obj) - expected = {'a': {'foo': [1], 'bar': [2]}} - - tm.assert_dict_equal(converted, expected) - - def test_convert_frame(self): - # built-in dataset - df = r['faithful'] - - converted = com.convert_robj(df) - - assert np.array_equal(converted.columns, ['eruptions', 'waiting']) - assert np.array_equal(converted.index, np.arange(1, 273)) - - def _test_matrix(self): - r('mat <- matrix(rnorm(9), ncol=3)') - r('colnames(mat) <- c("one", "two", "three")') - r('rownames(mat) <- c("a", "b", "c")') - - return r['mat'] - - def test_convert_matrix(self): - mat = self._test_matrix() - - converted = com.convert_robj(mat) - - assert np.array_equal(converted.index, ['a', 'b', 'c']) - assert np.array_equal(converted.columns, ['one', 'two', 'three']) - - def test_convert_r_dataframe(self): - - is_na = robj.baseenv.get("is.na") - - seriesd = tm.getSeriesData() - frame = pd.DataFrame(seriesd, columns=['D', 'C', 'B', 'A']) - - # Null data - frame["E"] = [np.nan for item in frame["A"]] - # Some mixed type data - frame["F"] = ["text" if item % - 2 == 0 else np.nan for item in range(30)] - - r_dataframe = com.convert_to_r_dataframe(frame) - - assert np.array_equal( - com.convert_robj(r_dataframe.rownames), frame.index) - assert np.array_equal( - com.convert_robj(r_dataframe.colnames), frame.columns) - assert all(is_na(item) for item in r_dataframe.rx2("E")) - - for column in frame[["A", "B", "C", "D"]]: - coldata = r_dataframe.rx2(column) - original_data = frame[column] - assert np.array_equal(com.convert_robj(coldata), original_data) - - for column in frame[["D", "E"]]: - for original, converted in zip(frame[column], - r_dataframe.rx2(column)): - - if pd.isnull(original): - assert is_na(converted) - else: - assert original == converted - - def test_convert_r_matrix(self): - - is_na = robj.baseenv.get("is.na") - - seriesd = tm.getSeriesData() - frame = pd.DataFrame(seriesd, columns=['D', 'C', 'B', 'A']) - # Null data - frame["E"] = [np.nan for item in frame["A"]] - - r_dataframe = com.convert_to_r_matrix(frame) - - assert np.array_equal( - com.convert_robj(r_dataframe.rownames), frame.index) - assert np.array_equal( - com.convert_robj(r_dataframe.colnames), frame.columns) - assert all(is_na(item) for item in r_dataframe.rx(True, "E")) - - for column in frame[["A", "B", "C", "D"]]: - coldata = r_dataframe.rx(True, column) - original_data = frame[column] - assert np.array_equal(com.convert_robj(coldata), - original_data) - - # Pandas bug 1282 - frame["F"] = ["text" if item % - 2 == 0 else np.nan for item in range(30)] - - try: - wrong_matrix = com.convert_to_r_matrix(frame) - except TypeError: - pass - except Exception: - raise - - def test_dist(self): - for name in ('eurodist',): - df = com.load_data(name) - dist = r[name] - labels = r['labels'](dist) - assert np.array_equal(df.index, labels) - assert np.array_equal(df.columns, labels) - - def test_timeseries(self): - """ - Test that the series has an informative index. - Unfortunately the code currently does not build a DateTimeIndex - """ - for name in ( - 'austres', 'co2', 'fdeaths', 'freeny.y', 'JohnsonJohnson', - 'ldeaths', 'mdeaths', 'nottem', 'presidents', 'sunspot.month', 'sunspots', - 'UKDriverDeaths', 'UKgas', 'USAccDeaths', - 'airmiles', 'discoveries', 'EuStockMarkets', - 'LakeHuron', 'lh', 'lynx', 'nhtemp', 'Nile', - 'Seatbelts', 'sunspot.year', 'treering', 'uspop'): - series = com.load_data(name) - ts = r[name] - assert np.array_equal(series.index, r['time'](ts)) - - def test_numeric(self): - for name in ('euro', 'islands', 'precip'): - series = com.load_data(name) - numeric = r[name] - names = numeric.names - assert np.array_equal(series.index, names) - - def test_table(self): - iris3 = pd.DataFrame({'X0': {0: '0', 1: '1', 2: '2', 3: '3', 4: '4'}, - 'X1': {0: 'Sepal L.', - 1: 'Sepal L.', - 2: 'Sepal L.', - 3: 'Sepal L.', - 4: 'Sepal L.'}, - 'X2': {0: 'Setosa', - 1: 'Setosa', - 2: 'Setosa', - 3: 'Setosa', - 4: 'Setosa'}, - 'value': {0: '5.1', 1: '4.9', 2: '4.7', 3: '4.6', 4: '5.0'}}) - hec = pd.DataFrame( - { - 'Eye': {0: 'Brown', 1: 'Brown', 2: 'Brown', 3: 'Brown', 4: 'Blue'}, - 'Hair': {0: 'Black', 1: 'Brown', 2: 'Red', 3: 'Blond', 4: 'Black'}, - 'Sex': {0: 'Male', 1: 'Male', 2: 'Male', 3: 'Male', 4: 'Male'}, - 'value': {0: '32.0', 1: '53.0', 2: '10.0', 3: '3.0', 4: '11.0'}}) - titanic = pd.DataFrame( - { - 'Age': {0: 'Child', 1: 'Child', 2: 'Child', 3: 'Child', 4: 'Child'}, - 'Class': {0: '1st', 1: '2nd', 2: '3rd', 3: 'Crew', 4: '1st'}, - 'Sex': {0: 'Male', 1: 'Male', 2: 'Male', 3: 'Male', 4: 'Female'}, - 'Survived': {0: 'No', 1: 'No', 2: 'No', 3: 'No', 4: 'No'}, - 'value': {0: '0.0', 1: '0.0', 2: '35.0', 3: '0.0', 4: '0.0'}}) - for name, expected in zip(('HairEyeColor', 'Titanic', 'iris3'), - (hec, titanic, iris3)): - df = com.load_data(name) - table = r[name] - names = r['dimnames'](table) - try: - columns = list(r['names'](names))[::-1] - except TypeError: - columns = ['X{:d}'.format(i) for i in range(len(names))][::-1] - columns.append('value') - assert np.array_equal(df.columns, columns) - result = df.head() - cond = ((result.sort(axis=1) == expected.sort(axis=1))).values - assert np.all(cond) - - def test_factor(self): - for name in ('state.division', 'state.region'): - vector = r[name] - factors = list(r['factor'](vector)) - level = list(r['levels'](vector)) - factors = [level[index - 1] for index in factors] - result = com.load_data(name) - assert np.equal(result, factors) - -if __name__ == '__main__': - nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], - # '--with-coverage', '--cover-package=pandas.core'], - exit=False) diff --git a/pandas/rpy/vars.py b/pandas/rpy/vars.py deleted file mode 100644 index 2073b47483141..0000000000000 --- a/pandas/rpy/vars.py +++ /dev/null @@ -1,22 +0,0 @@ -# flake8: noqa - -import pandas.rpy.util as util - - -class VAR(object): - """ - - Parameters - ---------- - y : - p : - type : {"const", "trend", "both", "none"} - season : - exogen : - lag_max : - ic : {"AIC", "HQ", "SC", "FPE"} - Information criterion to use, if lag_max is not None - """ - def __init__(y, p=1, type="none", season=None, exogen=None, - lag_max=None, ic=None): - pass diff --git a/setup.py b/setup.py index 0a84cf527bfb1..d8d9968c51576 100755 --- a/setup.py +++ b/setup.py @@ -630,7 +630,6 @@ def pxd(name): 'pandas.io', 'pandas.io.sas', 'pandas.formats', - 'pandas.rpy', 'pandas.sparse', 'pandas.sparse.tests', 'pandas.stats',