You caught us doing some quick maintenance, temporarily restricting your repository to read-only access.
Issue #615 new
I copy and pasted Laurent’s code in, but I am getting an error back. Do you have any suggestions to fix this error that says “Converter” object has no attribute rpy2py? Many thanks
import pandas as pd from rpy2 import robjects from rpy2.robjects import pandas2ri from rpy2.robjects.conversion import localconverter, Converter df = pd.DataFrame([['2019-01-01', 1]]) df = pd.to_datetime(df) with localconverter(robjects.default_converter + pandas2ri.converter): robjects.globalenv['mydata'] = df # Only use the default converter r_datecol = robjects.globalenv['mydata'] # The column with a date was converter to an R vector of dates in the data dataframe: # >>> r_datecol # R object with classes: ('POSIXct', 'POSIXt') mapped to: # [2019-01-01] # Use default + pandas converters with localconverter(robjects.default_converter + pandas2ri.converter) as cv: py_datecol = cv.rpy2py(r_datecol) # The conversion of the R vector back to a pandas array of dates appears to be working: # >>> py_datecol # DatetimeIndex(['2019-01-01 00:00:00-05:00'], dtype='datetime64[ns, America/New_York]', freq=None) # The issue is therefore with what is happening at the DataFrame level. Somehow the POSIXct column # in the R data.frame is mapped to an array of floats (which is the C-level type in R, and should # only happen at the `rpy2.rinterface` level) rather that to the R-level class for date vectors. # The issue reported is broader than only date/time vectors.