I am trying to calculate a reinspection date for surveys using the field calculator in ArcGIS Pro. I am using a predefined survey date and risk zone for this calculation. The risk zones are LOW, MED and HIGH. Low risk zones are reinspected every 1825 days, medium every 1095 days and high every 486 days. I am trying to use the known survey date and known risk zone to calculate the new reinspection date in the field calculator. This is what I have done in the field calculator :

Expression line: reclass(!SurveyDate!,!RiskZone!)
def reclass(SurveyDate, RiskZone):
    if (RiskZone == 'HIGH'):
        return SurveyDate + datetime.timedelta(days=486)
    elif (RiskZone == 'MED'):
        return  SurveyDate + datetime.timedelta(days=1095)
    elif (RiskZone == 'LOW'):
        return SurveyDate + datetime.timedelta(days=1825)

I validate the script and it confirms it is correct, however, when I run it an error message pops up.

ERROR 000539: Traceback (most recent call last):
 File "<expression>", line 1, in <module>
NameError: name 'MED' is not defined

Why is this happening? I'm not sure where the fault may be.

  • Everything looks good. Something sinister here... Are these strings coming from associated domain by any chance
    – FelixIP
    Commented Jun 17, 2021 at 5:12

1 Answer 1


As you can see from the error, it is complaining about line 1. There is no MED in Line 1 of the code block, but there IS a MED in line 1 of some iterations of the expression line.

And it's not quoted, and therefore treated as a variable name (and it is not a variable, hence the name error).

Change the expression to treat string inputs as a string literal:


Remember that ArcGIS field calculator is doing a literal interpolation of values here.

(Fixed it for me when testing with your exact code in ArcGIS Pro.)


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.