Check a particular annotation field

def check_field(self, field):
        """
        Check a particular annotation field
        """

        item = getattr(self, field)

        if not isinstance(item, ALLOWED_TYPES[field]):
            raise TypeError('The '+field+' field must be one of the following types:', ALLOWED_TYPES[field])

        # Numerical integer annotation fields: sample, label_store, sub,
        # chan, num
        if ALLOWED_TYPES[field] == (np.ndarray):
            record.check_np_array(item=item, field_name=field, ndim=1,
                                  parent_class=np.integer, channel_num=None)

        # Field specific checks
        if field == 'record_name':
            if bool(re.search('[^-\w]', self.record_name)):
                raise ValueError('record_name must only comprise of letters, digits, hyphens, and underscores.')
        elif field == 'extension':
            if bool(re.search('[^a-zA-Z]', self.extension)):
                raise ValueError('extension must only comprise of letters.')
        elif field == 'fs':
            if self.fs <=0:
                raise ValueError('The fs field must be a non-negative number')
        elif field == 'custom_labels':
            """
            The role of this section is just to check the
            elements of this item, without utilizing
            any other fields. No format conversion
            or free value looksups etc are done.
            """

            # Check the structure of the subelements
            if isinstance(item, pd.DataFrame):
                column_names = list(item)
                if 'symbol' in column_names and 'description' in column_names:
                    if 'label_store' in column_names:
                        label_store = list(item['label_store'].values)
                    else:
                        label_store = None
                    symbol = item['symbol'].values
                    description = item['description'].values
                else:
                    raise ValueError(''.join(['If the '+field+' field is pandas dataframe, its columns',
                                             ' must be one of the following:\n-[label_store, symbol, description]',
                                             '\n-[symbol, description]']))
            else:
                if set([len(i) for i in item]) == {2}:
                    label_store = None
                    symbol = [i[0] for i in item]
                    description = [i[1] for i in item]
                elif set([len(i) for i in item]) == {3}:
                    label_store = [i[0] for i in item]
                    symbol = [i[1] for i in item]
                    description = [i[2] for i in item]
                else:
                    raise ValueError(''.join(['If the '+field+' field is an array-like object, its subelements',
                                             ' must be one of the following:\n- tuple triplets storing: ',
                                             '(label_store, symbol, description)\n- tuple pairs storing: ',
                                             '(symbol, description)']))

            # Check the values of the subelements
            if label_store:
                if len(item) != len(set(label_store)):
                    raise ValueError('The label_store values of the '+field+' field must be unique')

                if min(label_store) < 1 or max(label_store) > 49:
                    raise ValueError('The label_store values of the custom_labels field must be between 1 and 49')

            if len(item) != len(set(symbol)):
                raise ValueError('The symbol values of the '+field+' field must be unique')

            for i in range(len(item)):
                if label_store:
                    if not hasattr(label_store[i], '__index__'):
                        raise TypeError('The label_store values of the '+field+' field must be integer-like')

                if not isinstance(symbol[i], str_types) or len(symbol[i]) not in [1,2,3]:
                    raise ValueError('The symbol values of the '+field+' field must be strings of length 1 to 3')

                if bool(re.search('[ \t\n\r\f\v]', symbol[i])):
                    raise ValueError('The symbol values of the '+field+' field must not contain whitespace characters')

                if not isinstance(description[i], str_types):
                    raise TypeError('The description values of the '+field+' field must be strings')

                # Would be good to enfore this but existing garbage annotations have tabs and newlines...
                #if bool(re.search('[\t\n\r\f\v]', description[i])):
                #    raise ValueError('The description values of the '+field+' field must not contain tabs or newlines')

        # The string fields
        elif field in ['symbol', 'description', 'aux_note']:
            uniq_elements = set(item)

            for e in uniq_elements:
                if not isinstance(e, str_types):
                    raise TypeError('Subelements of the '+field+' field must be strings')

            if field == 'symbol':
                for e in uniq_elements:
                    if len(e) not in [1,2,3]:
                        raise ValueError('Subelements of the '+field+' field must be strings of length 1 to 3')
                    if bool(re.search('[ \t\n\r\f\v]', e)):
                        raise ValueError('Subelements of the '+field+' field may not contain whitespace characters')
            else:
                for e in uniq_elements:
                    if bool(re.search('[\t\n\r\f\v]', e)):
                        raise ValueError('Subelements of the '+field+' field must not contain tabs or newlines')

        elif field == 'sample':
            if len(self.sample) == 1:
                sampdiffs = np.array([self.sample[0]])
            elif len(self.sample) > 1:
                sampdiffs = np.concatenate(([self.sample[0]], np.diff(self.sample)))
            else:
                raise ValueError("The 'sample' field must be a numpy array with length greater than 0")
            if min(self.sample) < 0 :
                raise ValueError("The 'sample' field must only contain non-negative integers")
            if min(sampdiffs) < 0 :
                raise ValueError("The 'sample' field must contain monotonically increasing sample numbers")
            if max(sampdiffs) > 2147483648:
                raise ValueError('WFDB annotation files cannot store sample differences greater than 2**31')

        elif field == 'label_store':
            if min(item) < 1 or max(item) > 49:
                raise ValueError('The label_store values must be between 1 and 49')

        # The C WFDB library stores num/sub/chan as chars.
        elif field == 'subtype':
            # signed character
            if min(self.subtype) < 0 or max(self.subtype) >127:
                raise ValueError("The 'subtype' field must only contain non-negative integers up to 127")
        elif field == 'chan':
            # un_signed character
            if min(self.chan) < 0 or max(self.chan) >255:
                raise ValueError("The 'chan' field must only contain non-negative integers up to 255")
        elif field == 'num':
            # signed character
            if min(self.num) < 0 or max(self.num) >127:
                raise ValueError("The 'num' field must only contain non-negative integers up to 127")

        return