How can Python compare strings with integers?

Python is not C. Unlike C, Python supports equality testing between arbitrary types. There is no ‘how’ here, strings don’t support equality testing to integers, integers don’t support equality testing to strings. So Python falls back to the default identity test behaviour, but the objects are not the same object, so the result is False. … Read more

== Operator and operands

In most languages it’s the same thing. People often do 1 == evaluated value because 1 is not an lvalue. Meaning that you can’t accidentally do an assignment. Example: if(x = 6)//bug, but no compiling error { } Instead you could force a compiling error instead of a bug: if(6 = x)//compiling error { } … Read more

Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?

Scala 2.7 tried to add functionality to Java [] arrays, and ran into corner cases that were problematic. Scala 2.8 has declared that Array[T] is T[], but it provides wrappers and equivalents. Try the following in 2.8 (edit/note: as of RC3, GenericArray is ArraySeq–thanks to retronym for pointing this out): import scala.collection.mutable.{GenericArray=>GArray, WrappedArray=>WArray} scala> GArray(0,1,2) … Read more

Why does (“foo” === new String(“foo”)) evaluate to false in JavaScript?

“foo” is a string primitive. (this concept does not exist in C# or Java) new String(“foo”) is boxed string object. The === operator behaves differently on primitives and objects. When comparing primitives (of the same type), === will return true if they both have the same value. When comparing objects, === will return true only … Read more

Pandas DataFrames with NaNs equality comparison

You can use assert_frame_equals with check_names=False (so as not to check the index/columns names), which will raise if they are not equal: In [11]: from pandas.testing import assert_frame_equal In [12]: assert_frame_equal(df, expected, check_names=False) You can wrap this in a function with something like: try: assert_frame_equal(df, expected, check_names=False) return True except AssertionError: return False In more … Read more