It seems that round(np.sum(Y) * fraction) is returning a float value. In the random.sample(), the value of n should be an integer. If n is a float value, it will throw the error. Make the following change and it should fix the error.
Change
n = round(np.sum(Y) * fraction)
to
n = int(round(np.sum(Y) * fraction))