reductionista commented on a change in pull request #475: Kmeans: Convert
python inf and nan values to postgres
URL: https://github.com/apache/madlib/pull/475#discussion_r372017347
##########
File path: src/ports/postgres/modules/kmeans/kmeans_auto.py_in
##########
@@ -151,8 +152,11 @@ def kmeans_auto(schema_madlib, rel_source, output_table,
expr_point, k,
WHERE k = {current_k}),
'{fn_dist}')
""".format(**locals())
- silhouette_vals.append(
- plpy.execute(silhouette_query)[0]['simple_silhouette'])
+ new_silh =
plpy.execute(silhouette_query)[0]['simple_silhouette']
+ new_silh = "Infinity" if math.isinf(new_silh) else new_silh
+ new_silh = "NaN" if math.isnan(new_silh) else new_silh
Review comment:
I think this may result in a SQL error unless we change these values
slightly to "'Infinity'::REAL" and "'NaN'::REAL"
```
select ARRAY[101458.80510776624, 54486.907688432577, 18710.554755872785,
1549.1568578504798, Infinity, Infinity, NaN];
ERROR: column "infinity" does not exist
select ARRAY[101458.80510776624, 54486.907688432577, 18710.554755872785,
1549.1568578504798, 'Infinity', 'Infinity', 'NaN'];
ERROR: column "infinity" does not exist
select ARRAY[101458.80510776624, 54486.907688432577, 18710.554755872785,
1549.1568578504798, 'Infinity'::REAL, 'Infinity'::REAL, 'NaN'::REAL];
array
--------------------------------------------------------
{101459,54486.9,18710.6,1549.16,Infinity,Infinity,NaN}
(1 row)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services