警告标记潜在的类型不兼容

时间:2016-04-02 04:51:01

标签: python types warnings

我应该使用哪种警告来标记潜在的类型不兼容性?

我的具体用例如下:

df = pd.DataFrame({'ColName': [10, 20, 60, 70],
                   'Col2': [1, 2, 3, 4, 5]})
lookup_val = ['10','20']
filter = filter_df(df, 'ColName', lookup_val)
#filter_df is a custom function which filters the df based values & column name

我想警告用户在具有数值的列中查找字符串。我查看documentationRuntimeWarning似乎最接近。我还查看了其他Python包,它们似乎通常是基类Warning类的子类。不确定这是否很重要,但我只是好奇,如果有一个'正确'的答案。

这就是我想要做的事情:

if looking_up_strings_in_column_with_numbers:
     warnings.warn('looking up strings in numbers', CustomWarningClass) 
     #CustomWarningClass could be a subclass of Warning or maybe RuntimeWarning. My question is which one?

0 个答案:

没有答案