I'm struggling to suppress a specific warning related to fasttext.
The warning is Warning : 'load_model' does not return WordVectorModel or SupervisedModel any more, but a 'FastText' object which is very similar.
And here is the offending block of code:
with warnings.catch_warnings():
warnings.filterwarnings('ignore')
return fasttext.load_model(str(model_path)) # this line
I've attempted several ways to suppress the warning, mostly from this thread without success.
I'm using Python 3.8, fasttext v0.9.2.
For fasttext v0.9.2 this can be solved by adding the monkey patch below to your code (as per this GitHub issue).
import fasttext
fasttext.FastText.eprint = lambda x: None
As mentioned in that same GitHub issue, the warning message was removed in commit 9ef22d9 in May 2020, which will likely be in the next official release (fasttext v0.9.3), whenever that is.
I'm using the DecisionTreeClassifier from scikit-learn (https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html) and getting the following warning:
FutureWarning: The sklearn.tree.tree module is deprecated in version
0.22 and will be removed in version 0.24. The corresponding classes / functions should instead be imported from sklearn.tree. Anything that
cannot be imported from sklearn.tree is now part of the private API.
I'm a bit confused about why I'm receiving this warning as I'm not using sklearn.tree.tree anywhere. I am using sklearn.tree as the warning suggests but still receive this warning. In fact I'm using code of the form:
from sklearn.tree import DecisionTreeClassifier
tree = DecisionTreeClassifier(<params>)
tree.fit(training_data, training_labels)
As per the example code given in https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html but still get this warning.
I've searched the scikit documentation and online and can't find how to update my code inline with the suggestion in the warning. Does anyone know what I need to change to fix the warning?
You can ignore the deprecation warning, it's only a warning (I wouldn't worry if your code isn't referencing that subpackage, there's probably an import somewhere under the hood inside sklearn.)
You could suppress all FutureWarnings, but then you might miss another more important one, on sklearn or another package. So I'd just ignore it for now. But if you want to:
import warnings
warnings.simplefilter('ignore', FutureWarning)
from sklearn.tree import ...
# ... Then turn warnings back on for other packages
warnings.filterwarnings('module') # or 'once', or 'always'
See the doc, or How to suppress Future warning from import?, although obviously you replace import pandas with your own import statement.
link of the same kind of problem
It's just a warning, for now -- until you upgrade scikit/sklearn to version 0.24, You need to update your scikit/sklearn version.
There are many questions related to the question title above and all basically tell you to do:
import warnings
warnings.filterwarnings('ignore')
and to make sure this is placed before the first import.
However, even after doing this I get many warnings from seaborn and sklearn. I get UserWarning, DataConversionWarning and RuntimeWarning which, according to documentation, all inherit from Warning and should be covered by the above code.
Is there another way to hide those warnings?
(I cannot really solve most of them anyway)
EDIT
Example 1:
C:\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py:645: DataConversionWarning: Data with input dtype int32, int64 were all converted to float64 by StandardScaler.
return self.partial_fit(X, y)
Example 2
C:\Anaconda3\lib\site-packages\seaborn\distributions.py:340: UserWarning: Attempted to set non-positive bottom ylim on a log-scaled axis.
Invalid limit will be ignored.
ax.set_ylim(0, auto=None)
Example2
It's a bit hard to track down; seaborn imports statsmodels. And in statsmodels/tools/sm_exceptions.py you find this line
warnings.simplefilter('always', category=UserWarning)
in which reverses any previous setting for user warnings.
A solution for now would be to remove that line or to set the warning state after the import of seaborn (and hence statsmodels). In a future version of statsmodels this will be fixed by PR 4712, so using the development version of statsmodels would also be an option.
Example1
I did not find a way to reproduce the first example from sklearn; so that may or may not have a different reason.
from slimit import minify
if __name__ == "__main__":
print("start")
# Normally, I pass real JavaScript. For this issue, an empty string reproduces problem.
minify("", mangle=True)
print("exit")
This triggers the following console output.
start
WARNING: Couldn't write lextab module <module 'slimit.lextab' from '/Users/kurtostfeld/samba/wrapad/venv/lib/python2.7/site-packages/slimit/lextab.pyc'>. Won't overwrite existing lextab module
WARNING: yacc table file version is out of date
WARNING: Token 'IMPORT' defined, but not used
WARNING: Token 'BLOCK_COMMENT' defined, but not used
WARNING: Token 'ENUM' defined, but not used
WARNING: Token 'EXTENDS' defined, but not used
WARNING: Token 'LINE_COMMENT' defined, but not used
WARNING: Token 'LINE_TERMINATOR' defined, but not used
WARNING: Token 'CONST' defined, but not used
WARNING: Token 'EXPORT' defined, but not used
WARNING: Token 'CLASS' defined, but not used
WARNING: Token 'SUPER' defined, but not used
WARNING: There are 10 unused tokens
WARNING: Couldn't create <module 'slimit.yacctab' from '/Users/kurtostfeld/samba/wrapad/venv/lib/python2.7/site-packages/slimit/yacctab.pyc'>. Won't overwrite existing tabmodule
exit
These warnings are flooding my application console output. How can I use minify without generating warnings?
I'm using Python 2.7.12, and what is currently the latest library versions: slimit 0.8.1, ply 3.10.
According to this issue on Github, slimit depends of the ply package. After few tries, it seems that theses warnings appear since version 3.8 of ply. . You could update ply to 3.6 which is the last version that doesn't bring these messages :
pip uninstall ply -y && pip install ply==3.6
It solved my problem.
UPDATE
Install a sooner version of ply was really a bad work around since some of my tests were failing. Original slimit version seems not maintained well so I suggest to update to a newer version, metatoaster did a good job to improve it and fixed that problem of warning message. The solution for me was to uninstall slimit and then install it's version:
pip install git+https://github.com/metatoaster/slimit.git#egg=slimit
FINAL UPDATE In fact, slimit seems not maintened anymore and its successor is called calmjs, there is few differences but it is really more stable and don't shows these annoying warning message. See: https://github.com/calmjs/calmjs.parse
Switching versions did not change anything for me, I found another workaround: simply delete (or move, if you want to be cautious) the mentioned files (yourpython/site-packages/slimit/yacctab.py and yourpython/site-packages/slimit/lextab.py).
I believe the module will re-create these files and stop bothering you with warning messages.
Slimit uses ply under the hood, which uses logging from stdlib. AFAICS slimit does not allow you to pass the logging parameters that ply's lex and yacc expect.
While you therefor can't (directly) access ply's logging, you should be able to suppress those messages my raising the global logging level:
import logging
...
logging.disable(logging.CRITICAL)
minify("", mangle=True)
logging.disable(logging.NOTSET)
You can use this parser, too: https://github.com/PiotrDabkowski/pyjsparser
It works and is easy to use. It does not handle comments though.
(Neither does calmjs seems to handle comments fully: Its parse function has a parameter to indicate that you want the comments, but as of now, some comments seem to get lost.)
Here was the solution that I went with. I made a custom variant of two slimit functions that pass an extra errorlog=ply.yacc.NullLogger() call to the ply.yacc.yacc function.
class SlimitNoLoggingParser(Parser):
"""
This is a simple customized variant to slimit.parser.Parser.
The only difference is that this passes a errorlog=ply.yacc.NullLogger() to ply.yacc.yacc to suppress unwanted
stderr logging output.
"""
def __init__(self, lex_optimize=True, lextab=lextab,
yacc_optimize=True, yacctab=yacctab, yacc_debug=False):
self.lex_optimize = lex_optimize
self.lextab = lextab
self.yacc_optimize = yacc_optimize
self.yacctab = yacctab
self.yacc_debug = yacc_debug
self.lexer = Lexer()
self.lexer.build(optimize=lex_optimize, lextab=lextab)
self.tokens = self.lexer.tokens
self.parser = ply.yacc.yacc(
module=self, optimize=yacc_optimize,
errorlog=ply.yacc.NullLogger(),
debug=yacc_debug, tabmodule=yacctab, start='program')
# https://github.com/rspivak/slimit/issues/29
# lexer.auto_semi can cause a loop in a parser
# when a parser error happens on a token right after
# a newline.
# We keep record of the tokens that caused p_error
# and if the token has already been seen - we raise
# a SyntaxError exception to avoid looping over and
# over again.
self._error_tokens = {}
# This is a simply variant of slimit.minify that suppresses unwanted noisy stderr logging output.
def warning_free_minify(text, mangle=False, mangle_toplevel=False):
parser = SlimitNoLoggingParser(lex_optimize=False)
tree = parser.parse(text)
if mangle:
mangler.mangle(tree, toplevel=mangle_toplevel)
minified = ECMAMinifier().visit(tree)
return minified
There are some similar questions, but the replies there do not work for me.
I am trying to do this, as explained in the warnings documentation:
def disable_pandas_warnings():
import warnings
warnings.resetwarnings() # Maybe somebody else is messing with the warnings system?
warnings.filterwarnings('ignore') # Ignore everything
# ignore everything does not work: ignore specific messages, using regex
warnings.filterwarnings('ignore', '.*A value is trying to be set on a copy of a slice from a DataFrame.*')
warnings.filterwarnings('ignore', '.*indexing past lexsort depth may impact performance*')
And I call this at the start of my test/program:
disable_pandas_warnings()
As you can see in the comments, I have:
made sure that the warnings filters are not polluted (since filtering is performed on a first-match way)
ignore all messages
ignore specific messages (by giving message regex)
Nothing seems to work: messages are still displayed. How can I disable all warnings?