using arcgis 2.4.1. Developed this script a few months ago and didn't have this problem until testing it again this week, and it is now throwing this error when trying to create a featureset from an SEDF created by the GeoAccessor.
ValueError("<weakref at 0x000002874A68BA10; to 'ExtensionBlock' at 0x000002874C193DD0> is not in list")The script is over 2k lines and this problem just started happening after we republished the services with the related tables included.
lv_sdf = GeoAccessor.from_featureclass(lv_config['lv_scratch_fc_path'])
# perform column renaming, etc.
feat_set = lv_sdf.spatial.to_featureset() # to_featureset() is broken here.Has anyone else come across this before?
I'm getting the same error in a similar situation using spatial.to_featureclass(). Script worked about 6 months ago but when I tried to run it this week it threw that error.
Doesn't look like there is much traction on this but glad to know that I'm not alone and more likely a bug than code syntax. Band aid workaround is to iterate over the dataframe and construct the list of feature dictionaries. This takes either featureclass (geometry) or table (no geometry):
def convert_to_featureset(lv_sdf):
"""
helper function to convert the sdf to a list of features for the edit_feature.
.to_featureset() here is causing <weakref at 0x0000011EC04640E0; to 'ExtensionBlock' at 0x0000011EC636CCB0>
errors in arcgis 2.4.1. should be tested in newer versions of arcgis and the be re-evaluated.
"""
features = []
if "SHAPE" in [col for col in lv_sdf.columns]:
for idx, row in lv_sdf.iterrows():
# Append to features list
features.append({
"attributes": {
key: value
for key, value in row.items()
if key != 'SHAPE' and pd.notna(value)
},
"geometry": row['SHAPE'].JSON if row['SHAPE'] else None})
else:
for idx, row in lv_sdf.iterrows():
# Append to features list
features.append({"attributes": {key: value for key, value in row.items() if pd.notna(value)}})
return features
I experienced the same problem with a script I wrote a couple of months that didn't work when I tried it this week.
I found this line in my code:
pd.options.mode.copy_on_write = True
and when I removed it, the script started working again.
Hope this help
I am using that line in the scripts as well.
pd.options.mode.copy_on_write = True
Hope esri is looking at this error because pandas is making it default:
Migrating to Copy-on-Write
Copy-on-Write will be the default and only mode in pandas 3.0. This means that users need to migrate their code to be compliant with CoW rules.
The default mode in pandas will raise warnings for certain cases that will actively change behavior and thus change user intended behavior.