-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Suppress deprecated warning when import monai #8067
Conversation
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
I aim to make the suppression of warnings as specific as possible to avoid impacting other parts of the code. For warnings that I can trace to specific imports, like |
It's a little worrying doing a blanket "ignore" on warnings from a library, but I know they're annoying to deal with in any other way. Even though some of the suppression is for optional packages, could we still use your filter function to ignore them? Eg. whether we import mlflow or not we can filter the warnings that it may create. |
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Looks like I can't use this custom filter handler due to this RecursionError.
|
This is possibly because you're calling |
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Hi @ericspod, I tried this but seems the warning message from optional_import will not shown in this init. One way we can do it is add this handler in the init file where will show the warning, but the issue is that we don't know the import order, so for each submodule init, we may need to add this handler. Do you think that make sense? |
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
I don't think it would be better to have this handler added in multiple places. Alternatively can we put the |
Actually I didn't understand why some of the warning message can be captured or shown by |
It's possible other libraries are using other functions in |
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Hi @ericspod, I discovered that the showwarning function has been modified, which is why some warnings are no longer displayed. I attempted to add a reset warning to the optional import, and set True in tensorrt and itk. Could you please help take another look at it. This may resolve your concern you mentioned before. |
Hi @KumoLiu , I think the reason that you can't disable some warnings is partially because they're sent by logging.warning module. This seems to be working to cancel out some of the warnings: import logging
# Create a custom filter
class DeprecatedTypesWarningFilter(logging.Filter):
def filter(self, record):
deprecated_aliases = ["np.bool8", "np.object0", "np.int0", "np.uint0", "np.void0", "np.str0", "np.bytes0"]
for alias in deprecated_aliases:
if alias in record.getMessage():
return False
return True
# Get the logger for warnings
logger = logging.getLogger("py.warnings")
# Create and add the filter to the logger
filter = DeprecatedTypesWarningFilter()
logger.addFilter(filter)
import monai
print(monai.__version__) |
Another example why the filter doesn't work is because the library forces it: |
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Thanks @mingxin-zheng,I added it in the latest commit. A good catch then I don't need to locate where shown the warning. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good to me. Thanks!
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
This strikes me as just being really bad behaviour. The point of filtering things is so that one can suppress warnings after they've seen them so they don't continue to annoy, people will abuse that to sweep warnings under the rug but this is the same thing in mirror. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little worried that we're having to do all this to shut up other warnings. Pytorch and others abuse the API of warnings I feel to force their messages to show, this is bad design but then we're doing the same thing here to counteract this. I hope this is all temporary until other dependencies update.
Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
/build |
- add packaging in setup.cfg - fix test_gdsdataset.py issue - add test_matshow3d to the skip list for min test - suppress deprecated warning when import monai (workaround for Project-MONAI#8060) ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.