Esri / data-assistant

ArcGIS Pro Add-in that assists in emergency management, local government and state government data aggregation workflows.
Apache License 2.0
22 stars 8 forks source link

Bugs with the SubString Method #188

Closed JRosenfeldIntern closed 7 years ago

JRosenfeldIntern commented 7 years ago

There are two bugs within the substring implementation in python Here.

First of all, if a value is null in the field that the method is acting on, the string "None" is then used as the string to slice. The value should just remain None type.

Secondly, the slicing of the string is incorrect. In the interface it asks for the number of characters after the starting position to go up to. Within the python, it merely slices it by that number.

An example of the first bug is here: pic 1 Here you can see a source field called Unit that is blank. pic 2 Here you see that the preview shows the outcome would be one, which is a substring of the string None pic 3 Here you see the incorrectly sliced String has been added to a field that should be null

An exmple of the second bug would be the following. At the moment, getSubstring looks this:

def getSubstring(sourceValue,start,chars):
    strVal = None
    try:
        start = int(start)
        chars = int(chars)
        strVal = str(sourceValue)[start:chars]
    except:
        pass
    return strVal

So if you had string "Example" starting at position 1 with the number of characters being 4, the function would return

"Example"[1:4]

Instead it should be

"Example[1:1+4]

I've implemented these changes in the following script. I would send a pull request but I'm not sure how to change the script within data assistant. If someone has a moment to show me that'd be very helpful. dlaFieldCalculator.zip @pLeBlanc93 @MikeMillerGIS @chris-fox