Field Calculator & Python 3 String Reclass Warning

Viewed 509

I am throwing a python 3 warning in ArcPro which states:

Warning 002858: Certain rows set to NULL due to error while evaluating python expression: File "string", line 3, in reclass

The code I am using is as follows:

UpOrDown_PerAcre = reclass(!GP2040Area!,!UpOrDownNum!)

Code Block

def reclass(GP2040AREA, UpOrDownNum): if (UpOrDownNum != 0 or UpOrDownNum != 999): UpOrDown_PerAcre = GP2040AREA * UpOrDownNum return UpOrDown_PerAcre

What I am trying to do is, for every cell in UpOrDownNum that is not 0 or 999, output the multiple of cell GP2040ArEA and UpOrDownNum in the new column UpOrDown_PerAcre.

Line 3 would, from my understanding, be "UpOrDown_PerAcre = GP2040AREA * UpOrDownNum" which is saying the output is a string? I did have the if statement classified as if (UpOrDownNum == int and UpOrDownNum != 0 or UpOrDownNum != 999): because there -are- null values in UpOrDownNum which may be throwing a 'string' warning but it was the same after removing that from the if statement.

Where exactly did I go wrong?

1 Answers

Perhaps check UpOrDownNum is not None (Python's version of null):

def reclass(GP2040AREA, UpOrDownNum):
    if (UpOrDownNum is not None and (UpOrDownNum != 0 or UpOrDownNum != 999)):
        UpOrDown_PerAcre = GP2040AREA * UpOrDownNum
        return UpOrDown_PerAcre
    else:
        return None # or 0 or -1 or whatever you want to signify the UpOrDown_PerAcre wasn't calculated
Related