Using Python to make XY Event Layer; get an error but the code continues

2011
16
03-13-2020 12:10 PM
deleted-user-nik7HiqJkbED
New Contributor III

Hello,

I am using python 3.6.8 to make an XY Event layer. I first use the arcpy.MakeXYEventLayer_management(inputCSV, "Longitude", "Latitude", TempFeatureLayer, WGS84, "")

where TempFeatureLayer is defined earlier as "XYTemp", and WGS84 is the variable holding the GCS_WGS84 coordinate system info.

I pass this and get an error the first time that is pretty extensive but the end says: "

SystemError: <built-in function isinstance> returned a result with an error set"

 I am able to continue running the code successfully inspite of this seeming error. I would like for this to simply not show up as the code will go to someone with little experience and i dont want this to trigger concern.

Interestingly when I run the code again for the next input, this error does not appear again....

Does anyone know of an exception handling i can use to eliminate this?

I am currently running 10.7 desktop and have been working in the jupityer notebooks version that comes with this desktop version.

i have attached the error and the python code i wrote. the section happens at line 277

Thank you for the help

0 Kudos
16 Replies
by Anonymous User
Not applicable

So it looks like the error is coming from numpy, which could be used by other modules (op.py) that you are indirectly using.  It is checking if the object's (featureclass in this case maybe?) dataframe is an instance of a numpy array and failing.

You could probably place that in a try/ except and just pass in the block to hide it.

try:
    XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except SystemError:
    pass
0 Kudos
deleted-user-nik7HiqJkbED
New Contributor III

Thank you so much for the quick response!

One question- do I need to set “SystemError” as a variable by defining it before I write the “except SystemError” command?

I apologize for this newbee question- I am what you might call a “baby pythoner” right now.

Thanks for the help!!

Sophia

0 Kudos
by Anonymous User
Not applicable

No problem-

You don't have to assign it because it is a named built-in exception (others are Exception, RuntimeError, TypeError, etc).  You could assign it to a variable and then do stuff with it though like log it, message it, ignore it.  Python docs for it are here: Built-in Exceptions — Python 3.8.2 documentation 

try:
    XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except SystemError as se:
    print(se)

0 Kudos
deleted-user-nik7HiqJkbED
New Contributor III

Thank you Mr. Kling.

I tried the following attempts:

1.

SystemError = "SystemError: <built-in function isinstance> returned a result with an error set"

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except SystemError:

pass

Result: no change- error still raised

2.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except SystemError as se:

pass

Result: no change- error still raised

3.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except SystemError:

pass

Result: no change- error still raised

Did I perhaps write the expression incorrectly?

Or do you perhaps have any other ideas? I was unsure how to even research this exception. I greatly appreciate the exceptions page you shared and will continue to look down that road but if you have any other insights I would be very appreciative.

Thanks so much!!

Sophia

SOPHIA THOMPSON

gis coordinator

o 505.924.3803

e ssthompson@cabq.gov<mailto:ssthompson@cabq.gov>

cabq.gov/planning<https://www.cabq.gov/planning>

0 Kudos
by Anonymous User
Not applicable

Rats.  Looking at the error message again it starts with a ValueError.  Maybe try catching both (TypeError thrown in for good measure):

except (ValueError, SystemError, TypeError):
    pass

if those don't catch it, maybe defaulting to catching all through using just Exception:

except Exception:
    pass
0 Kudos
deleted-user-nik7HiqJkbED
New Contributor III

Thanks so much for the alternative ideas! I will give those a try on Monday

I hope you have a great weekend!

Sophia

BlakeTerhune
MVP Regular Contributor

The suggestions from Jeff Kling‌ are effective but be careful catching and passing on a wide range of errors because you'll never know if there's a different problem you actually need to address.

deleted-user-nik7HiqJkbED
New Contributor III

Hi Jeff,

Thanks very much for the suggestions. I tried:

1.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except (ValueError, SystemError, TypeError):

pass

2.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except ValueError, SystemError, TypeError:

pass

3.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except ValueError, SystemError:

pass

4.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except (ValueError, SystemError):

pass

5.

try:

XYEventsFL = ap.MakeXYEventLayer_management(CleanedIncidentsPath, "Longitude", "Latitude",XYEventsTemp, WGS84, "")

except Exception:

pass

but unfortunately none of the above have prevented the errors from running. It appears that an error is triggered for each row in the csv table being used to make the XY Event layer and is quite extensive (greater than 80,000 records in some cases)

I have noticed when I run the code thru IPython in the 10.8 version or thru Jupyter notebook in the 10.8 version the error is not triggered….

It seems really surprising to me that even Exception did not work….I feel I may be grasping at straws in light of this seeming override command not having any effect but do you by chance have any other thoughts? Perhaps I did not write the code correctly?

Thanks very much for the help!

Sophia

0 Kudos
by Anonymous User
Not applicable

Well, I think in your attempts that have tried pretty much covered any combination options... I am kind of wondering if it is a mismatched package issue, seeing how its fine in python 2 (10.8) and 3 (3.6) it's not.  I get a ton of GDAL DLL errors in python 3 from the cloned environment, which I believe is caused by mismatched versions of the GDAL files and the version that the module is requesting.

Maybe look at if the package needs to be upgraded/ downgraded a version?

0 Kudos