Skip to content

Commit

Permalink
Add IterableDataset __repr__ (#6480)
Browse files Browse the repository at this point in the history
add iterabledataset repr
  • Loading branch information
lhoestq authored Dec 8, 2023
1 parent dd9044c commit 79e94fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/datasets/dataset_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,11 @@ def push_to_hub(


class IterableDatasetDict(dict):
def __repr__(self):
repr = "\n".join([f"{k}: {v}" for k, v in self.items()])
repr = re.sub(r"^", " " * 4, repr, 0, re.M)
return f"IterableDatasetDict({{\n{repr}\n}})"

def with_format(
self,
type: Optional[str] = None,
Expand Down
3 changes: 3 additions & 0 deletions src/datasets/iterable_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,9 @@ def __init__(
self._token_per_repo_id: Dict[str, Union[str, bool, None]] = token_per_repo_id or {}
_maybe_add_torch_iterable_dataset_parent_class(self.__class__)

def __repr__(self):
return f"IterableDataset({{\n features: {list(self._info.features.keys()) if self._info.features is not None else 'Unknown'},\n n_shards: {self.n_shards}\n}})"

def __getstate__(self):
return self.__dict__

Expand Down

0 comments on commit 79e94fc

Please sign in to comment.