Allow opposite of remove_columns on Dataset and DatasetDict
COLLABORATOR
Hi! I agree it would be nice to have a method like that. Instead of `keep_columns`, we can name it `select_columns` to be more aligned with PyArrow's naming convention (`pa.Table.select`).
2023-01-26T13:55:59Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1405041180
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5Tvzoc
https://api.github.com/repos/huggingface/datasets/issues/comments/1405041180/reactions
2023-01-26T13:56:19Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1405041180
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
NONE
Hi, I am a newbie to open source and would like to contribute. @mariosasko can I take up this issue ?
2023-01-27T07:31:32Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1406123173
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5Tz7yl
https://api.github.com/repos/huggingface/datasets/issues/comments/1406123173/reactions
2023-01-27T07:31:32Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1406123173
https://avatars.githubusercontent.com/u/97785770?v=4
https://api.github.com/users/avisinghal6/events{/privacy}
https://api.github.com/users/avisinghal6/followers
https://api.github.com/users/avisinghal6/following{/other_user}
https://api.github.com/users/avisinghal6/gists{/gist_id}
https://github.com/avisinghal6
avisinghal6
U_kgDOBdQXqg
https://api.github.com/users/avisinghal6/orgs
https://api.github.com/users/avisinghal6/received_events
https://api.github.com/users/avisinghal6/repos
https://api.github.com/users/avisinghal6/starred{/owner}{/repo}
https://api.github.com/users/avisinghal6/subscriptions
User
https://api.github.com/users/avisinghal6
public
NONE
Hey, I also want to work on this issue I am a newbie to open source. 
2023-01-27T08:08:44Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1406152562
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T0C9y
https://api.github.com/repos/huggingface/datasets/issues/comments/1406152562/reactions
2023-01-27T08:08:44Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1406152562
https://avatars.githubusercontent.com/u/59472284?v=4
https://api.github.com/users/vijaybirju/events{/privacy}
https://api.github.com/users/vijaybirju/followers
https://api.github.com/users/vijaybirju/following{/other_user}
https://api.github.com/users/vijaybirju/gists{/gist_id}
https://github.com/vijaybirju
vijaybirju
MDQ6VXNlcjU5NDcyMjg0
https://api.github.com/users/vijaybirju/orgs
https://api.github.com/users/vijaybirju/received_events
https://api.github.com/users/vijaybirju/repos
https://api.github.com/users/vijaybirju/starred{/owner}{/repo}
https://api.github.com/users/vijaybirju/subscriptions
User
https://api.github.com/users/vijaybirju
public
MEMBER
This sounds related to https://github.com/huggingface/datasets/issues/5474

I'm fine with `select_columns`, or we could also override `select` to also accept a list of columns maybe ?
2023-01-27T12:19:39Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1406423445
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T1FGV
https://api.github.com/repos/huggingface/datasets/issues/comments/1406423445/reactions
2023-01-27T12:19:39Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1406423445
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
NONE
@lhoestq, I am planning to add a member function to the dataset class to perform the selection operation. Do you think its the right way to proceed? or there is a better option ?
2023-01-27T19:24:20Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1406974210
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T3LkC
https://api.github.com/repos/huggingface/datasets/issues/comments/1406974210/reactions
2023-01-27T19:24:20Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1406974210
https://avatars.githubusercontent.com/u/97785770?v=4
https://api.github.com/users/avisinghal6/events{/privacy}
https://api.github.com/users/avisinghal6/followers
https://api.github.com/users/avisinghal6/following{/other_user}
https://api.github.com/users/avisinghal6/gists{/gist_id}
https://github.com/avisinghal6
avisinghal6
U_kgDOBdQXqg
https://api.github.com/users/avisinghal6/orgs
https://api.github.com/users/avisinghal6/received_events
https://api.github.com/users/avisinghal6/repos
https://api.github.com/users/avisinghal6/starred{/owner}{/repo}
https://api.github.com/users/avisinghal6/subscriptions
User
https://api.github.com/users/avisinghal6
public
MEMBER
Unless @mariosasko thinks otherwise, I think it can go in `Dataset.select()` :)
Though some parameters like keep_in_memory, indices_cache_file_name or writer_batch_size wouldn't when selecting columns, so we would need to update the docstring as well
2023-01-27T19:48:49Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1407002154
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T3SYq
https://api.github.com/repos/huggingface/datasets/issues/comments/1407002154/reactions
2023-01-27T19:48:49Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1407002154
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
MEMBER
If someone wants to give it a shot, feel free to comment `#self-assign` and it will assign the issue to you.

Feel free to ping us here if you have questions or if we can help :)
2023-01-30T11:08:54Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1408426573
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T8uJN
https://api.github.com/repos/huggingface/datasets/issues/comments/1408426573/reactions
2023-01-30T11:08:54Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1408426573
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
COLLABORATOR
I would rather have this functionality as a separate method. IMO it's always better to be explicit than to have an API where a single method can do different/uncorrelated things (somewhat reminds me of Pandas, and there is probably a good reason why PyArrow is more rigid in this aspect).
2023-01-30T14:30:09Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1408723610
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5T92qa
https://api.github.com/repos/huggingface/datasets/issues/comments/1408723610/reactions
2023-01-30T14:30:09Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1408723610
https://avatars.githubusercontent.com/u/47462742?v=4
https://api.github.com/users/mariosasko/events{/privacy}
https://api.github.com/users/mariosasko/followers
https://api.github.com/users/mariosasko/following{/other_user}
https://api.github.com/users/mariosasko/gists{/gist_id}
https://github.com/mariosasko
mariosasko
MDQ6VXNlcjQ3NDYyNzQy
https://api.github.com/users/mariosasko/orgs
https://api.github.com/users/mariosasko/received_events
https://api.github.com/users/mariosasko/repos
https://api.github.com/users/mariosasko/starred{/owner}{/repo}
https://api.github.com/users/mariosasko/subscriptions
User
https://api.github.com/users/mariosasko
public
MEMBER
In the end I also think it would be nice to have it as a separate method, this way we can also have it for `IterableDataset` (which can't have `select` for indices)
2023-01-31T10:48:56Z
https://github.com/huggingface/datasets/issues/5468#issuecomment-1410140088
https://api.github.com/repos/huggingface/datasets/issues/5468
IC_kwDODunzps5UDQe4
https://api.github.com/repos/huggingface/datasets/issues/comments/1410140088/reactions
2023-01-31T10:48:56Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1410140088
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
### Feature request

In this blog post https://huggingface.co/blog/audio-datasets, I noticed the following code:

```python
COLUMNS_TO_KEEP = ["text", "audio"]
all_columns = gigaspeech["train"].column_names
columns_to_remove = set(all_columns) - set(COLUMNS_TO_KEEP)

gigaspeech = gigaspeech.remove_columns(columns_to_remove)
```

This kind of thing happens a lot when you don't need to keep all columns from the dataset. It would be more convenient (and less error prone) if you could just write:

```python
gigaspeech = gigaspeech.keep_columns(["text", "audio"])
```

Internally, `keep_columns` could still call `remove_columns`, but it expresses more clearly what the user's intent is.

### Motivation

Less code to write for the user of the dataset.

### Your contribution

-