#5138·deepchem

DiskDataset.itersamples() returns the wrong rows if samples are collected before use

Author: RudraDudhat2509Created Sep 21, 2026Updated Sep 21, 2026

DiskDataset.itersamples() yields a lazy map(sanitize, ...) and sanitize reads the loop variable i, so the row is looked up when the map is consumed, not when it is yielded. Using each sample right away (for x, y, w, id in ds.itersamples()) works, but collecting them first gives the wrong rows:

python
import numpy as np
import deepchem as dc

X = np.arange(12).reshape(6, 2)
ds = dc.data.DiskDataset.from_numpy(X)
samples = list(ds.itersamples())
print([tuple(s)[0].tolist() for s in samples])
[[10, 11], [10, 11], [10, 11], [10, 11], [10, 11], [10, 11]]

Expected [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]]. NumpyDataset and ImageDataset yield plain tuples so they don't have this, and the docstring says it yields tuples of four arrays.

Will open a PR that yields a tuple.