AnsweredAssumed Answered

Is there a bug with sorting in_memory tables using arcpy.Sort_management?

Question asked by SRoybalECC on Mar 12, 2018
Latest reply on Mar 13, 2018 by Dan_Patterson

Hi all,

 

I'm using Arc Desktop 10.5 - Standard, and I've been running into an issue with a simple script that only exports a domain to an in_memory table, then outputs the domain as another in_memory table sorted on the code field. The problem is, the record order of the "sorted" dataset comes back seemingly randomized whenever I feed arcpy.Sort_management an in_memory input table. 

 

For instance, this will return a random order result:

import arcpy

def notWorking( inputWorkSpace, domain):
     rawDomain = arcpy.DomainToTable_management(inputWorkSpace, domain, "in_memory/domain", "code", "description")
     sortedDomain = arcpy.Sort_management( rawDomain, "in_memory/sorted", [["code","ASCENDING"]] )

     with arcpy.da.SearchCursor( sortedDomain, "*" ) as cursor:
          for row in cursor:
               print("{} {}".format(row[0], row[1]))

"""
Output on domain originally defined as:

C: Charlie
E: Echo
A: Alpha
D: Delta
B: Bravo


>>>
1 B
2 C
3 A
4 E
5 D
"""

 

Meanwhile, if I store the Sort_management's input in a gdb, it works just fine:

import arcpy

def works( inputWorkSpace, domain, temporaryWorkSpace):
     rawDomain = arcpy.DomainToTable_management(inputWorkSpace, domain, temporaryWorkSpace + "\\domain", "code", "description")
     sortedDomain = arcpy.Sort_management( rawDomain, "in_memory/sorted", [["code","ASCENDING"]] )

     with arcpy.da.SearchCursor( sortedDomain, "*" ) as cursor:
          for row in cursor:
               print("{} {}".format(row[0], row[1]))


"""
Output on domain originally defined as:

C: Charlie
E: Echo
A: Alpha
D: Delta
B: Bravo


>>>
1 A
2 B
3 C
4 D
5 E
"""

 

I've attached a sample data set with a domain called "testDomain", but I've experienced this with every source (gdb/sde db) and domain I've tried.

 

While I have a work-around to get what I need done, I was wondering if there was a bug going on or if I'm missing something basic. Thanks in advance for any insight.

Attachments

Outcomes