<?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: Bug?: File GDB: Add Join, SelectbyAttribute, Calculate Field in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690985#M53549</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;FYI, this was confirmed by Esri support to be a bug in ArcGIS 10 SP5, but it has been fixed in 10.1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;This is Sai from Esri Tech Support and I have taken ownership of your incident #1086756. Thank you for providing the forum link and the code for testing. I was able to reproduce the same issue at my end in ArcGIS v10.0 SP5 (It works fine with a shapefile and not with a Geodatabase feature class). However, when I tested the same issue with v10.1, I was able to confirm that this has already been fixed.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 17 Oct 2012 11:14:40 GMT</pubDate>
    <dc:creator>ErikMartin</dc:creator>
    <dc:date>2012-10-17T11:14:40Z</dc:date>
    <item>
      <title>Bug?: File GDB: Add Join, SelectbyAttribute, Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690983#M53547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am having a problem with a file geodatabase join (2 feature classes) that is not happening when I use shapefiles.&amp;nbsp; I am using ArcGIS 10 SP5.&amp;nbsp; Here is my problem &amp;amp; workflow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Take Feature Class 1 and add a new field&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;calculate that field to equal an existing field&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;join the feature class to Feature Class 2&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;use select by attributes to create a selection&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;calculate the new field to equal something else, for only the selected records.&amp;nbsp; The new value is the sum of 2 fields of the same name in the 2 feature classes &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;clear the selection and remove the join&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;SPAN&gt;The problem is that after I calculate the new field to equal something new, all of the old values (calculated in step 2) are set to null for records that do not join.&amp;nbsp; Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Workspace = r"C:\Users\me\Desktop\test.gdb" arcpy.env.overwriteOutput = True arcpy.env.workspace = Workspace&amp;nbsp; FC = "PointFC1" FC2 = "PointFC2"&amp;nbsp;&amp;nbsp; arcpy.AddField_management(FC, "newAttributeX", "DOUBLE") arcpy.CalculateField_management(FC, "newAttributeX", '[AttributeX]')&amp;nbsp; arcpy.MakeFeatureLayer_management(FC, "FC_lyr") FC_lyr = "FC_lyr"&amp;nbsp; #Join FCs and create selection arcpy.AddJoin_management(FC_lyr, "JoinField", "FC2", "JoinField") selection = '"%s.OBJECTID" IS NOT NULL' %FC2 arcpy.SelectLayerByAttribute_management(FC_lyr, "NEW_SELECTION", selection )&amp;nbsp; #Calc values for newAttributeX that join to second FC expression = "[%s.AttributeX] + [%s.AttributeX]" %(FC, FC2) arcpy.CalculateField_management(FC_lyr, "%s.newAttributeX" %FC, expression)&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(FC_lyr, "CLEAR_SELECTION") arcpy.RemoveJoin_management (FC_lyr, "FC2")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Again, everything up to the selection is working properly... the problem is that all the null values (from those records that didn't join) are copied over to the new field, when in fact the field calculation should only be working on the selected records.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A viable work around is to wait to calculate the old values until the end:&lt;/SPAN&gt;&lt;BR /&gt;&lt;OL&gt;&lt;BR /&gt;&lt;LI&gt;Take Feature Class 1 and add a new field&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;join the feature class to Feature Class 2&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;use select by attributes to create a selection&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;calculate the new field to equal something else, for only the selected records.&amp;nbsp; The new value is the sum of 2 fields of the same name in the 2 feature classes &lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;clear the selection and remove the join&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;select the values in the new field that didn't join&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;calculate the null values in the new field to equal the values an existing field&lt;/LI&gt;&lt;BR /&gt;&lt;/OL&gt;&lt;SPAN&gt;However, the behavior I am getting is contrary to the documentation -- only the selected records should be calculated.&amp;nbsp; And as i mentioned above, this problem is not happening when I use 2 shapefiles.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyone else come across this problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;-Erik&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 16:45:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690983#M53547</guid>
      <dc:creator>ErikMartin</dc:creator>
      <dc:date>2012-10-12T16:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Bug?: File GDB: Add Join, SelectbyAttribute, Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690984#M53548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I could be wrong here but this is what it looks like to me is throwing off your script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
arcpy.MakeFeatureLayer_management(FC, "FC_lyr")
FC_lyr = "FC_lyr"
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I do not think that the FC_lyr variable will be accessing the feature layer you created in the line above, but rather is just creating the literal text string of "FC_lyr".&amp;nbsp; I could be wrong here but this is the only thing that I see that looks a little off.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Try this instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
FC_lyr = "FC_lyr"
arcpy.MakeFeatureLayer_management(FC, FC_lyr)
&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
FC_lyr = arcpy.MakeFeatureLayer_management(FC, "FC_lyr")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:05:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690984#M53548</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T05:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Bug?: File GDB: Add Join, SelectbyAttribute, Calculate Field</title>
      <link>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690985#M53549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;FYI, this was confirmed by Esri support to be a bug in ArcGIS 10 SP5, but it has been fixed in 10.1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;This is Sai from Esri Tech Support and I have taken ownership of your incident #1086756. Thank you for providing the forum link and the code for testing. I was able to reproduce the same issue at my end in ArcGIS v10.0 SP5 (It works fine with a shapefile and not with a Geodatabase feature class). However, when I tested the same issue with v10.1, I was able to confirm that this has already been fixed.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2012 11:14:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/bug-file-gdb-add-join-selectbyattribute-calculate/m-p/690985#M53549</guid>
      <dc:creator>ErikMartin</dc:creator>
      <dc:date>2012-10-17T11:14:40Z</dc:date>
    </item>
  </channel>
</rss>

