Original User: Caleb1987 Interesting that the totals still match. Can you post the code that goes into creating the table? I know there have been some bugs related to in_memory statistics in the past but I had thought they had all been resolved. If you copy the in_memory output to disk can you narrow down any differences?
Yes, interesting indeed. It doesn't make any sense. I did do a test where I copied all the tables to that same scratch.gdb and there were no problems so I am at a loss. What is even stranger still is that there is a total of 3 tables that were created in the 'in_memory' workspace and the other two were correct.Below is the function where this is happening. I do not change anything except the 'ws' variable and I am getting the bad result table when using 'in_memory':
def lastnameinput(Parcels, PdfPath, MXD):
try:
arcpy.env.qualifiedFieldNames = True
# Collect input from user
lastname = raw_input("\nEnter the last name and hit ENTER\n").upper()
# Select input record
query = "REALDATA.DEEDHOLDER LIKE '*%s*'" % lastname
arcpy.SelectLayerByAttribute_management(Parcels, "NEW_SELECTION", query)
result = int(arcpy.GetCount_management(Parcels).getOutput(0))
# Return message to user
print "Initial Result: %s" % result
# set up twpname to avoid crash
if result == 1:
twpname = lastname
# Deterime if more than one result returned
if result > 1:
ws = 'in_memory' # This creates ONE bad table
## ws = r'G:\Map_Documents\Walkin_requests\Scratch.gdb'
## if arcpy.Exists(ws):
## arcpy.Delete_management(ws)
## arcpy.CreateFileGDB_management(r'G:\Map_Documents\Walkin_requests','Scratch.gdb')
arcpy.Statistics_analysis(Parcels,p.join(ws,'sum_tab'),[['PARCEL.PID', 'COUNT']],'REALDATA.DEEDHOLDER')
sum_tab = p.join(ws,'sum_tab')
# Create name dictionary
with arcpy.da.SearchCursor(sum_tab,['OBJECTID','REALDATA_DEEDHOLDER','FREQUENCY']) as rows:
namedict = dict([(row[0],[row[1], row[2]]) for row in rows])
for key,value in namedict.iteritems():
print '{0} : {1}, Count={2}'.format(key, str(value[0]),
str(value[-1])) # print menu
# Collect input from user from Name dictionary
idx = int(raw_input('Enter number for name\n'))
fin = "'%s'" %str(namedict[idx][0])
query = "\"REALDATA.DEEDHOLDER\" = %s" %fin # already has ''
arcpy.SelectLayerByAttribute_management(Parcels,"NEW_SELECTION",query)
# Generate sum table for twpsec
arcpy.CopyRows_management(Parcels, p.join(ws,'copy_tab')) # copies selected rows
# Add field
copy_tab = p.join(ws,'copy_tab')
arcpy.AddField_management(copy_tab,'TWPSEC','TEXT',5)
# pop TWPSEC field
with arcpy.da.UpdateCursor(copy_tab,['PARCEL_PID','TWPSEC']) as rows:
for row in rows:
row[1] = row[0][5:10]
rows.updateRow(row)
# Sum
sum_tab2 = p.join(ws,'sum_tab2')
arcpy.Statistics_analysis(copy_tab,sum_tab2,'TWPSEC COUNT','TWPSEC') # this is the ONLY one that comes out wrong if using 'in_memory'
# twpdict
with arcpy.da.SearchCursor(sum_tab2,['OBJECTID','TWPSEC','FREQUENCY']) as rows:
twpdict = dict([(row[0],[row[1],row[2]]) for row in rows])
needmenu = raw_input('Do you wish to see Township/Area Menu? (y,n)\n').lower()
if needmenu == 'y':
township_file = r'G:\Data\Geodatabase\Cedar_County.mdb\JURISDICTION\POLITICAL_TWP'
with arcpy.da.SearchCursor(township_file,['NAME','Area_Number']) as rows:
TwpNameDict = dict([(row[0],row[1]) for row in rows])
for key,value in TwpNameDict.iteritems():
if len(key) > 7:
print '{0}\t: {1}' .format(key,value)
else:
print '{0}\t\t: {1}' .format(key,value)
# Print display
print '\n'
for key,value in twpdict.iteritems():
print '{0} : TWP-{1}, SEC{2}, Count: {3}' .format((key,str(value[0])[0:2],str(value[0])[2:5],
str(value[1]))
# TWP dictionary index
twpidx = int(raw_input('\nType number for TWP SEC\n'))
twp = '%-{0}-%' .format(str(twpdict[twpidx][0]))
# Final Selection
query = "\"REALDATA.DEEDHOLDER\" = {0} AND \"PARCEL.PID\" LIKE '{1}'" .format(fin,twp)
twpname = lastname +'_TWP_%s' %str(twpdict[twpidx]).split(',')[0][3:-1].replace('-','_')
arcpy.SelectLayerByAttribute_management(Parcels, "NEW_SELECTION", query)
result = int(arcpy.GetCount_management(Parcels).getOutput(0))
# Return message to user
print "Post Result: %s" % result
# Determine if records returned
if result:
# Return message to user
print 'selecting parcel...'
# Modify layout in map document to the selected features
df.zoomToSelectedFeatures()
df.extent = parcels.getSelectedExtent(True)
if result == 1:
df.scale *= 2.0
elif result > 1:
df.scale *= 1.4
arcpy.RefreshActiveView()
# Local Variable
pdfownername = '{0}.pdf'.format(twpname)
pdf = p.join(PdfPath, pdfownername)
# Function: call printpdf()
arcpy.env.qualifiedFieldNames = False
printpdf(MXD, pdf)
else:
# Return Error message to user
print '\n#########################################################'
print '#\tInvalid SQL statement, no selected features\t#'
print '#\tPlease verify the Name and try again\t\t#'
print '#########################################################\n'
# Function: call lastnameinput()
lastnameinput(Parcels, PdfPath, MXD)
except:
print arcpy.GetMessages(2)
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n%s\nError Info:\n%s\n" % (tbinfo, sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n%s\n" % arcpy.GetMessages(2)
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
print pymsg
print msgs