Inconsistent 'Empty output generated' in Python 2.7 vs. 3.4 (Desktop vs. Pro)

1190
4
01-04-2017 03:51 AM
FilipKrál
Occasional Contributor III

Hi everyone,
I found an inconsistency between arcpy in Python 2.7 and in Python 3.4 (ArcGIS 10.4.1 and ArcGIS Pro 1.3.1 Patch 1).

The task is simple. Take an input feature class and a zone feature class, clip the input FC using the zone FC to produce a clipped FC. Then, use the statistics tool to summarize areas (or whatever) by a category field in the clipped FC.

The inconsistency occurs when the the zone feature(s) does not intersect the input feature(s):

  • In Python 2.7, result of the clip tool is an empty feature class with all the columns defined as if there was a feature. Warning 000117 ('empty output generated') is issued but the output feature class does exist. The statistics tool produces an empty output table with the expected fields included. As far as I know, this has been the usual behaviour and that's what my scripts expected.
  • In Python 3.4, result of the clip tool does not produce any output. Warning 000117 is issued but the output feature class does not exist. Calling .getOutput(0) on the clip result object returns the path where the feature class should be, but it is not actually there. Consequently, the statistics tool fails because it requires the result of the clip tool to exist.

I need my script to work in both pythons and empty results is a valuable result too. I dealt with it by checking whether the warning was issued. In my case, the task was inside a for-loop and I could simply skip to the next iteration (using the 'continue' statement) when the warning was raised. The code snippet below shows how one can check if the warning was issued and to act accordingly.

import arcpy
geology = r'C:\temp\geology.shp'
catchment = r'C:\temp\catchment.shp'
arcpy.env.workspace = r'C:\temp\wdb.gdb'

stats_table = None

clipped = arcpy.analysis.Clip(geology, catchment, 'clppd')

warnings = str(clipped.getMessages(1)).lower()

if 'empty output generated' in warnings:
    pass
else:
    clipped_fc = clipped.getOutput(0)
    stats = arcpy.analysis.Statistics(clipped_fc, 'outtbl', [["Shape_Area", "SUM"]], "LEX")
    stats_table = stats.getOutput(0)
‍‍‍‍‍‍‍‍‍‍‍‍‍

The same thing happened when I tried it in ArcGIS Pro user interface so it is probably not a Python problem, but I needed to solve it in Python.
I hope this will help someone or that someone will tell me if there is a better way to deal with it.

Cheers,
Filip.

0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

I agree, not a Python issue.  You have done a good job narrowing down the issue.  Can you open Esri Support cases?  If so, either yourself or through your organization, I suggest doing so to get this bug logged.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

You have two inputs as shapefiles and your output is not... did you try to set your clipped data out to a shapefile?  This would rule the destination to your workspace as the issue

0 Kudos
FilipKrál
Occasional Contributor III

HI Dan, that's a good tip but the inconsistency occurs even if everything is just in shapefiles.

I'll try to find somebody in my organization who can open Esri Support cases.

Cheers,

Filip.

0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

So the clipped file wasn't created?  Just trying to narrow down were the glitch is.

Another thing I noticed is the way you call the statistics tool... give this form a shot

arcpy.Statistics_analysis(intable, outtable, stats, casefield)    (I know, I know... shouldn't make a difference)

And ditto for Clip... also get rid of the getresult stuff and try to actually use the clipped file.  If you get rid of all the message/warning trapping, you may get some useful error messages which are far easier to dissect than those awful try/expcept or pass/continue things.

0 Kudos