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

after importing dtale, all python warnings are filtered out #668

Closed
hottwaj opened this issue May 18, 2022 · 7 comments
Closed

after importing dtale, all python warnings are filtered out #668

hottwaj opened this issue May 18, 2022 · 7 comments

Comments

@hottwaj
Copy link

hottwaj commented May 18, 2022

This library should not automatically filter out all warnings!

This line of code needs to be removed:
https://github.com/man-group/dtale/blob/master/dtale/__init__.py#L5

If specific warnings need to be filtered out, a more precise filter should be used?

Thanks!

@aschonfeld
Copy link
Collaborator

@hottwaj so I was thinking up my solution being that I'd add warnings.resetwarnings() to the bottom of dtale/__init__.py because all I really care about is filtering out some warnings that occur on import of D-Tale.

Let me know the specific warning that you weren't seeing but wanted to so I can test it to make sure it won't affect that.

@hottwaj
Copy link
Author

hottwaj commented May 24, 2022

Thanks and makes sense, though it might be safer to use the catchwarnings context manager as that will restore warnings to previous state when context exits:
https://docs.python.org/3/library/warnings.html#warnings.catch_warnings

As well as warnings from internal libraries developed at my employer (I realised something was up when those stopped appearing), I do find it useful to see the usual array of pandas warnings for misuse/deprecated usage. I think suppressing all warnings is a bit too big of a hammer because then you just don't know what you are missing :)

Anyway understand your need. Maybe an alternative suggestion would be to use a warnings filter + context manager with a regex for exactly the warnings you want to suppress? That way you'll still be able to spot any new warnings that might contain useful info.

Thanks for the great library by the way, awesome work :)

@aschonfeld
Copy link
Collaborator

So the warning I'm trying to hide is for

The dash_html_components package is deprecated. Please replace
`import dash_html_components as html` with `from dash import html`

but because it has newlines in it the regex filter isn't working.

I've tried doing:

with warnings.catch_warnings(record=True) as w:
    warnings.filterwarnings("ignore", """"The dash_html_components package is deprecated. Please replace
`import dash_html_components as html` with `from dash import html`""")

but that still seems to take out too much.

Thanks for your help

@hottwaj
Copy link
Author

hottwaj commented May 26, 2022

I tested and maybe the issue was that record=True stops output of all warnings to stdout?

The docs are a bit unclear but I think that is what it is saying here: https://docs.python.org/3/library/warnings.html#warnings.catch_warnings

The snippet below I think has the behaviour needed:

with warnings.catch_warnings():
    warnings.filterwarnings("ignore", '\nThe dash_html_components package is deprecated. Please replace\n`import dash_html_components as html` with `from dash import html`')
    
    # this warning will be filtered
    warnings.warn('\nThe dash_html_components package is deprecated. Please replace\n`import dash_html_components as html` with `from dash import html`')
    
    warnings.warn('this will still be visible')
    
    # this also does not produce a warning
    import dash_html_components as html
    
warnings.warn('this and next warning should be visible!')
warnings.warn('\nThe dash_html_components package is deprecated. Please replace\n`import dash_html_components as html` with `from dash import html`')

Slightly fragile I suppose as dash might change their deprecation message :)

I guess you are using import dash_html_components as html to preserve compatibility with earlier versions of dash?

Thanks!

@aschonfeld
Copy link
Collaborator

that worked perfect! Thank you. I'll have this added and a new release soon. Will keep you posted

@aschonfeld
Copy link
Collaborator

@hottwaj just released v2.5.1 with this fix. Also, if you haven't already, please toss your ⭐ on the repo. Thanks 🙏

@hottwaj
Copy link
Author

hottwaj commented May 29, 2022

Awesome thanks v much, and ⭐️done! Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants