Possible code improvement suggestion: Use is not None
rather than bool() for None check
#32720
Labels
Code Style
Code style, linting, code_checks
Milestone
Code Sample, a copy-pastable example if possible
While going through the code I observed at couple of places where
bool(o)
is being used to check whether the objecto
isNone
.Example 1:
pandas/pandas/core/strings.py
Line 449 in 6620dc6
Example 2:
pandas/pandas/core/strings.py
Line 821 in 6620dc6
Problem description
bool(o)
is several times slower thano is not None
(see below). In the above cases however, majority of the time indeed is being taken by there.search
and therefore it might not matter for the overall time. But, why not switch to the possibly correct version?Moreover, the functionality remains the same as
re.search
andre.match
returnNone
when they cannot find a match; which is fundamentally what is being checked in this code.The text was updated successfully, but these errors were encountered: