System Error when exporting Spatially Enabled DataFrame to Feature Class

2754
5
Jump to solution
04-07-2021 03:07 PM
DarrenConly
Occasional Contributor

Hi All,

I'm trying to do the following:

  1. Convert a non-spatial pandas dataframe to a spatial dataframe
  2. Export the spatial dataframe to a feature class in an ESRI file geodatabase, based on the instructions provided in ESRI'sIntroduction to the Spatially Enabled DataFrame

However, I get the error "SystemError: returned NULL without setting an error".

I googled the error and the only hits I got implied the issue has something to do with making a C extension. Do any of you have any insights on this?

Here's the full code for context:

out_fc_path = 'I:\\Projects\\Darren\\EmpInventory\\EmploymentInventory.gdb\\testrecs9581720210407_1435' sdft = GeoAccessor.from_xy(master_df, fld_lat, fld_lon) # no issues here! sdft.spatial.to_featureclass(location=out_fc_path) Traceback (most recent call last): File "", line 1, in  sdft.spatial.to_featureclass(location=out_fc_path) File "C:\Users\dconly\AppData\Local\ESRI\conda\envs\arcgispro-py3-dcmar21\lib\site-packages\arcgis\features\geo\_accessor.py", line 2122, in to_featureclass has_m=has_m) File "C:\Users\dconly\AppData\Local\ESRI\conda\envs\arcgispro-py3-dcmar21\lib\site-packages\arcgis\features\geo\_io\fileops.py", line 708, in to_featureclass arcpy.da.ExtendTable(fc, oidfld, array, join_dummy, append_only=False) SystemError:  returned NULL without setting an error

0Kudos
1 Solution

Accepted Solutions
DarrenConly
Occasional Contributor

I found the solution!

In trying to find a workaround, I discovered that you cannot export a spatial dataframe to a file or feature class if it contains categorical data types. To fix this, you must convert all categorical data types to string data type.

Example: if you have a column 'X' that is categorical, you must first convert to string data type by doing the following:

df['X'] = df['X'].astype('str')

I'm happy to have resolved this, and hope my solution is informative to others.

Cheers,

View solution in original post

5 Replies
DarrenConly
Occasional Contributor

I found the solution!

In trying to find a workaround, I discovered that you cannot export a spatial dataframe to a file or feature class if it contains categorical data types. To fix this, you must convert all categorical data types to string data type.

Example: if you have a column 'X' that is categorical, you must first convert to string data type by doing the following:

df['X'] = df['X'].astype('str')

I'm happy to have resolved this, and hope my solution is informative to others.

Cheers,

nzjs
by
New Contributor III

Darren, this led me in the right direction to solve similar issue. In my case I had a number of seemingly invalid data types, so this small function fixed it.

Cheers, John

def convert_dtypes_arcgis(df): # Convert dataframe dtypes which are not compatible with ArcGIS # Use builtin Pandas dtype conversion df = df.convert_dtypes(infer_objects=True) # Then str convert any remaining special object/category fields for col in df.columns: # print(col, '/', df[col].dtype) if df[col].dtype == 'object' or df[col].dtype == 'category': df[col] = df[col].astype('str') # Return modified df return df

RoderickPerendy
New Contributor II

Hello nzjs,

Does this function still work for you? I'm on Pro 3.0 and have a dataframe representing all the content within a group using the Group Object search method using search(query='type:web map', as_dict = True) and converting this to a dataframe. I then expand the 'results' key to additional columns with pd.series and it kicks out a ton of dtypes as objects. However when I run your function it doesn't do anything.

0Kudos
by Anonymous User
Not applicable

Thanks for posting the solution

0Kudos
feralcatcolonist_old
Occasional Contributor II

@Anonymous Useris this going to become a built-in for the API? I recently ran into this issue and am glad there's a workaround, but this seems to be a pretty significant defect.


Likes an array of [cats, gardening, photography]