Esri / incident-import-tools

Toolbox and scripts for importing spreadsheets to a gdb and optionally publishing out to ArcGIS Online or ArcGIS for Server.
Apache License 2.0
11 stars 16 forks source link

Exception thrown with delete duplicates #10

Closed chris-fox closed 6 years ago

chris-fox commented 6 years ago

Exception thrown here when geocoding addresses because loc_fields is a list of strings rather than a string. If you get past this error it throws an exception at len(dup_rows) error: object of type 'da.UpdateCursor' has no len()

        with arcpy.da.UpdateCursor(tempTable, [dt_field,loc_fields], where_dup) as dup_rows:
            recent_date = ""
            while len(dup_rows) > 1:
                for dup_row in dup_rows:
                    if dup_row[0] > recent_date:
                        recent_date = dup_row[0]
                    else:
                        dup_rows.delete(dup_row)
                        del_count += 1
cosbyr commented 6 years ago

@chris-fox Fixed this and other errors that occurred after this point. Your test data was good at exposing some logic problems. Its interesting that your test data has records with the same IDs AND the same dates for each record. In this case it will just pick one of them. It looks like your "date_completed" field has more unique dates that should be used instead. I ended up using an SQL ORDER BY clause in the update cursor to just bring the most current record to the top based on date. This seems to be a good default for when a group of records with the same IDs have records with the same date (like your data) or when there is a mix of null dates and populated dates

chris-fox commented 6 years ago

Thanks @cosbyr, looks good. I saw the duplicate permit ids as well, need to work with the customer to understand why that scenario might occur.