Skip to content

fix: tensor equals type raises exception #1739

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

Merged
merged 4 commits into from
Jul 31, 2023
Merged

Conversation

JohannesMessner
Copy link
Member

Currently the following raises and exception:

from docarray.typing import TorchTensor

TorchTensor == type
Traceback (most recent call last):
  File "/home/johannes/.config/JetBrains/PyCharmCE2023.2/scratches/scratch_183.py", line 3, in <module>
    TorchTensor == type
  File "/home/johannes/Documents/jina/docarrayv2/docarray/typing/tensor/abstract_tensor.py", line 101, in __eq__
    if cls._equals_special_case(other):
  File "/home/johannes/Documents/jina/docarrayv2/docarray/typing/tensor/abstract_tensor.py", line 62, in _equals_special_case
    is_tensor = is_type and AbstractTensor in other.mro()
TypeError: descriptor 'mro' of 'type' object needs an argument

This fixes that

Signed-off-by: Johannes Messner <[email protected]>
@codecov
Copy link

codecov bot commented Jul 31, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (7be038c) 84.45% compared to head (55ba014) 84.46%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1739      +/-   ##
==========================================
+ Coverage   84.45%   84.46%   +0.01%     
==========================================
  Files         134      134              
  Lines        8840     8840              
==========================================
+ Hits         7466     7467       +1     
+ Misses       1374     1373       -1     
Flag Coverage Δ
docarray 84.46% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
docarray/typing/tensor/abstract_tensor.py 91.41% <100.00%> (ø)

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

)
return any(issubclass(candidate, cls) for candidate in type(instance).mro())
return any(
issubclass(candidate, cls) for candidate in type(instance).__mro__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

us safe version of is_subclass please

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure if we want that here. This implements the "normal" isinstance() call, so i don't think it should work with non-class inputs. For example, the following also raises an exception:

isinstance(3, List[int])
TypeError: Subscripted generics cannot be used with class and instance checks

So I would not catch such things here

Signed-off-by: Johannes Messner <[email protected]>
@github-actions
Copy link

📝 Docs are deployed on https://ft-fix-tensor-equals-type--jina-docs.netlify.app 🎉

@JoanFM JoanFM merged commit d2c82d4 into main Jul 31, 2023
@JoanFM JoanFM deleted the fix-tensor-equals-type branch July 31, 2023 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants