warning control "once"
See original GitHub issueWhile ignoring warnings works well, I can’t make the warning appear only once (as they actually should do as default behaviour)
I have a (potentially corrupt) fits file that outputs tons of warnings like:
WARNING: The following header keyword is invalid or follows an unrecognized non-standard convention: ??????????????????????????????????????????????????????????????????????????????? [astropy.io.fits.card]
, even if I explicitly set the warning filter to “once”, they keep coming…
Is this wanted behaviour? If so, why, and can we not change it, or at least allow control over it?
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
warnings — Warning control — Python 3.11.1 documentation
There are two stages in warning control: first, each time a warning is issued, a determination is made whether a message should be...
Read more >Python Warning control - Stack Overflow
You can e.g. call warnings.filterwarnings("once") somewhere before the warnings are raised. However, there is no way to show the same warning ...
Read more >Warning Control Statements :: Error Handling (Programming)
Use query to determine the current state of all warnings. It reports that you have set all warnings to off with the exception...
Read more >3.20 warnings -- Warning control
There are two stages in warning control: first, each time a warning is issued, a determination is made whether a message should be...
Read more >Warning Options (Using the GNU Compiler Collection (GCC))
The warning message for each controllable warning includes the option that controls the warning. That option can then be used with -Werror= and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure thing. The fits is available in our public archive
then just:
and you should see all the warnings.
Then using the linked example about warning control, suppressing it with ignore works, but “once” does the same as “default”…
the python docs state:
as far as I can tell all those warnings come from the exact same module+line number so IMO only one warning should be printed with default settings…?
Tested on Win10 with astropy4.0, python 3.7.2
Finally had a more detailed look, and that’s Python’s warnings behavior:
There is some buffering when calling
warnings.warn
in a loop, but this is not the case if you callwarnings.catch_warnings
in the loop iterations. So this is not an Astropy issue, closing this.