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
  • 5,057
  • 8
  • 42
  • 75

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
  • 776,304
  • 153
  • 1,341
  • 1,358
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
  • 76,762
  • 20
  • 123
  • 145