avoid failure of plot_feature_outlier_image#774
Conversation
I call the function this way:
plot_feature_outlier_image(preds, # output of an prediction
ds, # my set of images
X_recon=recon, # reconstructed set of images
max_instances=5, # max nb of instances to display
n_channels=3, # number of channels of the images
figsize=(20,10),
outliers_only=True) # only show outlier predictions. this function fails when no outlier is detected and parameter set to True
In case there is no outlieres detected and the parameter outliers_only is set to True, then the function fails, because it calls plt.subplots(nrows=0, ....). 0 rows throws the error.
mauicv
left a comment
There was a problem hiding this comment.
Hey @signupatgmx,
Thank you very much for opening this PR! I think the change makes sense, one minor ask would be to add a warning if the outliers_only and n_instances == 0 condition is met. If the function returns without warning the user then it's not entirely clear what happened. Lmk if you are happy to do this otherwise I'm happy to pick it up!
Thanks regardless
|
Hallo @mauicv, as I'm not customized with your coding standards, I'd suggest you add a suitable warning output. I'm glad to have found your great library. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #774 +/- ##
==========================================
- Coverage 81.03% 80.98% -0.05%
==========================================
Files 146 146
Lines 9721 9720 -1
==========================================
- Hits 7877 7872 -5
- Misses 1844 1848 +4
|
alibi_detect/utils/visualize.py
Outdated
| instance_ids = instance_ids[:n_instances] | ||
|
|
||
| if outliers_only and n_instances == 0: | ||
| warnings.warn('No outliers found!', UserWarning, stacklevel=3) |
There was a problem hiding this comment.
@mauicv is the warning swallowed without stacklevel=3?
There was a problem hiding this comment.
Good point, I've removed it!
I call the function this way:
In case there is no outlieres detected and the parameter outliers_only is set to True, then the function fails, because it calls plt.subplots(nrows=0, ....). 0 rows throws the error.