deeplake icon indicating copy to clipboard operation
deeplake copied to clipboard

[Improvement] Make index errors while accessing Dataset and Tensor easier to understand.

Open AbhinavTuli opened this issue 2 years ago • 9 comments

🚨🚨 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

AbhinavTuli avatar Mar 22 '22 14:03 AbhinavTuli

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.

neel2299 avatar Mar 22 '22 21:03 neel2299

Hey @neel2299! We can certainly display the tensor name in case the error we're catching is happening while indexing into a tensor.

AbhinavTuli avatar Mar 23 '22 16:03 AbhinavTuli

Great!! image 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).

neel2299 avatar Mar 23 '22 19:03 neel2299

we can use if-else statements for this to show if the length is greater than 10 then show up the error

olivia632 avatar Mar 25 '22 16:03 olivia632

can you assign this to me i want to work in this issue

olivia632 avatar Mar 28 '22 18:03 olivia632

Is this issue available? Can I work on this issue?

aadityasinha-dotcom avatar Apr 13 '22 01:04 aadityasinha-dotcom

@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.

aadityasinha-dotcom avatar Apr 13 '22 11:04 aadityasinha-dotcom

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)

aadityasinha-dotcom avatar Apr 13 '22 12:04 aadityasinha-dotcom

Hello, I would like to work on this issue. Could you please assign it to me?

Moksh45 avatar Jan 04 '23 16:01 Moksh45