Calculate Field: Python Code Block: GP Tool Not Passing All Parameters to Code Block's Function

556
1
06-20-2021 12:38 AM
Labels (1)
ZianChoy
Occasional Contributor

I tried running Calculate Field with a code block that defined a function:

def test(incdt, t):
    result = None
    if t != "":
        result = incdt.date() + datetime.timedelta(seconds=float(t))
    return result

I ran the GP tool with the following expression:

test(!Time_Sent_To_Queue!, !F1st_Unit_Assigned!)

But, Pro says that its own GP tool isn't passing both fields. The GP tool returns:

TypeError: test() missing 1 required positional argument: 't'

I'm running Pro 2.8.0 on Windows 10.

What would make Pro fail to pass both fields to the function? The 2 source fields are of type Date and Text respectively. The destination field is a Date field.

Full GP tool history entry below:

Calculate Field
=====================
Parameters

Input Table AllColumns
Field Name (Existing or New) F1stUA_DT
Expression test(!Time_Sent_To_Queue!, !F1st_Unit_Assigned!)
Expression Type PYTHON3
Code Block def test(incdt, t):
result = None
if t != "":
result = incdt.date() + datetime.timedelta(seconds=float(t))
return result
Updated Input Table AllColumns
Field Type DATE
Enforce Domains NO_ENFORCE_DOMAINS
=====================
Messages

Start Time: Sunday, June 20, 2021 12:33:34 AM
ERROR 000539: Traceback (most recent call last):
File "<expression>", line 1, in <module>
TypeError: test() missing 1 required positional argument: 't'

Failed to execute (CalculateField).
Failed at Sunday, June 20, 2021 12:33:34 AM (Elapsed Time: 0.14 seconds)

0 Kudos
1 Reply
DanPatterson
MVP Esteemed Contributor

try adding

import datetime

before the def line

also, try switching the order of the parameters in the def to see if it still errors out


... sort of retired...