This all makes sense.  This code was obtained from Numpy (we used to just use it in Numpy, but this was declared a "private" API in Numpy 1.9, so we were forced to copy it here).  We probably should report the bug to them as well.