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
Fail to convert pandas dataframe: integer <some very large integer> does not fit 'int' #598
Comments
Original comment by Brian Lie (Bitbucket: [Brian Lie](https://bitbucket.org/Brian Lie), ). By the way if you checked the type of it will show up as So this is like an int64 problem? |
Hi, |
Hi, |
@artur-ba my workaround is to convert the dataframe to a csv string and then load that string via an R function: csv_text = df.to_csv(index=False)
robjects.r(f"source('r_utils.R')")
get_dataframe_from_csv_text = robjects.globalenv["get_dataframe_from_csv_text"]
r_df = get_dataframe_from_csv_text(csv_text=csv_text) where get_dataframe_from_csv_text <- function(csv_text) {
df <- read.csv(text = csv_text, check.names = FALSE)
return(df)
} |
@artur-ba - I am looking at whether I can fix this for release 3.5.0. @AnselmC - serializing from Python to CSV, and then unserialize to R seems quite inefficient. |
I just checked with R 4.1. It still can't handle such integers. > as.integer(30123456789)
[1] NA
Warning message:
NAs introduced by coercion to integer range 64-bit floats work though: pd_df = pd.DataFrame({
'int_values': [1.0, 2,30123456789, 4]
'str_values': ['abc', 'def', 'ghi', 'jkl']}) The options would be: |
Original report by Brian Lie (Bitbucket: [Brian Lie](https://bitbucket.org/Brian Lie), ).
Hello, so I found that pandas dataframes containing very large integers can’t be converted into R’s form yet?
There’s a demand to pass a pandas dataframe to R inside one Jupyter notebook, but we would like to find alternatives other than saving the dataframe in a file and load it in R (using IPython’s Rcell magics) later.
When the sample above is executed, some error similar to this below will appear:
/home/user/playground/rpy2/rpy2-3.1.0/rpy2/robjects/pandas2ri.py:60: UserWarning: Error while trying to convert the column "int_values". Fall back to string conversion. The error is: integer 30123456789 does not fit 'int'
the error occurs in the line when the conversion is being done.
Here’s the version informations:
Full stack trace:
The text was updated successfully, but these errors were encountered: