add CustomFeature base class to support user-defined features with encoding/decoding logic
CONTRIBUTOR
@lhoestq would you be open to supporting this kind of extensibility?
2024-11-03T19:27:04Z
https://github.com/huggingface/datasets/pull/7221#issuecomment-2453549387
https://api.github.com/repos/huggingface/datasets/issues/7221
IC_kwDODunzps6SPjFL
https://api.github.com/repos/huggingface/datasets/issues/comments/2453549387/reactions
2024-11-03T19:27:04Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2453549387
https://avatars.githubusercontent.com/u/5719745?v=4
https://api.github.com/users/alex-hh/events{/privacy}
https://api.github.com/users/alex-hh/followers
https://api.github.com/users/alex-hh/following{/other_user}
https://api.github.com/users/alex-hh/gists{/gist_id}
https://github.com/alex-hh
alex-hh
MDQ6VXNlcjU3MTk3NDU=
https://api.github.com/users/alex-hh/orgs
https://api.github.com/users/alex-hh/received_events
https://api.github.com/users/alex-hh/repos
https://api.github.com/users/alex-hh/starred{/owner}{/repo}
https://api.github.com/users/alex-hh/subscriptions
User
https://api.github.com/users/alex-hh
public
MEMBER
I suggested a fix in https://github.com/huggingface/datasets/issues/7220 that would not necessarily require a parent class for custom features, lmk what you think
2024-11-05T15:16:55Z
https://github.com/huggingface/datasets/pull/7221#issuecomment-2457446100
https://api.github.com/repos/huggingface/datasets/issues/7221
IC_kwDODunzps6SeabU
https://api.github.com/repos/huggingface/datasets/issues/comments/2457446100/reactions
2024-11-05T15:16:55Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2457446100
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
intended as fix for #7220 if this kind of extensibility is something that datasets is willing to support!


```python
from datasets.features.features import CustomFeature


class ListOfStrs(CustomFeature):
    requires_encoding = True
    def _encode_example(self, value):
        if isinstance(value, str):
            return [str]
        else:
            return value
feats = Features(strlist=ListOfStrs())
feats.encode_example({"strlist": "a"})["strlist"] == feats["strlist"].encode_example("a")
```