AnsweredAssumed Answered

Numpy: adding a field to a structured array fails in Python Toolbox, but not in IDE, or Python window

Question asked by nathanielroth on May 29, 2015
Latest reply on Jul 13, 2015 by

I've got a script that I'm trying to get into a python toolbox for use and distribution. It adds a new column to a dataset that containing the quantile that a data field falls into (number of quantiles is an input as is the field, and an option to invert the quantile numbers).



It extracts the needed fields (OID, and the selected field) from a feature class using arcpy.da.FeatureClassToNumPyArray.


When I try to add a new field to the the resulting structured array using the code in a Python Toolbox, I get the following error:


Traceback (most recent call last):

  File "<string>", line 133, in execute

TypeError: data type not understood


What's odd about this, is the same code differing (as far as I can see) only in externally providing the parameter values works fine in an IDE (Eclipse/PyDev using the same Python interpreter). So does cutting and pasting the lines of code into the Python window in ArcCatalog.


If I run the same section of code for creating the copy of the structured array using only the existing fields, it also works (at least that far) in the Python Toolbox.


I have tried multiple formulations of the dtype values with the same result from: <i4, int, integer


ArcGIS 10.2.2, with the default installation of python(2.7.5) and numpy (v1.7.1).


If anyone wants to take a look, my toolbox is available at: CenterForRegionalChange/QuantileCalc · GitHub