Inconsistent conversion of dataframe to table using GeoAccessor spatial.to_table()
I am using GeoAccessor spatial.to_table() method to convert standard pandas dataframes to geodatabase tables. This previously worked (ArcPro v.2.9) as long as I converted incompatible fields as described in this post: https://community.esri.com/t5/arcgis-api-for-python-questions/system-error-when-exporting-spatially-enabled/td-p/1044880
I'm now on ArcPro v.3.3, and I'm having inconsistent results. Some dataframes are converting to geodatabase tables and some are not, even though the fields causing issues are in both the successfully converted dataframes and the ones that are failing.
Below is a sample traceback -- with the TypeError at the bottom
Traceback (most recent call last):
File "d:\abai490\tlt\scripts\tlt_parcel_stats_debug.py", line 696, in <module>
main(parcel_fc, parcelid_field, yields_npv_tbl, yields_blv_tbl, slvmgt_tbl, stumpage_tbl, discount_rates_tbl, out_dir)
File "d:\abai490\tlt\scripts\tlt_parcel_stats_debug.py", line 678, in main
export_npvblv(pcl_df_list, riu_df_list, output_geodatabase, out_dir, timestamp, parcel_file_pfx)
File "d:\abai490\tlt\scripts\tlt_parcel_stats_debug.py", line 588, in export_npvblv
export_table(parcel_npvblv_df, out_gdb, f'{file_pfx}_npv_blv')
File "d:\abai490\tlt\scripts\tlt_parcel_stats_debug.py", line 378, in export_table
mod_df.spatial.to_table(os.path.join(gdb, out_table))
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\geo\_accessor.py", line 2751, in to_table
table = run_and_hide(
^^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\geo\_tools\_utils.py", line 30, in run_and_hide
raise err
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\geo\_tools\_utils.py", line 23, in run_and_hide
res = fn(**kwargs)
^^^^^^^^^^^^
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\features\geo\_io\fileops.py", line 617, in to_table
arcpy.da.ExtendTable(fc, oidfld, array, join_dummy, append_only=False)
TypeError: cannot add field: 'parcel_id'
I tested this with a standard pandas data frame and a SEDF (with dummy x/y), in the method call and both throw the error. mod_df.spatial.to_table(os.path.join(gdb, out_table))
I'm not sure if this is a bug, or a request for assistance. I am definitely puzzled by the fact that it worked previously and now it works inconsistently. Thanks for any suggestions for resolving this issue.
https://developers.arcgis.com/python/latest/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.to_table
Without a mock data it would be hard to say But I would try using this new io
ARCGIS_IO_ENGINE
Can you post sample data and code?
Thanks folks for your quick responses! I haven't had time to make a reproducible example yet -- had to create a workaround (export to csv and import back to geodatabase table) to get my colleagues rolling again.
I will try to do this and post when I have a chance.
I am using arcgis 2.3.0 (because it is loaded with arcpro 3.3), and I couldn't find the ARCGIS_IO_ENGINE option for that version. Maybe I'm missing it in the docs for v.2.3.0
@cybersea The ARCGIS_IO_ENGINE is starting at 2.4.2 so you won't find it in previous versions
@cybersea Were you able to upgrade and see if this is working at a later version?