diff --git a/python/ray/data/dataset.py b/python/ray/data/dataset.py index 96f031cf2c61..8788bd5d2deb 100644 --- a/python/ray/data/dataset.py +++ b/python/ray/data/dataset.py @@ -4203,6 +4203,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()])