Select one field as the label field.

        Note that this field will be exclude from feature fields.

        :param f: Selected label field
        :type f: str
        :rtype: DataFrame
777542
def label_field(self, f):
        
        if f is None:
            raise ValueError("Label field name cannot be None.")
        self._assert_ml_fields_valid(f)
        return _change_singleton_roles(self, {_get_field_name(f): FieldRole.LABEL}, clear_feature=True)
531108
Rule FieldFile() {
		return Sequence(String("F:"),
				ZeroOrMore(WSP()).suppressNode(),
				TexText(), HeaderEol()).label(FieldFile);
	}
185366
def get_name_and_value(self, label_type):
        
        if label_type in self._label_values:
            return self._label_values[label_type]
        else:
            return (label_type, self._df_labels[label_type])
353538
def select_field(col, field_or_fields, filters=None):
    
    fields = _preprocess_field_or_fields(field_or_fields)

    if filters is None:
        filters = dict()

    wanted = {field: True for field in fields}

    if len(fields) == 1:
        header = fields[0]
        data = [doc.get(header) for doc in col.find(filters, wanted)]
        return header, data
    else:
        headers = list(fields)
        data = [[doc.get(header) for header in headers]
                for doc in col.find(filters, wanted)]
        return headers, data
957561
def labelCount(self):
        
        if self._labels is None:
            count = self.maximumLabelCount()
            if count is None:
                return 1
            else:
                return count
        
        return len(self._labels)
430835
def f(field: str, kwargs: Dict[str, Any],
      default: Optional[Any] = None) -> str:
    
    if default is not None:
        return str(kwargs.get(field, default))
    return str(kwargs[field])
641211
def p_example(self, p):
        """"""
        if len(p) > 4:
            seen_fields = set()
            for example_field in p[6]:
                if example_field.name in seen_fields:
                    self.errors.append(
                        ("Example with label '%s' defines field '%s' more "
                        "than once." % (p[2], example_field.name),
                        p.lineno(1), self.path))
                seen_fields.add(example_field.name)
            p[0] = AstExample(
                self.path, p.lineno(1), p.lexpos(1), p[2], p[5],
                OrderedDict((f.name, f) for f in p[6]))
        else:
            p[0] = AstExample(
                self.path, p.lineno(1), p.lexpos(1), p[2], None, OrderedDict())
764619
def getfield(f):
    """"""
    if isinstance(f, list):
        return [getfield(x) for x in f]
    else:
        return f.value
765336
def __set_labels(self, labels):
        
        with self.fs.open(self.fs.join(self.path, self.LABEL_FILE), 'w') \
                as file_desc:
            for label in labels:
                file_desc.write("%s,%s\n" % (label.name,
                                             label.get_color_str()))
626468
def get_fields(self, strip_labels=False):
        
        if strip_labels:
            return [
                f[0] if type(f) in (tuple, list) else f for f in self.fields
            ]
        return self.fields
491208
def setLabel(self, value, label):
        
        if label:
            self._labels[value] = label
        else:
            self._labels.pop(value, None)
12341
def check_field_cohesion(self, present_label_fields):
        
        # Ensure all written annotation fields have the same length
        nannots = len(self.sample)

        for field in ['sample', 'num', 'subtype', 'chan', 'aux_note']+present_label_fields:
            if getattr(self, field) is not None:
                if len(getattr(self, field)) != nannots:
                    raise ValueError("The lengths of the 'sample' and '"+field+"' fields do not match")

        # Ensure all label fields are defined by the label map. This has to be checked because
        # it is possible the user defined (or lack of) custom_labels does not capture all the
        # labels present.
        for field in present_label_fields:
            defined_values = self.__label_map__[field].values

            if set(getattr(self, field)) - set(defined_values) != set():
                raise ValueError('\n'.join(['\nThe '+field+' field contains elements not encoded in the stardard WFDB annotation labels, or this object\'s custom_labels field',
                                      '- To see the standard WFDB annotation labels, call: show_ann_labels()',
                                      '- To transfer non-encoded symbol items into the aux_note field, call: self.sym_to_aux()',
                                      '- To define custom labels, set the custom_labels field as a list of tuple triplets with format: (label_store, symbol, description)']))

        return
1170104
def set_field(self, name, value):
        """"""
        f = getattr(self, name, None)
        if isinstance(f, DataField):
            f.set(self, value)
        else:
            raise FieldError("No field named '%s'" % name)
800673
def find_and_remove(self, f: Callable):
        
        self._table = [fld for fld in self._table if not f(fld)]
231181
def write_conll(self, fname):
        
        if 'label' not in self.fields:
            raise InvalidFieldsException("dataset is not in CONLL format: missing label field")

        def instance_to_conll(inst):
            tab = [v for k, v in inst.items() if k != 'label']
            return '{}\n{}'.format(inst['label'], '\n'.join(['\t'.join(['-' if e is None else str(e) for e in row]) for row in zip(*tab)]))

        with open(fname, 'wb') as f:
            f.write('# {}'.format('\t'.join([k for k in self.fields if k != 'label'])))
            for i, d in enumerate(self):
                f.write('\n{}'.format(instance_to_conll(d)))
                if i != len(self) - 1:
                    f.write('\n')
460634
def select(data, field_name):
    
    if isinstance(data, Cube):
        return data._select(_normalize_selects(field_name))

    if isinstance(data, PartFlatList):
        return data.select(field_name)

    if isinstance(data, UniqueIndex):
        data = (
            data._data.values()
        )  # THE SELECT ROUTINE REQUIRES dicts, NOT Data WHILE ITERATING

    if is_data(data):
        return select_one(data, field_name)

    if is_data(field_name):
        field_name = wrap(field_name)
        if field_name.value in ["*", "."]:
            return data

        if field_name.value:
            # SIMPLIFY {"value":value} AS STRING
            field_name = field_name.value

    # SIMPLE PYTHON ITERABLE ASSUMED
    if is_text(field_name):
        path = split_field(field_name)
        if len(path) == 1:
            return FlatList([d[field_name] for d in data])
        else:
            output = FlatList()
            flat_list._select1(data, path, 0, output)
            return output
    elif is_list(field_name):
        keys = [_select_a_field(wrap(f)) for f in field_name]
        return _select(Data(), unwrap(data), keys, 0)
    else:
        keys = [_select_a_field(field_name)]
        return _select(Data(), unwrap(data), keys, 0)
1168615
def as_colr(self, label_args=None, value_args=None):
        
        label_args = label_args or {'fore': 'red'}
        value_args = value_args or {'fore': 'blue', 'style': 'bright'}
        return Colr(self.default_format.format(
            label=Colr(self.label, **label_args),
            value=Colr(repr(self.value), **value_args),
        ))