'The above exception was the direct cause of the following exception - ValueError: 10 is not in range
I am trying to run the below code to load the dataset into a PyTorch dataset class with a custom collate function and map them but I am getting the error. The dataset consists of 123061 data samples so in the below code I have used only 10 samples. if i use total dataset then i am getting error of ValueError: 123061 is not in range. So exactly where i am doing wrong?
class Dataclass(Dataset):
def __init__(self,dataset):
self.dataset = dataset
def __len__(self):
return len(self.dataset)
def __getitem__(self, idx):
solute = self.dataset.loc[idx]['Drug1_SMILES']
mol = Chem.MolFromSmiles(solute)
mol = Chem.AddHs(mol)
solute = Chem.MolToSmiles(mol)
solute_graph = get_graph_from_smile(solute)
solvent = self.dataset.loc[idx]['Drug2_SMILES']
mol = Chem.MolFromSmiles(solvent)
mol = Chem.AddHs(mol)
solvent = Chem.MolToSmiles(mol)
solvent_graph = get_graph_from_smile(solvent)
delta_g = self.dataset.loc[idx]['label']
return [solute_graph, solvent_graph]
tg = Dataclass(train_df[:10])
solute_graphs, solvent_graphs, labels = map(list, zip(*tg))
Error
ValueError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance)
384 try:
--> 385 return self._range.index(new_key)
386 except ValueError as err:
ValueError: 10 is not in range
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
6 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance)
385 return self._range.index(new_key)
386 except ValueError as err:
--> 387 raise KeyError(key) from err
388 raise KeyError(key)
389 return super().get_loc(key, method=method, tolerance=tolerance)
KeyError: 10
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
