diff --git a/python/ray/data/dataset.py b/python/ray/data/dataset.py index 835b046ae772..d5ea1ea2d63d 100644 --- a/python/ray/data/dataset.py +++ b/python/ray/data/dataset.py @@ -4206,6 +4206,13 @@ def __len__(self) -> int: "This may be an expensive operation." ) + def __iter__(self): + raise TypeError( + "`Dataset` objects aren't iterable. To iterate records, call " + "`ds.iter_rows()` or `ds.iter_batches()`. For more information, read " + "https://docs.ray.io/en/latest/data/consuming-datasets.html." + ) + def _block_num_rows(self) -> List[int]: get_num_rows = cached_remote_fn(_get_num_rows) return ray.get([get_num_rows.remote(b) for b in self.get_internal_block_refs()])