Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors with pandas 2.0. #1013

Closed
lgautier opened this issue Apr 8, 2023 · 0 comments
Closed

Errors with pandas 2.0. #1013

lgautier opened this issue Apr 8, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@lgautier
Copy link
Member

lgautier commented Apr 8, 2023

Describe the issue or bug

Pandas 2.0 is the new major pandas release. It introduces API-breaking changes. The following rpy2 tests fail with pandas 2.0.

FAILED rpy2/tests/robjects/test_pandas_conversions.py::TestPandasConversions::test_series_issue264 - AttributeError: module 'pandas' has no attribute 'Int64Index'
FAILED rpy2/tests/robjects/test_pandas_conversions.py::TestPandasConversions::test_datetime2posixct - AttributeError: 'datetime.timezone' object has no attribute 'zone'
FAILED rpy2/tests/robjects/test_pandas_conversions.py::TestPandasConversions::test_datetime2posixct_withNA - AttributeError: 'datetime.timezone' object has no attribute 'zone'

To Reproduce

  1. update pandas to the latest in the 2.0 series.
  2. pytest rpy2/tests/robjects/test_pandas_conversions.py

Expected behavior

Tests passing without error.

Error

__________________ TestPandasConversions.test_series_issue264 __________________

self = <rpy2.tests.robjects.test_pandas_conversions.TestPandasConversions object at 0x7f91ff45b520>

    def test_series_issue264(self):
        Series = pandas.core.series.Series
        s = Series(('a', 'b', 'c', 'd', 'e'),
>                  index=pandas.Int64Index([0,1,2,3,4]))
E       AttributeError: module 'pandas' has no attribute 'Int64Index'

rpy2/tests/robjects/test_pandas_conversions.py:245: AttributeError
_________________ TestPandasConversions.test_datetime2posixct __________________

self = <rpy2.tests.robjects.test_pandas_conversions.TestPandasConversions object at 0x7f91ff485700>

    def test_datetime2posixct(self):
        datetime = pandas.Series(
            pandas.date_range('2017-01-01 00:00:00.234',
                              periods=20, freq='ms', tz='UTC')
        )
        with localconverter(default_converter + rpyp.converter) as cv:
>           rp_c = robjects.conversion.converter_ctx.get().py2rpy(datetime)

rpy2/tests/robjects/test_pandas_conversions.py:311: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/functools.py:875: in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

obj = 0    2017-01-01 00:00:00.234000+00:00
1    2017-01-01 00:00:00.235000+00:00
2    2017-01-01 00:00:00.236000+00:00
3   ...:00.251000+00:00
18   2017-01-01 00:00:00.252000+00:00
19   2017-01-01 00:00:00.253000+00:00
dtype: datetime64[ns, UTC]

    @py2rpy.register(pandas.core.series.Series)
    def py2rpy_pandasseries(obj):
        if obj.dtype.name == 'O':
            warnings.warn('Element "%s" is of dtype "O" and converted '
                          'to R vector of strings.' % obj.name)
            res = StrVector(obj)
        elif obj.dtype.name == 'category':
            res = py2rpy_categorical(obj.cat)
            res = FactorVector(res)
        elif is_datetime64_any_dtype(obj.dtype):
            # time series
>           tzname = obj.dt.tz.zone if obj.dt.tz else ''
E           AttributeError: 'datetime.timezone' object has no attribute 'zone'


rpy2/robjects/pandas2ri.py:179: AttributeError
______________ TestPandasConversions.test_datetime2posixct_withNA ______________

self = <rpy2.tests.robjects.test_pandas_conversions.TestPandasConversions object at 0x7f91ff485820>

    def test_datetime2posixct_withNA(self):
        datetime = pandas.Series(
            pandas.date_range('2017-01-01 00:00:00.234',
                              periods=20, freq='ms', tz='UTC')
        )
        datetime[1] = pandas.NaT
        with localconverter(default_converter + rpyp.converter) as cv:
>           rp_c = robjects.conversion.converter_ctx.get().py2rpy(datetime)

rpy2/tests/robjects/test_pandas_conversions.py:324: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/functools.py:875: in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

obj = 0    2017-01-01 00:00:00.234000+00:00
1                                 NaT
2    2017-01-01 00:00:00.236000+00:00
3   ...:00.251000+00:00
18   2017-01-01 00:00:00.252000+00:00
19   2017-01-01 00:00:00.253000+00:00
dtype: datetime64[ns, UTC]

    @py2rpy.register(pandas.core.series.Series)
    def py2rpy_pandasseries(obj):
        if obj.dtype.name == 'O':
            warnings.warn('Element "%s" is of dtype "O" and converted '
                          'to R vector of strings.' % obj.name)
            res = StrVector(obj)
        elif obj.dtype.name == 'category':
            res = py2rpy_categorical(obj.cat)
            res = FactorVector(res)
        elif is_datetime64_any_dtype(obj.dtype):
            # time series
>           tzname = obj.dt.tz.zone if obj.dt.tz else ''
E           AttributeError: 'datetime.timezone' object has no attribute 'zone'

rpy2/robjects/pandas2ri.py:179: AttributeError

Additional context

None.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant