<?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: Python Calculatefield error: incompatible with the field type in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474825#M37193</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I changed NA to long and put int inside the variable like below and it now works!&lt;/P&gt;&lt;P&gt;Thanks for your suggestion for changing it to long!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1426003540077534 jive_text_macro" data-renderedposition="74_11_353_16" jivemacro_uid="_1426003540077534" modifiedtitle="true"&gt;&lt;P&gt;expression3 = "int(float('!PG!') * 12425)"&lt;/P&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Mar 2015 16:05:58 GMT</pubDate>
    <dc:creator>LisCollins</dc:creator>
    <dc:date>2015-03-10T16:05:58Z</dc:date>
    <item>
      <title>Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474820#M37188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have been having trouble with getting Calculatefield_management to accept my SQL expression variables. I have tried various ways to enter the variables to get the first two calculate field functions to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The error is now occurring with the 3rd calculate field/expression3/calculating the NA in the code below. [arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I get different errors depending on how I enter in the variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;One of the errors I get while debugging now&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "test.py", line 175, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 3354, in CalculateField&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/P&gt;&lt;P&gt;ExecuteError: ERROR 999999: Error executing function.&lt;/P&gt;&lt;P&gt;The value type is incompatible with the field type. [NA]&lt;/P&gt;&lt;P&gt;Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Method&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The first calculatefield updates the RG field based on the numbers in the !Join_Count! features column. RG is a short integer.&lt;/P&gt;&lt;P&gt;The second calculatefield updates the PG field which is (!RG!/sum of RG) * 100. PG should be a float since it's finding the percentage.&lt;/P&gt;&lt;P&gt;The third calcualtefield udpates the NA field which is !PG! * 12425. &lt;STRONG&gt;NA should be a short integer.&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on how I can write expression3 to be the correct field type format for NA? Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Background&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;-Novice Programmer&lt;/P&gt;&lt;P&gt;-Using the Python 2.75 Idle Shell&lt;/P&gt;&lt;P&gt;-Using ArcMap 10.2.1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample Code Snippet:&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import ArcPy site-package to use Arcgis and os modules to use operating system
import arcpy, os, sys, string, numpy
from arcpy import env
env.overwriteOutput = True

#set environment settings to where mxd is saved
env.workspace = r'J:\folder\scripts'

#folders
output = r'J:\folder\scripts\output' + "\\"

inFeatures = output + "joined_" + c.name + "_" + w.name + ".dbf"
print inFeatures


#First Calculate Field from spatial join count numbers 
fieldName = "RG"&amp;nbsp;&amp;nbsp;&amp;nbsp; #SHORT
expression = '!Join_Count!'&amp;nbsp;&amp;nbsp; #LONG type
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON_9.3")

print "Join Count numbers added to RG Field"

#Need sum of rg...
arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('RG'))

# Sum the RG field
print "The total sum of features in RG is: "

rg_sum = arr["RG"].sum()
print rg_sum 
flnum = "!RG!"
print flnum

#Calculate PG which equals (!RG!/Sum of !RG!) * 100
fieldName2 = "PG"&amp;nbsp;&amp;nbsp; #FLOAT type, it's a percentage number
arcpy.CalculateField_management(inFeatures, fieldName2, "(float('!RG!')) / " +&amp;nbsp; str(rg_sum) + "* 100" , "PYTHON_9.3")

arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('PG'))
PG_sum = arr["PG"].sum()
print "The total sum of features in PG is: " + str(PG_sum)&amp;nbsp; #should equal 100.0


# Calculate NA, which equals !PG! * 12425
fieldName3 = "NA"&amp;nbsp;&amp;nbsp; #SHORT type, it needs to be a whole number
expression3 = "'!PG!' * 12425"
arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")

arr = arcpy.da.FeatureClassToNumPyArray(inFeatures, ('NA'))
NA_sum = arr["NA"].sum()
print "The total sum of features in NA is: " + str(NA_sum)&amp;nbsp; #needs to equal 12425&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:59:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474820#M37188</guid>
      <dc:creator>LisCollins</dc:creator>
      <dc:date>2021-12-11T20:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474821#M37189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And if I try the the code below to make PG float and make the whole result an integer, I get this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "test.py", line 174, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; expression3 = int("float('!PG!') * 12425")&lt;/P&gt;&lt;P&gt;ValueError: invalid literal for int() with base 10: "float('!PG!') * 12425"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;expression3 = int("float('!PCTGROWTH!') * 12425")
arcpy.CalculateField_management(inFeatures, fieldName3, expression3, "PYTHON_9.3")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:59:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474821#M37189</guid>
      <dc:creator>LisCollins</dc:creator>
      <dc:date>2021-12-11T20:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474822#M37190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems your value is crossing the limit that short int can handle which is &lt;SPAN style="color: #000000; font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 12px; background-color: #eeeeee;"&gt;-32,768 to 32,767.&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;You should change it to long.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2015 15:21:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474822#M37190</guid>
      <dc:creator>MahtabAlam1</dc:creator>
      <dc:date>2015-03-10T15:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474823#M37191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@&lt;SPAN class="j-post-author"&gt;&lt;STRONG&gt;&lt;A href="https://community.esri.com/people/mahtab.gis"&gt;mahtab.gis&lt;/A&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="j-post-author"&gt;I'm still getting the same value error even after I changed the NA field to long.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2015 15:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474823#M37191</guid>
      <dc:creator>LisCollins</dc:creator>
      <dc:date>2015-03-10T15:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474824#M37192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please remove the single quotes within your expression around field name. Change your expression to something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"!PG!*12425"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2015 15:51:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474824#M37192</guid>
      <dc:creator>MahtabAlam1</dc:creator>
      <dc:date>2015-03-10T15:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python Calculatefield error: incompatible with the field type</title>
      <link>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474825#M37193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I changed NA to long and put int inside the variable like below and it now works!&lt;/P&gt;&lt;P&gt;Thanks for your suggestion for changing it to long!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1426003540077534 jive_text_macro" data-renderedposition="74_11_353_16" jivemacro_uid="_1426003540077534" modifiedtitle="true"&gt;&lt;P&gt;expression3 = "int(float('!PG!') * 12425)"&lt;/P&gt;&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Mar 2015 16:05:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-calculatefield-error-incompatible-with-the/m-p/474825#M37193</guid>
      <dc:creator>LisCollins</dc:creator>
      <dc:date>2015-03-10T16:05:58Z</dc:date>
    </item>
  </channel>
</rss>

