My concrete example:
In: list(pd.unique(df['x'].ravel()))
Out: [nan, 1.0]
But when I check if this is true:
In: list(pd.unique(df['x'].ravel())) is [nan, 1.0]
Out: False
Anybody can help me understand what am I doing wrong?
My concrete example:
In: list(pd.unique(df['x'].ravel()))
Out: [nan, 1.0]
But when I check if this is true:
In: list(pd.unique(df['x'].ravel())) is [nan, 1.0]
Out: False
Anybody can help me understand what am I doing wrong?
is
tests to see if the expressions on each side are the same object. To see if they are equivalent, use ==
.
Either way, even if you were to properly use ==, you'd still get False
. A quick workaround would be to filter out nan's:
[x for x in list(pd.unique(df['x'].ravel())) if str(x) != 'nan'] == ...
See why "NaN" doesn't equal "NaN".
I think you need test like:
In [73]: df['x']
Out[73]:
0 np.nan
1 1
Name: x, dtype: object
In [74]: list(pd.unique(df['x'].ravel())) == ['np.nan', '1']
Out[74]: True