Skip to content

Conversation

@yarikoptic
Copy link
Member

real-life example of strings not always (I am not even talking about possible unicode here) being singletones, thus inappropriate for 'is' whenever '==' is intended:

(Pdb) self.algorithm is "nipals"
False
*(Pdb) self.algorithm == "nipals"
True
*(Pdb) print self.algorithm
nipals
*(Pdb) print repr(self.algorithm)
'nipals'
*(Pdb) print self.algorithm.__class__
<type 'str'>

(Pdb) self.algorithm is "nipals"
False
*(Pdb) self.algorithm == "nipals"
True
*(Pdb) print self.algorithm
nipals
*(Pdb) print repr(self.algorithm)
'nipals'
*(Pdb) print self.algorithm.__class__
<type 'str'>
@GaelVaroquaux
Copy link
Member

Yup, indeed. 'is' shouldn't be used for checking for equality. Thank you!

GaelVaroquaux added a commit that referenced this pull request May 12, 2011
0.8.x (to be cp to master as well) PLS -- use string comparisons (instead of identity checking) and few spell fixes
@GaelVaroquaux GaelVaroquaux merged commit 67ff4ef into scikit-learn:0.8.X May 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants