I recently cloned arcgispro-py3 env so that that i can use geopandas and arcpy together to output geodataframe to featureclass. To do that, I first export GPKG and then copy over the layer to GDB. It seems that I cannot export to GPKG because geopandas.to_file() depends on fiona, and fiona checks for gdal version. gdal that comes with the cloned env is version "3.7.0e" which throws an error exception because that version cannot be parsed using the regex pattern set in version.py. I believe the string has to be gdal.__version__ == '3.7.0'.
these are the libs and versions that i am working with:
geopandas = '0.12.2'
fiona = '1.8.21'
gdal = '3.7.0e'
arcpy = '3.2'
Here is the error output:
Cell In[11], line 32
27 from arcpy import conversion
28 """Converts a geopandas dataframe to a geopackge layer, converts
29 the geopackage layer to a new feature class in a gdb using arcpy.
30 Returns path to new feature class."""
---> 32 in_gdf.to_file("temp_package.gpkg", layer="temp_package_layer", driver="GPKG")
33 gpkg_layerpath = os.path.join(os.getcwd(), 'temp_package.gpkg\main.temp_geopackage_layer')
34 conversion.FeatureClassToFeatureClass(gpkg_layerpath, out_gdb, out_layer)
File c:\Program Files\ArcGIS\Pro\bin\Python\envs\OpenArcpy\lib\site-packages\geopandas\geodataframe.py:1203, in GeoDataFrame.to_file(self, filename, driver, schema, index, **kwargs)
1120 """Write the ``GeoDataFrame`` to a file.
1121
1122 By default, an ESRI shapefile is written, but any OGR data source
(...)
1199 >>> gdf.to_file('dataframe.shp', mode="a") # doctest: +SKIP
1200 """
1201 from geopandas.io.file import _to_file
-> 1203 _to_file(self, filename, driver, schema, index, **kwargs)
File c:\Program Files\ArcGIS\Pro\bin\Python\envs\OpenArcpy\lib\site-packages\geopandas\io\file.py:545, in _to_file(df, filename, driver, schema, index, mode, crs, engine, **kwargs)
538 warnings.warn(
539 "Column names longer than 10 characters will be truncated when saved to "
540 "ESRI Shapefile.",
541 stacklevel=3,
542 )
544 if engine == "fiona":
--> 545 _to_file_fiona(df, filename, driver, schema, crs, mode, **kwargs)
546 elif engine == "pyogrio":
547 _to_file_pyogrio(df, filename, driver, schema, crs, mode, **kwargs)
File c:\Program Files\ArcGIS\Pro\bin\Python\envs\OpenArcpy\lib\site-packages\geopandas\io\file.py:568, in _to_file_fiona(df, filename, driver, schema, crs, mode, **kwargs)
566 except AttributeError:
567 gdal_version = "2.0.0" # just assume it is not the latest
--> 568 if Version(gdal_version) >= Version("3.0.0") and crs:
569 crs_wkt = crs.to_wkt()
570 elif crs:
File c:\Program Files\ArcGIS\Pro\bin\Python\envs\OpenArcpy\lib\site-packages\packaging\version.py:200, in Version.__init__(self, version)
198 match = self._regex.search(version)
199 if not match:
--> 200 raise InvalidVersion(f"Invalid version: '{version}'")
202 # Store the parsed out pieces of the version
203 self._version = _Version(
204 epoch=int(match.group("epoch")) if match.group("epoch") else 0,
205 release=tuple(int(i) for i in match.group("release").split(".")),
(...)
211 local=_parse_local_version(match.group("local")),
212 )
InvalidVersion: Invalid version: '3.7.0e'
I'm experiencing a similar error when writing to shp. Pseudo code example:
url = 'https://www2.census.gov/geo/tiger/TIGER2022/ROADS/tl_2022_01003_roads.zip'
gdf = geopandas.read_file(url) gdf.to_file('~\tl_2022_01003_roads.shp')
Relevant env versions:
pkgs/main/win-64::geopandas-0.12.2-py39haa95532_0
esri::gdal-3.7.0-arcgispro_py39_17195 (pinned in clone)
Appears this has been an issue in some prior versions as well: https://stackoverflow.com/questions/75994612/invalidversion-error-returned-when-writting-an-esri-shp...
I'm experiencing identical issue, have you had any luck resolving?
My workaround has been to use geopandas = '0.9.0', which seems to be less stringent in its version check. Ideally I'd like to get onto a higher version of gpd though; there are various 0.9.0 conflicts ArcGIS Pro 3.2 standard environment, for example the higher version of pandas (e.g. pandas.Int64Index deprecation).
I would be very grateful to see this resolved 🙏
The workaround I found is to write the file using pyogrio as stated here:
geopandas.options.io_engine = "pyogrio"
def geopandas_to_featureclass(in_gdf, out_gdb, out_layer):
from arcpy import conversion
from pyogrio import write_dataframe
write_dataframe(in_gdf, "temp_package.gpkg", layer="temp_package_layer")
gpkg_layerpath = os.path.join(os.getcwd(), r'temp_package.gpkg', 'main.temp_package_layer')
conversion.FeatureClassToFeatureClass(gpkg_layerpath, out_gdb, out_layer)
os.remove('temp_package.gpkg')
return os.path.join(out_gdb, out_layer)
I created an issue on geopandas' GitHub, even if this is clearly an Esri problem, creating weird versions of packages...
@Esri, please stick to usual versionning 🙏
I have also the same issue - is there an update from @ESRI?
Resolved with latest version of geopandas 🙂