Reticulate converts Python integers to "-1" in R

>>> AAPL["financials"]["annual"]["revenue"]
[5742000000, 6207000000, 8279000000, 13931000000, 19315000000, 24578000000, 37491000000, 42905000000, 65225000000, 108249000000, 156508000000, 170910000000, 182795000000, 233715000000, 215639000000, 229234000000, 265595000000, 260174000000, 274515000000, 365817000000]
py$AAPL$financials$annual$revenue
 [1] -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

What are the things I should start looking into?

> sessioninfo()
Error in sessioninfo() : could not find function "sessioninfo"
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    
system code page: 1257

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reticulate_1.23

loaded via a namespace (and not attached):
 [1] compiler_4.1.2    here_1.0.1        Matrix_1.3-4      rprojroot_2.0.2   tools_4.1.2      
 [6] rappdirs_0.3.3    Rcpp_1.0.8        grid_4.1.2        data.table_1.14.2 jsonlite_1.7.3   
[11] png_0.1-7         lattice_0.20-45  

R integers can't store arbitrarily large numbers.

as.integer(2^30)
as.integer(2^31)
[1] 1073741824
[1] NA

your 'integers' are very large. either scale them down by division. or cast them to a type that accommodates larger values

Thank you.

fl = float(AAPL["financials"]["annual"]["revenue"][0])
5742000000.0
py$fl
[1] 5742000000

Works for single element.

Any suggestions for best practices to prepare complex data frames in Python for conversion to R for someone with zero knowledge in Python? For example change all integers to float for the whole data frame?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.