<?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 Calculate Field,  SyntaxError invalid syntax partially working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094369#M62222</link>
    <description>&lt;P&gt;I'm attempting to run a script to calculate a field that is conditional.&amp;nbsp; If &lt;STRONG&gt;float2&lt;/STRONG&gt; is available I want to calculate the ratio of &lt;STRONG&gt;float1/float2&lt;/STRONG&gt;, if it is null I want to use the ratio of &lt;STRONG&gt;float1/float3&lt;/STRONG&gt;, and then leave null if both &lt;STRONG&gt;float2&lt;/STRONG&gt; and &lt;STRONG&gt;float3&lt;/STRONG&gt; are null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script doesn't immediately fail when running, but does error out after a few thousand records with the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Derek_Mink_0-1630503152044.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/22173i5CA5F53597B3AEC9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Derek_Mink_0-1630503152044.png" alt="Derek_Mink_0-1630503152044.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;PRE&gt;calc(!float1!, !text1!, !float2!, !float3!)&lt;/PRE&gt;&lt;P&gt;Code Block:&lt;/P&gt;&lt;PRE&gt;def calc(f1, t1, f2, f3):&lt;BR /&gt;    if f1 &amp;gt; 0 and t1 == "H":&lt;BR /&gt;        if f2:&lt;BR /&gt;            return f1 / f2&lt;BR /&gt;        elif f3:&lt;BR /&gt;            return f1 / f3&lt;BR /&gt;        else:&lt;BR /&gt;            return None&lt;BR /&gt;    else:&lt;BR /&gt;        return None&lt;/PRE&gt;&lt;P&gt;Any ideas on what is happening here or how to address it?&amp;nbsp; &lt;STRONG&gt;!float1!&lt;/STRONG&gt; is indeed a float, so my first thought that maybe there was some hard coded scientific notation in there doesn't seem to be an issue.&amp;nbsp; Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 13:48:33 GMT</pubDate>
    <dc:creator>DMink</dc:creator>
    <dc:date>2021-09-01T13:48:33Z</dc:date>
    <item>
      <title>Calculate Field,  SyntaxError invalid syntax partially working</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094369#M62222</link>
      <description>&lt;P&gt;I'm attempting to run a script to calculate a field that is conditional.&amp;nbsp; If &lt;STRONG&gt;float2&lt;/STRONG&gt; is available I want to calculate the ratio of &lt;STRONG&gt;float1/float2&lt;/STRONG&gt;, if it is null I want to use the ratio of &lt;STRONG&gt;float1/float3&lt;/STRONG&gt;, and then leave null if both &lt;STRONG&gt;float2&lt;/STRONG&gt; and &lt;STRONG&gt;float3&lt;/STRONG&gt; are null.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The script doesn't immediately fail when running, but does error out after a few thousand records with the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Derek_Mink_0-1630503152044.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/22173i5CA5F53597B3AEC9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Derek_Mink_0-1630503152044.png" alt="Derek_Mink_0-1630503152044.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;PRE&gt;calc(!float1!, !text1!, !float2!, !float3!)&lt;/PRE&gt;&lt;P&gt;Code Block:&lt;/P&gt;&lt;PRE&gt;def calc(f1, t1, f2, f3):&lt;BR /&gt;    if f1 &amp;gt; 0 and t1 == "H":&lt;BR /&gt;        if f2:&lt;BR /&gt;            return f1 / f2&lt;BR /&gt;        elif f3:&lt;BR /&gt;            return f1 / f3&lt;BR /&gt;        else:&lt;BR /&gt;            return None&lt;BR /&gt;    else:&lt;BR /&gt;        return None&lt;/PRE&gt;&lt;P&gt;Any ideas on what is happening here or how to address it?&amp;nbsp; &lt;STRONG&gt;!float1!&lt;/STRONG&gt; is indeed a float, so my first thought that maybe there was some hard coded scientific notation in there doesn't seem to be an issue.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:48:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094369#M62222</guid>
      <dc:creator>DMink</dc:creator>
      <dc:date>2021-09-01T13:48:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field,  SyntaxError invalid syntax partially working</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094373#M62223</link>
      <description>&lt;P&gt;It seems to be an error associated with that particular record.&amp;nbsp; When I select on the record and do a simple calculation of float1 / float2 I get the same error.&amp;nbsp; Any idea what this could be or how to fix?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Derek_Mink_0-1630504759970.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/22174i77BD4B439C846ED1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Derek_Mink_0-1630504759970.png" alt="Derek_Mink_0-1630504759970.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 13:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094373#M62223</guid>
      <dc:creator>DMink</dc:creator>
      <dc:date>2021-09-01T13:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field,  SyntaxError invalid syntax partially working</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094394#M62224</link>
      <description>&lt;P&gt;You should use DOUBLE datatype for floating values of more than six-digits. Create a new DOUBLE field and assign the values of Field1 to it.&lt;/P&gt;&lt;P&gt;Could you test the following code block (Test with Field1 or the new field)?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def calc(f1, t1, f2, f3):
    if f1 &amp;gt; 0 and t1 == "H":
        if f2 &amp;gt; 0:
            return (f1 / f2)
        elif f3 &amp;gt; 0:
            return (f1 / f3)
        else:
            return None
    else:
        return None&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 14:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094394#M62224</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2021-09-01T14:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field,  SyntaxError invalid syntax partially working</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094395#M62225</link>
      <description>&lt;P&gt;OK, I'm convinced it has something to do with the scientific notation.&amp;nbsp; I have some records with float1 = 10,000,000 ; 20,000,000 ; 50,000,000 and they are the only ones that fail.&amp;nbsp; It seems as long as the value doesn't result in a number divisible by 10 million it works.&amp;nbsp; Other records have values 10 million plus.&lt;/P&gt;&lt;P&gt;What's going on here?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 14:31:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094395#M62225</guid>
      <dc:creator>DMink</dc:creator>
      <dc:date>2021-09-01T14:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field,  SyntaxError invalid syntax partially working</title>
      <link>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094524#M62230</link>
      <description>&lt;P&gt;Thanks for your feedback Jayanta.&lt;/P&gt;&lt;P&gt;The feature class I'm using is created in a script from a sql server table and upon import the field is created as a float (using arcpy.XYTableToPoint_management).&amp;nbsp; If I create a new field, set to double, and try to populate with the float1 value it doesn't work:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Derek_Mink_0-1630515947784.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/22208i679F63870AD7C185/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Derek_Mink_0-1630515947784.png" alt="Derek_Mink_0-1630515947784.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, I don't follow how the double datatype is required here since if I run this calculation excluding only the float1 values that are multiples of 10 million it works.&lt;/P&gt;&lt;P&gt;EDIT: So those were the cases where it crashed, but values weren't always being calculated elsewhere.&amp;nbsp; How do I create the featureclass and ensure the incoming fields are set to DOUBLE?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 18:52:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculate-field-syntaxerror-invalid-syntax/m-p/1094524#M62230</guid>
      <dc:creator>DMink</dc:creator>
      <dc:date>2021-09-01T18:52:26Z</dc:date>
    </item>
  </channel>
</rss>

