<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute  in ModelBuilder Questions</title>
    <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824839#M684</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A colleague of mine find an article that might help me:&amp;nbsp;&amp;nbsp;&lt;A class="link-titled" href="https://support.esri.com/en/technical-article/000011840" title="https://support.esri.com/en/technical-article/000011840"&gt;How To: Calculate fields where some inputs are null values&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears at this point that if I do the test for None at the beginning of the function, instead of down in the existing if statement, it may work.&amp;nbsp; I'm currently testing this change.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Oct 2020 19:31:02 GMT</pubDate>
    <dc:creator>MikeSayre</dc:creator>
    <dc:date>2020-10-22T19:31:02Z</dc:date>
    <item>
      <title>When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824835#M680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to convert some VB Calculate Field code to Python for use in ArcGIS Pro.&amp;nbsp; This code would work in VB, but I'm unable to get the Python syntax to execute in all scenarios.&amp;nbsp; I have a simplified example of what I trying to do below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field name = type&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DetermineType(!lanes!,!speed!)&amp;nbsp; - this goes in the expression box&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following is in the code block:&lt;/P&gt;&lt;P&gt;def DetermineType(Lanes, Speed):&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;if Lanes.rstrip() == "1" and int(Speed.rstrip()) &amp;lt; 30:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;elif Lanes.rstrip() == "2" and int(Speed.rstrip()) &amp;lt; 30:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return 2&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;elif Lanes.rstrip() == "3" and int(Speed.rstrip()) &amp;gt; 30:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return 3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;else:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return 4&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will work as long as a row of data has values for both the Lanes and Speed field attributes.&amp;nbsp; However, if one of these fields is null, I would expect a value of 4 to be returned to populate the type field but instead, my code block doesn't get executed at all.&amp;nbsp; I end up with null in the type field.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question is this:&amp;nbsp; How do I populate a field if either of the input fields used to determine its value is null?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, I've tried several experiments, including just concatenating !lanes! and !speed! in the Expression box, but as long as at least one of those fields is null, I get a null result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 16:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824835#M680</guid>
      <dc:creator>MikeSayre</dc:creator>
      <dc:date>2020-10-22T16:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824836#M681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is what your code looks like when you use the syntax highlighter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;DetermineType&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Lanes&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Speed&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

   &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; Lanes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"1"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Speed&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;30&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;

   &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; Lanes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"2"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Speed&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;30&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt;

   &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; Lanes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"3"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Speed&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;30&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;

   &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;

      &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;4&lt;/SPAN&gt; &lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to check for the &amp;lt;Null&amp;gt; values specifically with:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; Lanes&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;rstrip&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   do what you need to do&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 09:49:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824836#M681</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-12T09:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824837#M682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, but that's not working because the program execution never gets into the "if" statement at all if Lanes or Speed are null/None.&amp;nbsp; If you try to do a function call by passing in a null value, it will bypass the function completely and move onto the next step in the Model.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 17:57:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824837#M682</guid>
      <dc:creator>MikeSayre</dc:creator>
      <dc:date>2020-10-22T17:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824838#M683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Guess I missed that it's a function.&amp;nbsp; How are you calling the function?&amp;nbsp; Can you trap for &amp;lt;Null&amp;gt; values before hand, and then pass something like -999 to your function?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 18:13:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824838#M683</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2020-10-22T18:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824839#M684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A colleague of mine find an article that might help me:&amp;nbsp;&amp;nbsp;&lt;A class="link-titled" href="https://support.esri.com/en/technical-article/000011840" title="https://support.esri.com/en/technical-article/000011840"&gt;How To: Calculate fields where some inputs are null values&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It appears at this point that if I do the test for None at the beginning of the function, instead of down in the existing if statement, it may work.&amp;nbsp; I'm currently testing this change.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2020 19:31:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824839#M684</guid>
      <dc:creator>MikeSayre</dc:creator>
      <dc:date>2020-10-22T19:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: When using Python in a Model Builder Calculate Field operation and one of the input field values is null, code does not execute</title>
      <link>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824840#M685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To follow up, I was able to get this working by bringing my original model into ArcGIS Pro, editing the syntax of the calculate field functions there, and including tests for None at the beginning of the functions.&amp;nbsp; I had previously been editing the Python code in ArcMap, and when I exported the functionality to a python script and tried to run it using ArcPro libraries, it wasn't the exact flavor of Python needed by Pro.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Nov 2020 15:04:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/modelbuilder-questions/when-using-python-in-a-model-builder-calculate/m-p/824840#M685</guid>
      <dc:creator>MikeSayre</dc:creator>
      <dc:date>2020-11-02T15:04:07Z</dc:date>
    </item>
  </channel>
</rss>

