def _validate_label_types(self, labels):
        """
        Ensure the label types matched the expected types.

        Parameters
        ----------
        spec
                The spec.

        labels
                The list of labels.

        Returns
        -------
        None, throws a TypeError if not expected.
        """
        if self.spec.kNearestNeighborsClassifier.HasField("int64ClassLabels"):
            check_is_valid = KNearestNeighborsClassifierBuilder._is_valid_number_type
        else:
            check_is_valid = KNearestNeighborsClassifierBuilder._is_valid_text_type
        for label in labels:
            if not check_is_valid(label):
                raise TypeError("Invalid type for label: {}".format(type(label)))

        Ensure the label types matched the expected types.

        Parameters
        ----------
        spec
                The spec.

        labels
                The list of labels.

        Returns
        -------
        None, throws a TypeError if not expected.
        
coremltools/models/nearest_neighbors/builder.py