Ensure ConcatenationTable.cast uses target_schema metadata
CONTRIBUTOR
Hi @lhoestq, Thanks for the detailed comment. I've tested the suggested approach and can confirm it works for the testcase outlined above! The PR is updated with the changes.
2022-07-19T07:19:47Z
https://github.com/huggingface/datasets/pull/4614#issuecomment-1188690999
https://api.github.com/repos/huggingface/datasets/issues/4614
IC_kwDODunzps5G2fw3
https://api.github.com/repos/huggingface/datasets/issues/comments/1188690999/reactions
2022-07-19T07:19:47Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1188690999
https://avatars.githubusercontent.com/u/8114067?v=4
https://api.github.com/users/dtuit/events{/privacy}
https://api.github.com/users/dtuit/followers
https://api.github.com/users/dtuit/following{/other_user}
https://api.github.com/users/dtuit/gists{/gist_id}
https://github.com/dtuit
dtuit
MDQ6VXNlcjgxMTQwNjc=
https://api.github.com/users/dtuit/orgs
https://api.github.com/users/dtuit/received_events
https://api.github.com/users/dtuit/repos
https://api.github.com/users/dtuit/starred{/owner}{/repo}
https://api.github.com/users/dtuit/subscriptions
User
https://api.github.com/users/dtuit
public
NONE
_The documentation is not available anymore as the PR was closed or merged._
2022-07-19T13:07:56Z
https://github.com/huggingface/datasets/pull/4614#issuecomment-1189031854
https://api.github.com/repos/huggingface/datasets/issues/4614
IC_kwDODunzps5G3y-u
https://api.github.com/repos/huggingface/datasets/issues/comments/1189031854/reactions
2022-07-19T13:48:45Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1189031854
https://avatars.githubusercontent.com/u/99929124?v=4
https://api.github.com/users/HuggingFaceDocBuilderDev/events{/privacy}
https://api.github.com/users/HuggingFaceDocBuilderDev/followers
https://api.github.com/users/HuggingFaceDocBuilderDev/following{/other_user}
https://api.github.com/users/HuggingFaceDocBuilderDev/gists{/gist_id}
https://github.com/HuggingFaceDocBuilderDev
HuggingFaceDocBuilderDev
U_kgDOBfTMJA
https://api.github.com/users/HuggingFaceDocBuilderDev/orgs
https://api.github.com/users/HuggingFaceDocBuilderDev/received_events
https://api.github.com/users/HuggingFaceDocBuilderDev/repos
https://api.github.com/users/HuggingFaceDocBuilderDev/starred{/owner}{/repo}
https://api.github.com/users/HuggingFaceDocBuilderDev/subscriptions
User
https://api.github.com/users/HuggingFaceDocBuilderDev
public
Currently, `ConcatenationTable.cast` does not use target_schema metadata when casting subtables. This causes an issue when using cast_column and the underlying table is a ConcatenationTable.

Code example of where issue arrises:
```
from datasets import Dataset, Image

column1 = [0, 1]
image_paths = ['/images/image1.jpg', '/images/image2.jpg']

ds = Dataset.from_dict({"column1": column1})
ds = ds.add_column("image", image_paths)
ds.cast_column("image", Image()) # Fails here
```
Output
```
...
TypeError: Couldn't cast array of type
string
to
{'bytes': Value(dtype='binary', id=None), 'path': Value(dtype='string', id=None)}
```
