huggingface / huggingface/datasets

`SplitDict.copy()` crashes when `dataset_name` is not set

Open Beginner friendly
#8,617 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
22k
Forks
3.4k
Avg merge
5d 7h
Merged PRs (30d)
17

Description

## Description

`SplitDict.copy()` (and `SplitDict.from_split_dict`) crashes with
`AttributeError: 'SplitInfo' object has no attribute 'get'` whenever the split
dict contains `SplitInfo` objects and `dataset_name` is `None`.

## Reproduction

```python
from datasets import SplitDict, SplitInfo

split_dict = SplitDict({"train": SplitInfo(name="train", num_bytes=1337, num_examples=42)})
split_dict.copy()
```

Traceback:

```
File ".../datasets/splits.py", line 574, in from_split_dict
dataset_name = split_infos[0].get("dataset_name") if split_infos else None
AttributeError: 'SplitInfo' object has no attribute 'get'
```

## Expected behavior

`copy()` should work for `SplitDict` instances holding `SplitInfo` objects,
which is the normal state after construction (e.g. from a dataset's info).
The method should read `dataset_name` from `SplitInfo.dataset_name` when the
entries are `SplitInfo` objects, and only fall back to `.get()` for raw
dictionaries.

## Environment

- `datasets` version: 5.0.2.dev0 (main, d336dcb)
- Python: 3.11

Contributor guide

Open the contributing guide

Research direction

Start in datasets/splits.py around SplitDict.from_split_dict, referenced at line 574, and trace how SplitInfo entries and raw dictionaries are handled. Run the reproduction from the issue, then verify that SplitDict.copy() and SplitDict.from_split_dict work with SplitInfo objects when dataset_name is unset and preserve the expected dataset name when it is available.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.