codeant-ai-for-open-source[bot] commented on code in PR #44679:
URL: https://github.com/apache/superset/pull/44679#discussion_r4300438366


##########
superset/charts/client_processing.py:
##########
@@ -479,6 +479,133 @@ def _apply_show_values_as(  # pylint: 
disable=too-many-arguments
     return numeric / denominator.replace(0, np.nan)
 
 
+def _reduce_result_values(values: pd.Series, aggregate: str) -> Any:
+    """Reduce original metric results without aggregating intermediate 
summaries."""
+    if values.empty:
+        return None
+    name = aggregate.split(" as Fraction of ")[0]
+    if name == "Count":
+        return len(values)
+    if name == "Count Unique Values":
+        return values.nunique(dropna=False)
+    if name == "List Unique Values":
+        return ", ".join(sorted({str(value) for value in values}))
+    if name in {"First", "Last"}:
+        present = values.dropna()
+        return present.iloc[0 if name == "First" else -1] if len(present) else 
None

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `71d3b97`.
   
   The `Last` reducer now returns `values.iloc[-1]` directly, preserving a NULL 
final result instead of selecting an earlier value.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



##########
superset/charts/client_processing.py:
##########
@@ -479,6 +479,133 @@ def _apply_show_values_as(  # pylint: 
disable=too-many-arguments
     return numeric / denominator.replace(0, np.nan)
 
 
+def _reduce_result_values(values: pd.Series, aggregate: str) -> Any:
+    """Reduce original metric results without aggregating intermediate 
summaries."""
+    if values.empty:
+        return None
+    name = aggregate.split(" as Fraction of ")[0]
+    if name == "Count":
+        return len(values)
+    if name == "Count Unique Values":
+        return values.nunique(dropna=False)
+    if name == "List Unique Values":
+        return ", ".join(sorted({str(value) for value in values}))
+    if name in {"First", "Last"}:
+        present = values.dropna()
+        return present.iloc[0 if name == "First" else -1] if len(present) else 
None
+    numeric = pd.to_numeric(values, errors="coerce").dropna()
+    if name == "Sum":
+        text = values.dropna()
+        return text.iloc[-1] if numeric.empty and len(text) else numeric.sum()
+    if numeric.empty:
+        return None
+    if name == "Sample Variance":
+        return numeric.var(ddof=1) if len(numeric) > 1 else 0
+    if name == "Sample Standard Deviation":
+        return numeric.std(ddof=1) if len(numeric) > 1 else 0
+    return {
+        "Average": numeric.mean,
+        "Median": numeric.median,
+        "Minimum": numeric.min,
+        "Maximum": numeric.max,
+    }[name]()
+
+
+def _group_result_records(
+    source: pd.DataFrame, dimensions: list[str]
+) -> dict[tuple[str, ...], pd.DataFrame]:
+    """Index contributing records by the dimension prefix of a summary 
scope."""
+    if not dimensions:
+        return {(): source}
+    keys = [source[dim].fillna("SUPERSET_PANDAS_NAN").astype(str) for dim in 
dimensions]
+    return {
+        key if isinstance(key, tuple) else (key,): group
+        for key, group in source.groupby(keys, sort=False, dropna=False)
+    }

Review Comment:
   ✅ **CodeAnt verified this suggestion was addressed in subsequent commits and 
marked this thread resolved** as of `71d3b97`.
   
   Dimension keys are grouped as original scalar values, and 
`_result_scope_key` preserves those typed values instead of converting them to 
strings.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it 
open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to