Select to view content in your preferred language

ArcGIS Pro Calculate Field Using Python - Return String if Field is Null not working

272
5
2 weeks ago
SaranehSFitzgerald
New Contributor
def RampQA(ramp_type😞
    if ramp_type is None:
       return "Ramp type is blank"
 
 
This hasnt worked, but feels like it should be simple... "ramp_type" is a string field. This calculation would return an error in a completely different field. Instead of returning "Ramp type is blank" it just returns Null in that field and results in this warning message:

WARNING 002858: Certain rows set to NULL due to error while evaluating python expression: File "<string>", line **, in RampQA
0 Kudos
5 Replies
DavidPike
MVP Notable Contributor

Can you post a screengrab of the expression and codeblock from Pro?  Also your text got formatted into an emoji.

0 Kudos
KenBuja
MVP Esteemed Contributor

Are the values Null, an empty string (""), or a space (" ")?

AustinAverill
Frequent Contributor

This is likely the root. Trying to verify "blank" values in field calculator is a mess. 

0 Kudos
RichardHowe
Frequent Contributor

Your expression for the above code block would need to be:

RampQA(!ramp_type!)

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You don't even need a code block for this, a Python 6.13. Conditional expressions in the expression block will do the trick:

"Ramp type is blank" if !ramp_type! is None else !ramp_type!