Custom features not compatible with special encoding/decoding logic
MEMBER
I think you can fix this simply by replacing the line with hardcoded features with `hastattr(schema, "encode_example")` actually
2024-11-05T15:15:43Z
https://github.com/huggingface/datasets/issues/7220#issuecomment-2457443012
https://api.github.com/repos/huggingface/datasets/issues/7220
IC_kwDODunzps6SeZrE
https://api.github.com/repos/huggingface/datasets/issues/comments/2457443012/reactions
2024-11-05T15:15:43Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2457443012
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
CONTRIBUTOR
#7284 
2024-11-08T15:10:56Z
https://github.com/huggingface/datasets/issues/7220#issuecomment-2464999835
https://api.github.com/repos/huggingface/datasets/issues/7220
IC_kwDODunzps6S7Omb
https://api.github.com/repos/huggingface/datasets/issues/comments/2464999835/reactions
2024-11-08T15:10:56Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2464999835
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
### Describe the bug

It is possible to register custom features using datasets.features.features.register_feature (https://github.com/huggingface/datasets/pull/6727)

However such features are not compatible with Features.encode_example/decode_example if they require special encoding / decoding logic because encode_nested_example / decode_nested_example checks whether the feature is in a fixed list of encodable types:

https://github.com/huggingface/datasets/blob/16a121d7821a7691815a966270f577e2c503473f/src/datasets/features/features.py#L1349

This prevents the extensibility of features to complex cases

### Steps to reproduce the bug

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

### Expected behavior

Registered feature types should be encoded based on some property of the feature (e.g. requires_encoding)?

### Environment info

3.0.2