Converting a Value to a ClassLabel
{'login': 'nelson-liu', 'id': 7272031, 'node_id': 'MDQ6VXNlcjcyNzIwMzE=', 'avatar_url': 'https://avatars.githubusercontent.com/u/7272031?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/nelson-liu', 'html_url': 'https://github.com/nelson-liu', 'followers_url': 'https://api.github.com/users/nelson-liu/followers', 'following_url': 'https://api.github.com/users/nelson-liu/following{/other_user}', 'gists_url': 'https://api.github.com/users/nelson-liu/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/nelson-liu/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/nelson-liu/subscriptions', 'organizations_url': 'https://api.github.com/users/nelson-liu/orgs', 'repos_url': 'https://api.github.com/users/nelson-liu/repos', 'events_url': 'https://api.github.com/users/nelson-liu/events{/privacy}', 'received_events_url': 'https://api.github.com/users/nelson-liu/received_events', 'type': 'User', 'site_admin': False}
[{'id': 1935892871, 'node_id': 'MDU6TGFiZWwxOTM1ODkyODcx', 'url': 'https://api.github.com/repos/huggingface/datasets/labels/enhancement', 'name': 'enhancement', 'color': 'a2eeef', 'default': True, 'description': 'New feature or request'}]
[]
Hi @nelson-liu!
Here is what I do to convert a string to class label:

```python
from datasets import load_dataset, features


dset = load_dataset(...)
col_name = "the string column name"

class_names  = dset.unique(col_name)
class_feature = features.ClassLabel(names=sorted(class_names))
dset = dset.map(lambda str_value: {col_name: class_feature.str2int(str_value)}, input_columns=col_name)

dset = dset.cast(features.Features({
    ...
    col_name: class_feature
})
```
 Hi! You can use `Dataset.class_encode_column` for this. And in the next release of `datasets` (this feature is only available on `master`), you'll also be able to use `cast` to do the conversion. 

An example of conversion via `cast`: 
```python
from datasets import Dataset, Features, ClassLabel
d = Dataset.from_dict({"a": ["no", "yes", "no"]})
d = d.cast(Features({"a": ClassLabel(names=["yes", "no"])}))
```
Hi!

In the docs for `cast`, it's noted that `For non-trivial conversion, e.g. string <-> ClassLabel you should use map() to update the Dataset.`

Would it be possible to have an example  that demonstrates such a string <-> ClassLabel conversion using `map`? Thanks!
{'url': 'https://api.github.com/repos/huggingface/datasets/issues/2176/reactions', 'total_count': 1, '+1': 1, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}