Hi,
I am getting this error : ValueError: Circular reference detected when I run this code. Does someone have an idea how to solve this?
from arcgis import geometry #use geometry module to project Long,Lat to X and Y
from copy import deepcopy
for Project in overlap_rows['Project']:
# get the feature to be updated
original_feature = [f for f in all_features if f.attributes['Project'] == Project][0]
feature_to_be_updated = deepcopy(original_feature)
# get the matching row from csv
matching_row = PB1_df[PB1_df['Project'] == Project].iloc[0]
#get geometries in the destination coordinate system
#input_geometry = {'y':float(matching_row['latitude']),
#'x':float(matching_row['longitude'])}
#output_geometry = geometry.project(geometries = [input_geometry],
# in_sr = 4326,
# out_sr = cities_fset.spatial_reference['latestWkid'],
# gis = gis)
# assign the updated values
#feature_to_be_updated.attributes['FID'] = int(matching_row['FID'])
#feature_to_be_updated.attributes['Begindatum'] = (matching_row['Begindatum'])
#feature_to_be_updated.attributes['Einddatum'] = (matching_row['Einddatum'])
feature_to_be_updated.attributes['Duur'] = int(matching_row['Duur'])
feature_to_be_updated.attributes['Status'] = str(matching_row['Status'])
#feature_to_be_updated.attributes['Taaknaam'] = str(matching_row['Taaknaam'])
#feature_to_be_updated.attributes['Werkzaamheden'] = str(matching_row['Werkzaamheden'])
#feature_to_be_updated.attributes['Latitude'] = (matching_row['Latitude'])
#feature_to_be_updated.attributes['Longitude'] = (matching_row['Longitude'])
#add this to the list of features to be updated
features_for_update.append(feature_to_be_updated)
print(str(feature_to_be_updated))
print("========================================================================")
WZ1_flayer.edit_features(updates = features_for_update)
---
This is the message with error:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [101], in <cell line: 1>() ----> 1 WZ1_flayer.edit_features(updates = features_for_update) File /opt/conda/lib/python3.9/site-packages/arcgis/features/layer.py:2879, in FeatureLayer.edit_features(self, adds, updates, deletes, gdb_version, use_global_ids, rollback_on_failure, return_edit_moment, attachments, true_curve_client, session_id, use_previous_moment, datum_transformation, future) 2875 params["updates"] = json.dumps( 2876 [dict(f) for f in updates], default=_date_handler 2877 ) 2878 elif isinstance(updates[0], Feature): -> 2879 params["updates"] = json.dumps( 2880 [f.as_dict for f in updates], default=_date_handler 2881 ) 2882 else: 2883 print("pass in features as list of Features, dicts or PropertyMap") File /opt/conda/lib/python3.9/json/__init__.py:234, in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw) 232 if cls is None: 233 cls = JSONEncoder --> 234 return cls( 235 skipkeys=skipkeys, ensure_ascii=ensure_ascii, 236 check_circular=check_circular, allow_nan=allow_nan, indent=indent, 237 separators=separators, default=default, sort_keys=sort_keys, 238 **kw).encode(obj) File /opt/conda/lib/python3.9/json/encoder.py:199, in JSONEncoder.encode(self, o) 195 return encode_basestring(o) 196 # This doesn't pass the iterator directly to ''.join() because the 197 # exceptions aren't as detailed. The list call should be roughly 198 # equivalent to the PySequence_Fast that ''.join() would do. --> 199 chunks = self.iterencode(o, _one_shot=True) 200 if not isinstance(chunks, (list, tuple)): 201 chunks = list(chunks) File /opt/conda/lib/python3.9/json/encoder.py:257, in JSONEncoder.iterencode(self, o, _one_shot) 252 else: 253 _iterencode = _make_iterencode( 254 markers, self.default, _encoder, self.indent, floatstr, 255 self.key_separator, self.item_separator, self.sort_keys, 256 self.skipkeys, _one_shot) --> 257 return _iterencode(o, 0) ValueError: Circular reference detected
Code formatting ... the Community Version - Esri Community
would help provide line numbers and proper indentation for those trying to look at the code
I struck this myself recently; in my case, whitespace characters in two of the string fields were causing the issue.
Using the fillna and/or str.replace methods before updating any of the feature_to_be_updated.attributes could help.