The Wayback Machine - http://web.archive.org/web/20220709025148/https://github.com/activeloopai/Hub/issues/1560
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
AbhinavTuli opened this issue Mar 22, 2022 · 8 comments
Open
1 task done
Labels
enhancement good first issue

Comments

@AbhinavTuli
Copy link
Collaborator

@AbhinavTuli AbhinavTuli commented Mar 22, 2022

🚨🚨 Feature Request

  • 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 AbhinavTuli added the enhancement label Mar 22, 2022
@AbhinavTuli AbhinavTuli added this to Easy tasks in New Contributor projects Mar 22, 2022
@AbhinavTuli AbhinavTuli added the good first issue label Mar 22, 2022
@neel2299
Copy link
Contributor

@neel2299 neel2299 commented Mar 22, 2022

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.

@AbhinavTuli
Copy link
Collaborator Author

@AbhinavTuli AbhinavTuli commented Mar 23, 2022

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

@neel2299
Copy link
Contributor

@neel2299 neel2299 commented Mar 23, 2022

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

@olivia632
Copy link

@olivia632 olivia632 commented Mar 25, 2022

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

@olivia632
Copy link

@olivia632 olivia632 commented Mar 28, 2022

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

@aadityasinha-dotcom
Copy link

@aadityasinha-dotcom aadityasinha-dotcom commented Apr 13, 2022

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

@aadityasinha-dotcom
Copy link

@aadityasinha-dotcom aadityasinha-dotcom commented Apr 13, 2022

@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
Copy link

@aadityasinha-dotcom aadityasinha-dotcom commented Apr 13, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue
Projects
Development

Successfully merging a pull request may close this issue.

4 participants