The formula for the manual calculation is only valid if there are no ties in the rank calculation. See for example the definition and calculation part of https://en.wikipedia.org/wiki/Spearman%27s_rank_correlation_coefficient