I think it would be beneficial to test this function separately against np.median or something as it is somewhat non-trivial.