Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pylint, pandas : Comparison to True should be just 'expr' or 'expr is True' (singleton-comparison)

did anyone solve this pylint issue when using pandas?

C:525,59: Comparison to True should be just 'expr' or 'expr is True' (singleton-comparison)

this happens in the line where i'm using:

df_current_dayparts_raw['is_standard'] == True

I tried these but didn't work:

df_current_dayparts_raw['is_standard'] is True
df_current_dayparts_raw['is_standard'].isin([True])
df_current_dayparts_raw['is_standard'].__eq__(True)
like image 321
findissuefixit Avatar asked Aug 02 '18 15:08

findissuefixit


1 Answers

If you have instantiate a dataframe with the following code

test = pd.DataFrame({"bool": [True, False, True], "val":[1,2,3]})
>>> test
    bool  val
0   True    1
1  False    2
2   True    3

the following should only return the fields where "bool" is True

test[test['bool']]

   bool  val
0  True    1
2  True    3

You do not need to explicitly state that test['bool'] == True, test['bool'] should be enough. This should be pylint compliant and satisfy singleton-comparison.

like image 110
superli3 Avatar answered Oct 20 '22 19:10

superli3