Use Arrow filtering instead of writing a new arrow file for Dataset.filter
{'login': 'lhoestq', 'id': 42851186, 'node_id': 'MDQ6VXNlcjQyODUxMTg2', 'avatar_url': 'https://avatars.githubusercontent.com/u/42851186?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/lhoestq', 'html_url': 'https://github.com/lhoestq', 'followers_url': 'https://api.github.com/users/lhoestq/followers', 'following_url': 'https://api.github.com/users/lhoestq/following{/other_user}', 'gists_url': 'https://api.github.com/users/lhoestq/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/lhoestq/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/lhoestq/subscriptions', 'organizations_url': 'https://api.github.com/users/lhoestq/orgs', 'repos_url': 'https://api.github.com/users/lhoestq/repos', 'events_url': 'https://api.github.com/users/lhoestq/events{/privacy}', 'received_events_url': 'https://api.github.com/users/lhoestq/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'}]
{'login': 'theo-m', 'id': 17948980, 'node_id': 'MDQ6VXNlcjE3OTQ4OTgw', 'avatar_url': 'https://avatars.githubusercontent.com/u/17948980?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/theo-m', 'html_url': 'https://github.com/theo-m', 'followers_url': 'https://api.github.com/users/theo-m/followers', 'following_url': 'https://api.github.com/users/theo-m/following{/other_user}', 'gists_url': 'https://api.github.com/users/theo-m/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/theo-m/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/theo-m/subscriptions', 'organizations_url': 'https://api.github.com/users/theo-m/orgs', 'repos_url': 'https://api.github.com/users/theo-m/repos', 'events_url': 'https://api.github.com/users/theo-m/events{/privacy}', 'received_events_url': 'https://api.github.com/users/theo-m/received_events', 'type': 'User', 'site_admin': False}
[{'login': 'theo-m', 'id': 17948980, 'node_id': 'MDQ6VXNlcjE3OTQ4OTgw', 'avatar_url': 'https://avatars.githubusercontent.com/u/17948980?v=4', 'gravatar_id': '', 'url': 'https://api.github.com/users/theo-m', 'html_url': 'https://github.com/theo-m', 'followers_url': 'https://api.github.com/users/theo-m/followers', 'following_url': 'https://api.github.com/users/theo-m/following{/other_user}', 'gists_url': 'https://api.github.com/users/theo-m/gists{/gist_id}', 'starred_url': 'https://api.github.com/users/theo-m/starred{/owner}{/repo}', 'subscriptions_url': 'https://api.github.com/users/theo-m/subscriptions', 'organizations_url': 'https://api.github.com/users/theo-m/orgs', 'repos_url': 'https://api.github.com/users/theo-m/repos', 'events_url': 'https://api.github.com/users/theo-m/events{/privacy}', 'received_events_url': 'https://api.github.com/users/theo-m/received_events', 'type': 'User', 'site_admin': False}]
Currently the filter method reads the dataset batch by batch to write a new, filtered, arrow file on disk. Therefore all the reading + writing can take some time.

Using a mask directly on the arrow table doesn't do any read or write operation therefore it's significantly quicker.

I think there are two cases:
- if the dataset doesn't have an indices mapping, then one can simply use the arrow filtering on the main arrow table `dataset._data.filter(...)`
- if the dataset an indices mapping, then the mask should be applied on the indices mapping table `dataset._indices.filter(...)`

The indices mapping is used to map between the idx at `dataset[idx]` in `__getitem__` and the idx in the actual arrow table.

The new filter method should therefore be faster, and allow users to pass either a filtering function (that returns a boolean given an example), or directly a mask.

Feel free to discuss this idea in this thread :)

One additional note: the refactor at #2025 would make all the pickle-related stuff work directly with the arrow filtering, so that we only need to change the Dataset.filter method without having to deal with pickle.

cc @theo-m @gchhablani 

related issues: #1796 #1949 
{'url': 'https://api.github.com/repos/huggingface/datasets/issues/2032/reactions', 'total_count': 4, '+1': 4, '-1': 0, 'laugh': 0, 'hooray': 0, 'confused': 0, 'heart': 0, 'rocket': 0, 'eyes': 0}