4

I want to insert nan instead of the float values using python code. Here is what I'm trying, and always end up with a typecast error:

example input_map <int, float> {1:0.9, 2:0.8, 3:NaN}
for key in input_map:
    if (not math.isnan(input_map[key])):
        out_values[key] = values[key]
    else:
        out_values[key] = float('nan') 

Tried all the possible combinations in the else float(nan) | float('NaN') |float("NaN") etc

// Insert statement to be executed:
insert into keyspace.cfamily (var1, var2, map_data) values ('value1', 'value2', {1:0.9, 2:0.8, 3:nan})

cql error: cassandra.InvalidRequest: code=2200 [Invalid query] message="Unable to make float from 'nan'"

C* version details: cqlsh:keyspace> show version [cqlsh 5.0.1 | Cassandra 2.2.4 | CQL spec 3.3.1 | Native protocol v4]

Python version: $python3 --version Python 3.4.3

Thank you for your time !

PRM
  • 41
  • 3
  • Quick update: numpy.nan or float('nan') responds with value nan for which cql query fails, but the same cql works fine when I manually change that to NaN – PRM Feb 10 '16 at 06:55

1 Answers1

0

Cassandra's nan syntax is NaN. You have to replace python's nan for NaN when mounting the query.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
mndcdk
  • 1
  • Edited: Cassandra's syntax is "NaN" . You have to replace python's "nan" for "NaN" when mounting the query. – mndcdk Jul 02 '21 at 11:49
  • Welcome to Stack Overflow. You can edit your own answer by clicking the _Edit_ link under the post. It's fine to explain or announce edits as comments, but updates to your answer should be done as actual edits. – Jeremy Caney Jul 05 '21 at 02:03