Just upgraded RStudio to v1.4.869-4 Preview to trial new functionality for interacting with Python objects. Encountering an issue with R crashing when using View() function on a geopandas.GeoDataFrame object; however, the same error does not occur for a pandas.DataFrame object.
library(tidyverse)
library(reticulate)
conda_create("reprex", packages = c("pandas", "geopandas", "shapely"))
#> [1] "/Users/Brian/Library/r-miniconda/envs/reprex/bin/python"
use_condaenv(condaenv = "reprex", conda = "auto", required = TRUE)
pd <- import("pandas",convert=F)
gpd <- import("geopandas",convert=F)
shapely <- import("shapely",convert=F)
pd <- import("pandas",convert=F)
gpd <- import("geopandas",convert=F)
shapely <- import("shapely",convert=F)
d = list('col1'=c(1, 2), 'col2'=c(3, 4))
df = pd$DataFrame(data=d)
View(df)
#> Error in as.data.frame.default(x): cannot coerce class 'c("pandas.core.frame.DataFrame", "pandas.core.generic.NDFrame", ' to a data.frame
gd = list('col1'=c(1, 2), 'col2'=c(3, 4), 'geometry'=c(shapely$geometry$Point(1,2), shapely$geometry$Point(2,1)))
gdf = gpd$GeoDataFrame(gd, crs="EPSG:4326")
View(gdf)
#> Error in as.data.frame.default(x): cannot coerce class 'c("geopandas.geodataframe.GeoDataFrame", "geopandas.base.GeoPandasBase", ' to a data.frame
Created on 2020-10-07 by the reprex package (v0.3.0)
Interestingly, the errors in the above reprex aren't returned in the Console when I run the code. For View(df)
, the code works fine with no raised errors and I can view df
in the normal RStudio brower window. For View(gdf)
, the RStudio brower window returns r error 4 (R code execution error)
while the Console returns
Error in py_get_item_impl(x, key, FALSE) :
IndexError: index 2 is out of bounds for axis 0 with size 2
Detailed traceback:
File "/Users/Brian/Library/r-miniconda/envs/reprex/lib/python3.8/site-packages/geopandas/array.py", line 331, in __getitem__
return GeometryArray(self.data[idx], crs=self.crs)
Error in py_get_item_impl(x, key, FALSE) :
IndexError: index 2 is out of bounds for axis 0 with size 2
Detailed traceback:
File "/Users/Brian/Library/r-miniconda/envs/reprex/lib/python3.8/site-packages/geopandas/array.py", line 331, in __getitem__
return GeometryArray(self.data[idx], crs=self.crs)
Thoughts on what might be going on? Are geopandas.GeoDataFrame just not currently supported by View() in RStudio v1.4.869-4 Preview?