Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

debugging - How to find out where a Python Warning is from

I'm still kinda new with Python, using Pandas, and I've got some issues debugging my Python script.

I've got the following warning message :

[...]pandascoreindex.py:756: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
return self._engine.get_loc(key)

And can't find where it's from.

After some research, I tried to do that in the Pandas lib file (index.py):

try:
    return self._engine.get_loc(key)
except UnicodeWarning:
    warnings.warn('Oh Non', stacklevel=2)

But that didn't change anything about the warning message.

question from:https://stackoverflow.com/questions/17208567/how-to-find-out-where-a-python-warning-is-from

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can filter the warnings to raise which will enable you to debug (e.g. using pdb):

import warnings
warnings.filterwarnings('error')

*The warnings filter can be managed more finely (which is probably more appropriate) e.g.:

warnings.filterwarnings('error', category=UnicodeWarning)
warnings.filterwarnings('error', message='*equal comparison failed*')

Multiple filters will be looked up sequentially. ("Entries closer to the front of the list override entries later in the list, if both match a particular warning.")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...