Kolmogorov-Smirnov function
The shorter version seemed better to me at first sight (because it is simpler), but actually it is incorrect. Both if statements intend to compare the same two values, but incrementing index1 changes data1[index1] for the second statement. You could fix this by assigning the values to variables:

while index1 &lt; len(data1) and index2 &lt; len(data2):
    value1, value2 = data1[index1], data2[index2]
    if value1 &lt;= value2:
        index1 += 1
    if value1 &gt;= value2:
        index2 += 1

Updating ks_stat one value at a time feels a bit awkward to me. You could collect all the absolute differences in a list and take max() of it in the end. Or, extract the loop into a generator to avoid the list.