deeplake
deeplake copied to clipboard
[Improvement] Make index errors while accessing Dataset and Tensor easier to understand.
🚨🚨 Feature Request
- [x] A new implementation (Improvement, Extension)
Is your feature request related to a problem?
Currently, if a user tries to access an index that is larger than the dataset length or tensor length, an internal error is thrown which is not easy to understand.
Description of the possible solution
We can catch the error and throw a more descriptive error that's easier to understand.
Example of when the error is thrown:-
ds = hub.dataset("path/to/dataset")
ds.create_tensor("xyz")
for i in range(10):
ds.xyz.append(i)
# now length of xyz and ds is 10
ds[20] # throws error
ds.xyz[89] # throws error
Hello! Do we wish to output the details of the tensor that did not have the index specified? I am guessing that would be much more helpful in debugging.
Hey @neel2299! We can certainly display the tensor name in case the error we're catching is happening while indexing into a tensor.
Great!!
I tried it and got an error raised from validate method(s) in index.py as shown above. The error made me think that even dataset was using tensors to validate(may be changing tensor to dataset in that error message for datasets will help).
we can use if-else statements for this to show if the length is greater than 10 then show up the error
can you assign this to me i want to work in this issue
Is this issue available? Can I work on this issue?
@AbhinavTuli Do I have to raise an exception in the __getitem__
method if self.index
is greater than the length of the list then print the required message else return the item.
Like this :-
if isinstance(item, str):
if(Index > self.__len__):
raise IndexError("Index out of range")
else:
fullpath = posixpath.join(self.group_index, item)
tensor = self._get_tensor_from_root(fullpath)
Hello, I would like to work on this issue. Could you please assign it to me?