1

The following code isn't working as expected and I'm not sure why:

 UpOrDown = reclass(!UpOrDown!) 
 def reclass (Z,GP):
 if (GP == "DT" and Z == "CG"):
 UpOrDown = 1
 if (GP == "DT" and Z == "CN"):
 UpOrDown = 1
 if (GP == ...and so on.... )

The expression is passing as valid but the wrning (warning 002858) suggests that there is a TypeError in reclass() which is missing the argument 'G'.

enter image description here

I have added this into the code at UpOrDown = reclass(!UpOrDown!,!G!) which returns no error but doesn't output the expected variable of 1 in the UpOrDown column (which is Double).

I also changed the dependent variables to both Z and GP which still didn't change anything.

enter image description here

What is missing?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 20, 2020 at 21:26
5
  • 3
    You have one argument reclass(!UpOrDown!) and two in the arglist def reclass (Z,GP) and you don't show what is returned. Look again at the documentation. 1) same number of arguments, 2) return a singleton value Commented May 20, 2020 at 21:47
  • I took your advice but it's still not working. Commented May 20, 2020 at 22:02
  • 4
    As @Vince mentioned, you need a return statement in your function. At the end, type return UpOrDown. Commented May 20, 2020 at 22:05
  • 2
    Please always provide errors as formatted text rather than pictures. That way they are available to future searches by others stuck at the same place, and be easily readable on all devices. Commented May 20, 2020 at 22:44
  • You should also use elif in your conditional logic (or return 1 instead of not returning the set variable) Commented May 21, 2020 at 2:21

1 Answer 1

2

The field calculator needs to return a value that will be populated onto your field. Your current code just sets a variable UpOrDown, it doesn't tell the calculator what to write.

Additionally you should use elif rather than if for your subsequent lines so that the parser only processes what it needs to, and then finish up with an else to handle what happens if none of the if/elif do anything.

reclass(!Parcels_Zoning_Interest_ZONINGABBREV!, !GPABBREVIATION!)

def reclass (Z,GP):
 if (GP == "DT" and Z == "CG"):
 UpOrDown = 1
 elif (GP == "DT" and Z == "CN"):
 UpOrDown = 2
 elif (GP == "this" and Z == "that" ):
 UpOrDown = 3
 else:
 UpOrDown = 0
 return UpOrDown
answered Jun 24, 2020 at 21:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.