Modified to use target column type when encoding the data, instead of assuming same type as input.