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

Fix import_optional_module function to return NoneType #597

Merged
merged 7 commits into from
May 3, 2024

Conversation

amrit110
Copy link
Member

PR Type ([Feature | Fix | Documentation | Test])

Fix

Short Description

The import_optional_module currently returns None when a module cannot be imported and the error parameter is set to ignore. When we use isinstance this doesn't work, so introducing an option to return NoneType.

Tests Added

...

@amrit110 amrit110 requested a review from fcogidi April 29, 2024 18:50
@amrit110 amrit110 self-assigned this Apr 29, 2024
@amrit110 amrit110 added the bug Something isn't working label Apr 29, 2024
Copy link
Collaborator

@fcogidi fcogidi left a comment

Choose a reason for hiding this comment

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

Instead of returning sometimes returning NoneType, would it be better to check if it's None before isinstance?

@amrit110
Copy link
Member Author

Instead of returning sometimes returning NoneType, would it be better to check if it's None before isinstance?

yeah that sounds better. i wonder if the metric_dict is the only place where that needs to be done.

@fcogidi
Copy link
Collaborator

fcogidi commented Apr 30, 2024

Instead of returning sometimes returning NoneType, would it be better to check if it's None before isinstance?

yeah that sounds better. i wonder if the metric_dict is the only place where that needs to be done.

There are a few cases of that in the models package. For example, in cyclops/models/torch_utils, there's

isinstance(X, (torch.Tensor, PackedSequence))

torch and PackedSequence are both optionally imported.

@codecov-commenter
Copy link

codecov-commenter commented Apr 30, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 75.14%. Comparing base (efb402d) to head (590b15f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #597      +/-   ##
==========================================
- Coverage   75.15%   75.14%   -0.01%     
==========================================
  Files         128      128              
  Lines       11394    11399       +5     
==========================================
+ Hits         8563     8566       +3     
- Misses       2831     2833       +2     
Files Coverage Δ
cyclops/utils/optional.py 100.00% <100.00%> (ø)
...clops/evaluate/metrics/experimental/metric_dict.py 92.13% <50.00%> (-0.48%) ⬇️
cyclops/models/torch_utils.py 75.60% <50.00%> (-0.65%) ⬇️

Impacted file tree graph

@amrit110 amrit110 merged commit b8cf8b3 into main May 3, 2024
8 checks passed
@amrit110 amrit110 deleted the fix_import_optional_module branch May 3, 2024 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants