Statistics used for cleaning, such as a median for filling gaps, must be learned from the training rows only and then applied to test rows. Learning them from all rows leaks test information and makes results look better than they are.
Related: Data leakage, Imputation