Add new column to dataset
CONTRIBUTOR
I think it's an issue with the code.

Specifically:
```python
dataset = dataset['train'].add_column("/workspace/data", new_column)
```

Now `dataset` is the train set with a new column. 
To fix this, you can do:

```python
dataset['train'] = dataset['train'].add_column("/workspace/data", new_column)
```
2023-09-18T14:37:13Z
https://github.com/huggingface/datasets/issues/6246#issuecomment-1723574775
https://api.github.com/repos/huggingface/datasets/issues/6246
IC_kwDODunzps5mu6n3
https://api.github.com/repos/huggingface/datasets/issues/comments/1723574775/reactions
2023-09-18T14:37:13Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1723574775
https://avatars.githubusercontent.com/u/8976546?v=4
https://api.github.com/users/Dref360/events{/privacy}
https://api.github.com/users/Dref360/followers
https://api.github.com/users/Dref360/following{/other_user}
https://api.github.com/users/Dref360/gists{/gist_id}
https://github.com/Dref360
Dref360
MDQ6VXNlcjg5NzY1NDY=
https://api.github.com/users/Dref360/orgs
https://api.github.com/users/Dref360/received_events
https://api.github.com/users/Dref360/repos
https://api.github.com/users/Dref360/starred{/owner}{/repo}
https://api.github.com/users/Dref360/subscriptions
User
https://api.github.com/users/Dref360
public
NONE
> I think it's an issue with the code.
> 
> Specifically:
> 
> ```python
> dataset = dataset['train'].add_column("/workspace/data", new_column)
> ```
> 
> Now `dataset` is the train set with a new column. To fix this, you can do:
> 
> ```python
> dataset['train'] = dataset['train'].add_column("/workspace/data", new_column)
> ```

Thanks for your response, but i can not access mask images, please let me know why the problem still persists. Here is the notebook for reference: https://colab.research.google.com/drive/10lZ_zLtU4itYVmIVTvIEVbjfOtCZaAZy?usp=sharing 
2023-09-18T14:52:04Z
https://github.com/huggingface/datasets/issues/6246#issuecomment-1723607713
https://api.github.com/repos/huggingface/datasets/issues/6246
IC_kwDODunzps5mvCqh
https://api.github.com/repos/huggingface/datasets/issues/comments/1723607713/reactions
2023-09-18T14:52:04Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1723607713
https://avatars.githubusercontent.com/u/20493493?v=4
https://api.github.com/users/andysingal/events{/privacy}
https://api.github.com/users/andysingal/followers
https://api.github.com/users/andysingal/following{/other_user}
https://api.github.com/users/andysingal/gists{/gist_id}
https://github.com/andysingal
andysingal
MDQ6VXNlcjIwNDkzNDkz
https://api.github.com/users/andysingal/orgs
https://api.github.com/users/andysingal/received_events
https://api.github.com/users/andysingal/repos
https://api.github.com/users/andysingal/starred{/owner}{/repo}
https://api.github.com/users/andysingal/subscriptions
User
https://api.github.com/users/andysingal
public
CONTRIBUTOR
I think there is a slight misunderstanding.
```python
new_column = ["mask"] * len(dataset["train"])
dataset['train'] = dataset['train'].add_column("/workspace/data", new_column)
```

adds a column with the string `mask` to your dataset.
If you're trying to load the images `"mask_{idx}.png"` in your dataset, you could try:

```
from datasets import Image

dataset['train'] = dataset['train'].map(lambda u, idx: {'mask': f"/workspace/data/mask_{idx}.png", with_indices=True).cast_column("mask", Image())
```

What this does is that it adds a column to your dataset name `mask` with the path to the mask, then it cast the column as an `Image` feature.

This [link](https://huggingface.co/docs/datasets/v2.5.1/en/image_load) explains how to load images.

Hope this helps!
2023-09-18T15:52:14Z
https://github.com/huggingface/datasets/issues/6246#issuecomment-1723787488
https://api.github.com/repos/huggingface/datasets/issues/6246
IC_kwDODunzps5mvujg
https://api.github.com/repos/huggingface/datasets/issues/comments/1723787488/reactions
2023-09-18T15:52:14Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1723787488
https://avatars.githubusercontent.com/u/8976546?v=4
https://api.github.com/users/Dref360/events{/privacy}
https://api.github.com/users/Dref360/followers
https://api.github.com/users/Dref360/following{/other_user}
https://api.github.com/users/Dref360/gists{/gist_id}
https://github.com/Dref360
Dref360
MDQ6VXNlcjg5NzY1NDY=
https://api.github.com/users/Dref360/orgs
https://api.github.com/users/Dref360/received_events
https://api.github.com/users/Dref360/repos
https://api.github.com/users/Dref360/starred{/owner}{/repo}
https://api.github.com/users/Dref360/subscriptions
User
https://api.github.com/users/Dref360
public
NONE
> I think there is a slight misunderstanding.
> 
> ```python
> new_column = ["mask"] * len(dataset["train"])
> dataset['train'] = dataset['train'].add_column("/workspace/data", new_column)
> ```
> 
> adds a column with the string `mask` to your dataset. If you're trying to load the images `"mask_{idx}.png"` in your dataset, you could try:
> 
> ```
> from datasets import Image
> 
> dataset['train'] = dataset['train'].map(lambda u, idx: {'mask': f"/workspace/data/mask_{idx}.png", with_indices=True).cast_column("mask", Image())
> ```
> 
> What this does is that it adds a column to your dataset name `mask` with the path to the mask, then it cast the column as an `Image` feature.
> 
> This [link](https://huggingface.co/docs/datasets/v2.5.1/en/image_load) explains how to load images.
> 
> Hope this helps!

Thank you very much, this is really helpful...
i made some changes for it to work:
```
dataset['train'] = dataset['train'].map(lambda u, idx: {'mask': f"/content/data/mask_{idx}.png"}, with_indices=True).cast_column("mask", Image())
```
Thanks Again @Dref360 
2023-09-18T16:20:09Z
https://github.com/huggingface/datasets/issues/6246#issuecomment-1723839418
https://api.github.com/repos/huggingface/datasets/issues/6246
IC_kwDODunzps5mv7O6
https://api.github.com/repos/huggingface/datasets/issues/comments/1723839418/reactions
2023-09-18T16:20:09Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1723839418
https://avatars.githubusercontent.com/u/20493493?v=4
https://api.github.com/users/andysingal/events{/privacy}
https://api.github.com/users/andysingal/followers
https://api.github.com/users/andysingal/following{/other_user}
https://api.github.com/users/andysingal/gists{/gist_id}
https://github.com/andysingal
andysingal
MDQ6VXNlcjIwNDkzNDkz
https://api.github.com/users/andysingal/orgs
https://api.github.com/users/andysingal/received_events
https://api.github.com/users/andysingal/repos
https://api.github.com/users/andysingal/starred{/owner}{/repo}
https://api.github.com/users/andysingal/subscriptions
User
https://api.github.com/users/andysingal
public
### Describe the bug

```
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-9-bd197b36b6a0>](https://localhost:8080/#) in <cell line: 1>()
----> 1 dataset['train']['/workspace/data']

3 frames
[/usr/local/lib/python3.10/dist-packages/datasets/formatting/formatting.py](https://localhost:8080/#) in _check_valid_column_key(key, columns)
    518 def _check_valid_column_key(key: str, columns: List[str]) -> None:
    519     if key not in columns:
--> 520         raise KeyError(f"Column {key} not in the dataset. Current columns in the dataset: {columns}")
    521 
    522 

KeyError: "Column train not in the dataset. Current columns in the dataset: ['image', '/workspace/data']"
```

### Steps to reproduce the bug

please find the notebook for reference: https://colab.research.google.com/drive/10lZ_zLtU4itYVmIVTvIEVbjfOtCZaAZy?usp=sharing

### Expected behavior

add column to the dataset

### Environment info

colab pro