2

I am working on a dataframe that has many custom functions, libraries, and calculations. After doing some critical calcs, I noticed some errors in calculations that should have returned a float:

enter image description here

To inspect one of the calculations, I do the following.

dFA.loc['20101120']['variable x']

which returns (in small caps)

nan

Then, to confirm that this thing is what looks like a weird (small caps) numpy.nan (True or False) I do:

dFA.loc['20101120']['variable x'] == np.nan

Which returns:

False

Then I do:

dFA.loc['20101120']['variable x'].dtype

Which returns:

dtype('float64')

Also:

dFA.loc['20101120']['variable x'] > 1000
False

Also:

dFA.loc['20101120']['variable x'] < 1000
False
Luis Miguel
  • 4,847
  • 8
  • 37
  • 72

2 Answers2

3
dFA.loc['20101120']['variable x'] == np.nan

Oops. NaN is never equal to NaN.

np.isnan(dFA.loc['20101120']['variable x'])
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325
2

All comparisons with np.nan evaluate to False by definition.

>>> np.nan == np.nan
False
>>> np.nan <= 1
False
>>> np.nan > 1
False

np.nan is a float:

>>> np.nan.__class__
<type 'float'>

... just a very special one.

Community
  • 1
  • 1
timgeb
  • 73,231
  • 20
  • 109
  • 138