Select to view content in your preferred language

Not a number (nan/1.#QNAN) condition testing for a FGDB raster attribute table?

1913
2
Jump to solution
09-17-2012 02:46 PM
ChrisSnyder
Honored Contributor
I'm cursoring through a FGDB raster attribute table in v10.1... Some of the attribute values are "Null" (aka 1.#QNAN), but when when evaluated in a cursor, they appear as a value called nan, for example:

>>> print updateRow[updateRows.fields.index("HCB")] nan
Unfortunatly nan is not a string but a float value... which is what the HCB field type is.

>>> type(updateRow[updateRows.fields.index("HCB")]) <type 'float'>


And nan isn't the same as None

>>> updateRow[updateRows.fields.index("HCB")] == None False

Problem is, I need a way to test for these nan values and then evaluate them as 0's... Something like:

hcbValue = updateRow[updateRows.fields.index("HCB")]) if hcbValue == None:     hcbValue = 0


If these evaluated as None, then of course it would be easy... but they don't, so it aint.

Anyone know how to do a conditional test for nan values???
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Honored Contributor
Found it

math.isnan()

as in

>>> math.isnan(updateRow[updateRows.fields.index("HCB")]) True

View solution in original post

0 Kudos
2 Replies
ChrisSnyder
Honored Contributor
Found it

math.isnan()

as in

>>> math.isnan(updateRow[updateRows.fields.index("HCB")]) True
0 Kudos
ChrisSnyder
Honored Contributor
FYI: A ESRI nan is not the same as

float('nan')
or
str(1e400*0)

...which I guess are other/older methods of evaluating nan values (http://stackoverflow.com/questions/944700/how-to-check-for-nan-in-python)

So...

>>> updateRow[updateRows.fields.index("HCB")] in [float('nan'), str(1e400*0)]
False
but the math.isnan() works...
0 Kudos