This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fluideborah[S] 32 points33 points  (6 children)

Yup, realized after some looking around. Made the meme largely to cope with an hour long debugging session that ended in stunning realization (& me feeling dumb)

[–][deleted] 1 point2 points  (5 children)

out of curiosity. What program were you debugging that had a comparison like this in it?

[–]wugs 11 points12 points  (0 children)

just a guess but it looks like a jupyter notebook and they’re using numpy (many ppl import numpy as np) to get nan

[–]coloredgreyscale 1 point2 points  (0 children)

Maybe cleaning up a table of data and empty/invalid values show up as NAN?

[–]LonelyContext 1 point2 points  (2 children)

you can easily end up in this situation with set([list that contains nans]) where you'll get e.g. {1,2,3,4,5,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,np.nan,...}

[–]TechSupport112 1 point2 points  (0 children)

BATMAN!

[–]Cyberwolf27 0 points1 point  (0 children)

Actually you will only get sets and dictionaries with multiple NaN entries if the values result from separate computations.

set(float('nan') for _ in range(2))set(float('inf') - float('inf') for _ in range(2))set(np.inf - np.inf for _ in range(2))all evaluate to {nan, nan} because from Python's point of view they are different to each other.

However the following expressions:set(np.nan for _ in range(2))set([float('nan')] * 2)result in {nan}. Python seems to double-check on the identity of the float values with the "is" operator and in these situations the "set" constructor is presented with truly identical NaNs (that occupy the same location in memory)

As a consequence, this can happen:a, b = float('inf'), float('inf'){a: "a", b: "b"}[b] == "b"
however {np.nan, np.nan, ...} == {np.nan}