carloea2 commented on code in PR #8346:
URL: https://github.com/apache/texera/pull/8346#discussion_r3973443653


##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/contourPlot/ContourPlotOpDesc.scala:
##########
@@ -137,6 +161,65 @@ class ContourPlotOpDesc extends PythonOperatorDescriptor {
        |        yield {'html-content': html}
        |""".encode
   }
+
+  override def producesDataFrame(): Boolean = false
+
+  override def generateStandaloneCode(): String =
+    // render_error's continuation line keeps the runtime path's indentation — 
the
+    // HTML is triple-quoted, so those spaces reach the browser.
+    s"""import numpy as np
+       |from scipy.interpolate import griddata
+       |
+       |def render_error(error_msg):
+       |    return '''<h1>Contour plot is not available.</h1>
+       |                  <p>Reason is: {} </p>
+       |               '''.format(error_msg)
+       |
+       |def _write_error(message):
+       |    with open("output.html", "w", encoding="utf-8") as output:
+       |        output.write(render_error(message))
+       |
+       |# A row missing any of the three has no point to contribute, and 
griddata
+       |# refuses a NaN coordinate outright. Bound to a name of its own: the 
same
+       |# frame can feed another branch of the plan, which must still see 
every row.
+       |chart_df = in1df.dropna(subset=[${pyStringLiteral(x)}, 
${pyStringLiteral(
+      y
+    )}, ${pyStringLiteral(
+      z
+    )}])
+       |if chart_df.empty:
+       |    _write_error("Table should not have any empty/null values or 
fields.")
+       |else:
+       |    x = chart_df[${pyStringLiteral(x)}].values
+       |    y = chart_df[${pyStringLiteral(y)}].values
+       |    z = chart_df[${pyStringLiteral(z)}].values
+       |
+       |    # Cubic interpolation triangulates the points before it 
interpolates, which
+       |    # needs them to span a plane. Points that all fall on one line 
leave Qhull
+       |    # without a simplex to start from and it raises instead.
+       |    points = np.unique(np.column_stack((x, y)), axis=0)
+       |    if np.linalg.matrix_rank(points - points.mean(axis=0)) < 2:
+       |        _write_error("The x and y values all fall on one line, so 
there is no area to contour.")
+       |        raise SystemExit(0)

Review Comment:
   This exits the entire exported workflow, not just the contour operator. 
Collinear points such as (0, 0), (1, 1), (2, 2) trigger a successful process 
exit before later branches or final DataFrame outputs run. The native operator 
only emits its error page and returns. Keep this branch local instead of 
raising SystemExit.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to