Feature Class To FeatureClass conversion 2.7 python vs 3.6 Python

1068
15
02-04-2019 12:11 PM
CCWeedcontrol
Occasional Contributor III

I am trying to test some of my 2.7 python scripts on 3.6 python and i noticed a huge difference on amount of time it takes to run the FeatureClassToFeatureClass_conversion process. so with 3.6 python the process took 18 min 5 secs, with 2.6 python it took only 8 seconds. Does anyone know why the it take much longer in 3.6 Python?

This is what i am using, there is more fields than this i just removed a lot of them.

PT1 = "C:/Temp/Scratchworkspace.gdb/Drain"

def Layers15(PT1):
    FieldMapString = "" \

                + """PIN "PIN" true true false 13 Text 0 0 ,First,#,""" + PT1 + """,Pin,-1,-1;"""\
                + """ACRES "ACRES" true true false 4 Double 0 0  ,First,#,""" + PT1+ """,ACRES,-1,-1;"""\
                + """Instrument "Instrument" true true false 10 Text 0 0 ,First,#,""" + PT1 + """,Instrument,-1,-1;"""\
                + """SiteAddres "SiteAddres" true true false 106 Text 0 0 ,First,#,""" + PT1 + """,SiteAddres,-1,-1;"""\
                + """SiteCity "SiteCity" true true false 32 Text 0 0 ,First,#,""" + PT1 + """,SiteCity,-1,-1;"""\
                + """SiteZip "SiteZip" true true false 10 Text 0 0 ,First,#,""" + PT1 + """,SiteZip,-1,-1;"""\
                + """SubName "SubName" true true false 20 Text 0 0 ,First,#,""" + PT1 + """,SubName,-1,-1;"""\       
                            

    fieldmappings = arcpy.FieldMappings()
    fieldmappings.loadFromString(FieldMapString)
    return fieldmappings


def main(args=None):
        if args is None:
                args = sys.argv

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(PT1, "C:/Temp/Scratchworkspace.gdb", "PT_ALL","", Layers15(PT1),"")
0 Kudos
15 Replies
DanPatterson_Retired
MVP Emeritus

the arcpy and arcgisscripting and all the esri stuff in Pro is different, so when you call FeatureClassToFeatureClass, there is an arcmap and an ArcGIS pro version.  If you will notice your pure python stuff in your code example very limited...

Try testing it yourself if you have an appropriate python ide that used line magics (ie IPython in Spyder etc)

def tester():
    PT1 = 'HELLO'
    FieldMapString = '''
    PIN "PIN" true true false 13 Text 0 0 ,First,#, {0}, Pin,-1,-1;
    ACRES "ACRES" true true false 4 Double 0 0  ,First,#, {0}, ACRES,-1,-1;
    Instrument "Instrument" true true false 10 Text 0 0 ,First,#, {0}, Instrument,-1,-1;
    SiteAddres "SiteAddres" true true false 106 Text 0 0 ,First,#, {0}, SiteAddres,-1,-1;
    SiteCity "SiteCity" true true false 32 Text 0 0 ,First,#, {0}, SiteCity,-1,-1;
    SiteZip "SiteZip" true true false 10 Text 0 0 ,First,#, {0}, SiteZip,-1,-1;
    SubName "SubName" true true false 20 Text 0 0 ,First,#, {0}, SubName,-1,-1;
    '''
    FieldMapString.format(PT1)
    return

# ----- timing section

tester()

%timeit tester()
2.36 µs ± 194 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

# ---- that is on my laptop, haven't tested on the desktop

So if yours is several orders of magnitude faster than 2ish microseconds then you can blame python 3... otherwise file a case with esri about the slowness of fc2fc with field mapping

0 Kudos
CCWeedcontrol
Occasional Contributor III

ok i think i understand. so i tired to run what you posted to test but i am getting invalid syntax on line with %timeit Tester()

0 Kudos
DanPatterson_Retired
MVP Emeritus

which means you don't have 'line magics' so you have an older IDE (try spyder, you will have to replace timing stuff with whatever you use)

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You answered Dan's question about the field mapping being necessary, but did you try copying without using a field mapping?  In terms of isolating the issue, it is important to know whether the field mapping is contributing to the problem or if it something else.

0 Kudos
CCWeedcontrol
Occasional Contributor III

I upgrade to Pro 2.3 this morning and now i am getting this error on line 81 and i didn't change the script at all.

RuntimeError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.

import sys, arcpy, os, fnmatch

from datetime import datetime as d
startTime = d.now()
start_time = time.time()


# Local variables:
print ('Started')
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/Scratchworkspace.gdb"
arcpy.env.qualifiedFieldNames = False
arcpy.env.preserveGlobalIds = True

PT1 = "C:/Temp/Scratchworkspace.gdb/Drain"

FieldMapString = '''
DXF_TEXT "DXF_TEXT" true true false 11 Text 0 0 ,First,#, {0}, ACRES,-1,-1;
ACCOUNT "ACCOUNT" true true false 11 Text 0 0 ,First,#, {0}, ACCOUNT,-1,-1;
PIN "PIN" true true false 13 Text 0 0 ,First,#, {0}, PIN,-1,-1;
ACRES "ACRES" true true false 4 Double 0 0  ,First,#, {0}, ACRES,-1,-1;
Instrument "Instrument" true true false 10 Text 0 0 ,First,#, {0}, Instrument,-1,-1;
SiteAddres "SiteAddres" true true false 106 Text 0 0 ,First,#, {0}, SiteAddres,-1,-1;
SiteCity "SiteCity" true true false 32 Text 0 0 ,First,#, {0}, SiteZip,-1,-1;
SiteZip "SiteZip" true true false 10 Text 0 0 ,First,#, {0}, SiteZip,-1,-1;

'''
#print(FieldMapString.format(PT1))

def Layers15(PT1, FieldMapString):
    """pass the variable and the constant into
    the function
    """
    fieldmappings = arcpy.FieldMappings()
    fieldmappings.loadFromString(FieldMapString)
    return fieldmappings

def main(args=None):
        if args is None:
                args = sys.argv

# Process: Feature Class to Feature Class
arcpy.FeatureClassToFeatureClass_conversion(PT1, "C:/Temp/Scratchworkspace.gdb", "PT_ALL","", Layers15(PT1, FieldMapString),"")

print ("Finished")
print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')

try:
    print ('(Elapsed time: ' + str(d.now() - startTime)[:-3] + ')')

except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print ("Line %i" % tb.tb_lineno)
    print (e.message)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
DanPatterson_Retired
MVP Emeritus

Over the last 10 years since python 2.x, python 3 has had a number of changes to the datetime module and dates in general

datetime — Basic date and time types — Python 3.7.2 documentation 

you should check out some of the changes and/or new features

0 Kudos