0

I have a file geodatabase in ArcGIS with a list of parking transactions that include start and end time, and a zone. I want to calculate a field in each row that gives the occupancy in that transaction's zone at the start time, but keep receiving error messages from the expression and code block I use.

This is the expression: calculate_occupancy(!Zone!, !Parking_Start_date!, !Parking_End_date!)

Also, I am using the Calculate Field tool in Geoprocessing.

UPDATE:

I've fixed the syntax on the code block and now have this:

def calculate_occupancy(zone, start_date, end_date):
    count = 0
    table_name = r"./Default.gdb/Parkmobile"
    field_names = ["Zone", "Parking_Start_date", "Parking_End_date"]
    with arcpy.da.SearchCursor(table_name, field_names) as cursor:
        for row in cursor:
            if row[0] == zone and row[1] <= start_date and row[2] >= start_date:
                count += 1
    return count

The syntax checker confirms it is valid, but now I get the following error:

 ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
 Failed to evaluate Arcade expression. [
 Rule name: Zone_Occ,
 Triggering event: Update,
 Class name: Parkmobile,
 GlobalID: ,
 Arcade error: Object not found $featureset,
 Script line: 9]
 Failed to execute (CalculateField).

This is confusing as $featureset is nowhere in my code. I have Python selected, but it seems like this is Arcade-related.

3
  • Exclamation marks are not syntactically valid anywhere in Python. What exactly are you trying to do with !Zone! etc.? Commented Jun 15, 2023 at 17:39
  • These were required to reference the fields I wanted in the expression, but I realize now they don't belong in the code block. Commented Jun 15, 2023 at 17:59
  • Thank you for pointing this out, I was able to fix the syntax and have updated the post with a new error I'm getting. Commented Jun 15, 2023 at 18:04

1 Answer 1

0

This is hard to answer because you didn't post the part of your code where you use the "calculate_occupancy" function or the line where you used the Calculate Field tool.

From what I understand, the problem is with CalculateField, which has an "expression_type" attribute, which could be an ARCADE expression type but you are most likely using a PYTHON3 expression. Try mentioning it by adding expression_type='PYTHON3' to the CalculateField method and see if it works.

If not, please post the rest of the code so we can find out the problem and help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.