Repository navigation
fix(mcp): use chart metrics for the preview y axis - #44684
Conversation
Choose the Vega-Lite preview y field from the chart's metric labels instead of the first numeric-looking column. The previous heuristic is kept as a fallback when no metric label matches, and boolean values are no longer treated as numeric.
Code Review Agent Run #454e74Actionable Suggestions - 0Additional Suggestions - 1
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #44684 +/- ##
==========================================
+ Coverage 81.12% 81.20% +0.07%
==========================================
Files 2956 2961 +5
Lines 178434 178931 +497
Branches 41339 41406 +67
==========================================
+ Hits 144762 145293 +531
+ Misses 30967 30921 -46
- Partials 2705 2717 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Code Review Agent Run #aaa115Actionable Suggestions - 0Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
rebenitez1802
left a comment
There was a problem hiding this comment.
Approve — genuine improvement (kills the bool-as-int misclassification and ties the y-axis to the chart's actual metrics), security-neutral, and correctly tested for the numeric types real previews carry. Only optional nits below.
🟢 Low — Numeric gate is narrower than the sibling treemap validator
_resolve_y_metric_column gates on isinstance(value, (int, float)) and not isinstance(value, bool) (preview_utils.py:1273-1274, 1281-1282), whereas the treemap validator in the same module uses isinstance(value, (Real, Decimal)) (query_result.py:321) precisely because SQL NUMERIC/DECIMAL results (e.g. Postgres AVG/SUM) arrive as decimal.Decimal. This is not a real preview regression: the preview data comes from ChartDataCommand.run(), whose pipeline runs df_metrics_to_num (normalize_df → common/utils/dataframe_utils.py:62, enforce_numerical_metrics=True by default), coercing object-dtype metric columns to native float64 before df.to_dict("records") — a Decimal("7") SUM(amount) column becomes native float 7.0 at the resolver, so the gate passes and the y-axis is set. The only uncoerced path is the fallback loop over all columns (1281-1282), which df_metrics_to_num doesn't touch for non-metric dimensions — a marginal edge. Matching the treemap validator's (Real, Decimal) is a cheap consistency/robustness win; reasonable to take or skip. Fix (if taken): add from decimal import Decimal / from numbers import Real and use isinstance(value, (Real, Decimal)) and not isinstance(value, bool) in both checks.
🟢 Low — _resolve_y_metric_column return type is Any
The helper only ever returns str | None (a column label or None), but is annotated -> Any (preview_utils.py:1260). Tightening it documents the contract and gives mypy narrowing at the if metric_col: call site (1355). Fix: def _resolve_y_metric_column(row: Dict[str, Any], metrics: List[Any]) -> str | None:.
Verified, no change needed: the matched_metric early-None correctly still lets a later numeric metric win over an earlier non-numeric one (covered by test_vega_preview_y_axis_skips_nonnumeric_metrics); the numpy-scalar concern is moot (pandas 2.3.3 to_dict boxes np.int64/np.float64 to native types); the pie/theta and x==y fallback edges are pre-existing (untouched by this PR); the docs section accurately describes the code; and the change is out of security scope — read-only display-spec construction on already-authorized chart data, no auth/query/data-access boundary touched.
|
Taken both nits in a8c9ed3: both numeric checks use Real/Decimal (excluding bool), with a Decimal fallback regression test, and the return type is str | None. Chart tests: 2,153 passed, 3 skipped; pre-commit passed. |
|
Bito Automatic Review Skipped – PR Already Merged |
(cherry picked from commit f6d9b7b)
SUMMARY
The MCP chart preview built its Vega-Lite y encoding from the first column whose name looked like an aggregate or whose value looked numeric. Because Python
boolis a subclass ofint, a boolean x-axis column could be picked as the y field, and in general the y field was not guaranteed to be one of the chart's metrics.This change resolves the y field from the chart's
metricsin form_data, using their result labels (same rules asmetric_result_label) and picking the first one present in the result columns. The previous heuristic is kept only as a fallback when no metric label matches, and it no longer treats boolean values as numeric.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend preview spec change)
TESTING INSTRUCTIONS
New tests cover: boolean x column with a numeric metric (y is the metric), multiple metrics (first matching metric is used), metrics with no matching label (fallback skips booleans), and no metrics (no y encoding, unchanged).
ADDITIONAL INFORMATION
🤖 Generated with Claude Code