This is an automated email from the ASF dual-hosted git repository.

okislal pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/madlib.git


The following commit(s) were added to refs/heads/master by this push:
     new 6b0240e  Kmeans: Convert python inf and nan values to postgres
6b0240e is described below

commit 6b0240e2a575b0bd354b5f83de922d3dc06aeef5
Author: Orhan Kislal <[email protected]>
AuthorDate: Fri Jan 31 17:23:41 2020 -0500

    Kmeans: Convert python inf and nan values to postgres
---
 src/ports/postgres/modules/kmeans/kmeans_auto.py_in | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/ports/postgres/modules/kmeans/kmeans_auto.py_in 
b/src/ports/postgres/modules/kmeans/kmeans_auto.py_in
index 5eb7d3c..3e6f0ab 100644
--- a/src/ports/postgres/modules/kmeans/kmeans_auto.py_in
+++ b/src/ports/postgres/modules/kmeans/kmeans_auto.py_in
@@ -26,6 +26,7 @@
 
 import numpy as np
 import plpy
+import math
 from utilities.control import MinWarning
 from utilities.utilities import _assert
 from utilities.utilities import unique_string
@@ -151,13 +152,18 @@ 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']
+                if math.isinf(new_silh):
+                    new_silh = "Infinity"
+                elif math.isnan(new_silh):
+                    new_silh = "NaN"
+                silhouette_vals.append(new_silh)
+
 
         update_query = """
             UPDATE {output_table} SET {{column}} = __value__ FROM
             (SELECT unnest(ARRAY[{k_arr}]) AS __k__,
-                    unnest(ARRAY[{{calc_arr}}]) AS __value__
+                    unnest(ARRAY[{{calc_arr}}]::DOUBLE PRECISION[]) AS 
__value__
             )sub_q
             WHERE __k__ = k
             """.format(output_table = output_table,

Reply via email to