Skip to content

fix(recommandation): Fix chart recommandation#39886

Open
alexandrusoare wants to merge 2 commits intomasterfrom
alexandrusoare/fix/get_chart_recommandation
Open

fix(recommandation): Fix chart recommandation#39886
alexandrusoare wants to merge 2 commits intomasterfrom
alexandrusoare/fix/get_chart_recommandation

Conversation

@alexandrusoare
Copy link
Copy Markdown
Contributor

SUMMARY

recommended_visualizations in get_chart_data responses are based purely on column count and column name string matching. A table chart with 2 columns gets "scatter plot" recommended; any column with "time" in the name triggers "line chart" even if it's not actually temporal.

Root Cause

Two problems:

  1. Temporal columns are invisible — The DataColumn.data_type inference uses a Python isinstance heuristic that checks for int/float/bool. Datetime values from SQL arrive as strings, so temporal columns are always classified as "string". Meanwhile, the query result already contains coltypes — a list of GenericDataType enum values (NUMERIC, STRING, TEMPORAL, BOOLEAN) derived from actual SQL types via extract_dataframe_dtypes() — but this field was never read.
  2. Recommendation logic ignores context — The old code only checked if any column name contains "time"/"date" and if column count <= 3. It didn't consider chart.viz_type (so it recommends the same type you already have), actual data types, or column cardinality (so high-cardinality ID columns trigger "scatter plot").

Fix

  • Read coltypes from the query result and use it to populate DataColumn.data_type with accurate SQL-derived types (falling back to the isinstance heuristic when coltypes is unavailable)
  • Replace the inline recommendation block with _recommend_visualizations(viz_type, columns, row_count) which:
    • Classifies columns by type (temporal, numeric, categorical based on cardinality)
    • Applies data-shape rules (temporal+numeric → line/area; categorical+numeric → bar/pie; multi-numeric → scatter; etc.)
    • Excludes the chart's current viz_type category from suggestions
    • Caps output at 4 recommendations

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 5, 2026

Code Review Agent Run #04a47b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 8b2a8d2..8b2a8d2
    • superset/mcp_service/chart/tool/get_chart_data.py
    • tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify
Copy link
Copy Markdown

netlify Bot commented May 5, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 8b2a8d2
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69f9bec7fe13600008c71fec
😎 Deploy Preview https://deploy-preview-39886--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

❌ Patch coverage is 15.58442% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.35%. Comparing base (dc1c0f6) to head (81d6fc2).
⚠️ Report is 17 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/chart/tool/get_chart_data.py 15.58% 65 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39886      +/-   ##
==========================================
- Coverage   64.35%   64.35%   -0.01%     
==========================================
  Files        2569     2569              
  Lines      134680   134750      +70     
  Branches    31254    31272      +18     
==========================================
+ Hits        86679    86718      +39     
- Misses      46505    46534      +29     
- Partials     1496     1498       +2     
Flag Coverage Δ
hive 39.65% <15.58%> (?)
mysql 59.89% <15.58%> (-0.05%) ⬇️
postgres 59.97% <15.58%> (-0.05%) ⬇️
presto 41.40% <15.58%> (-0.03%) ⬇️
python 61.50% <15.58%> (-0.01%) ⬇️
sqlite 59.59% <15.58%> (-0.05%) ⬇️
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread superset/mcp_service/chart/tool/get_chart_data.py
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 5, 2026

Code Review Agent Run #b70632

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset/mcp_service/chart/tool/get_chart_data.py - 1
    • Incorrect pie chart logic · Line 160-160
      The pie chart suggestion logic checks only the first categorical column's unique_count, but should verify if any categorical column has unique_count <= 10. This ensures pie charts are recommended when suitable low-cardinality categorical data exists, even if not in the first position. The old code filtered categorical columns upfront, so this check was implicitly for any; the refactor removed that filter but didn't update the pie condition accordingly.
      Code suggestion
       @@ -160,1 +160,1 @@
      -    if len(numeric) == 1 and categorical and categorical[0].unique_count <= 10:
      +    if len(numeric) == 1 and categorical and any(c.unique_count <= 10 for c in categorical):
Review Details
  • Files reviewed - 2 · Commit Range: 8b2a8d2..81d6fc2
    • superset/mcp_service/chart/tool/get_chart_data.py
    • tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +127 to +129
temporal = [c for c in columns if c.data_type == "temporal"]
numeric = [c for c in columns if c.data_type == "numeric"]
categorical = [c for c in columns if c.data_type in ("string", "boolean")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can probably be one loop right? Would that be better for the performance overhead?

Comment on lines +131 to +139
if temporal and numeric:
return _candidates_temporal_numeric(numeric, row_count)
if categorical and numeric:
return _candidates_categorical_numeric(numeric, categorical)
if len(numeric) >= 2:
return _candidates_multi_numeric(numeric, categorical)
if len(numeric) == 1 and not temporal and not categorical:
return _candidates_single_numeric(numeric[0], row_count)
return []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a single function call with multiple arguments instead?

Comment on lines +142 to +186
def _candidates_temporal_numeric(
numeric: list[DataColumn], row_count: int
) -> list[str]:
# Few data points are better as a bar chart than a line
if row_count < 5:
candidates = ["bar chart", "table"]
else:
candidates = ["line chart", "area chart", "bar chart"]
if len(numeric) > 1:
candidates.append("multi-line chart")
return candidates


def _candidates_categorical_numeric(
numeric: list[DataColumn],
categorical: list[DataColumn],
) -> list[str]:
candidates = ["bar chart"]
if len(numeric) == 1 and categorical[0].unique_count <= 10:
candidates.append("pie chart")
if len(numeric) >= 2:
candidates.append("scatter plot")
candidates.append("heatmap")
if any(c.unique_count > 5 for c in categorical):
candidates.append("treemap")
return candidates


def _candidates_single_numeric(col: DataColumn, row_count: int) -> list[str]:
candidates = ["big number / KPI", "gauge chart"]
if row_count > 20 and col.unique_count > 10:
candidates.insert(0, "histogram")
return candidates


def _candidates_multi_numeric(
numeric: list[DataColumn],
categorical: list[DataColumn],
) -> list[str]:
candidates = ["scatter plot"]
if len(numeric) >= 3:
candidates.append("bubble chart")
if categorical:
candidates.append("heatmap")
return candidates
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks a bit clearer with multiple functions though, not sure

if all(isinstance(v, (int, float)) for v in sample_values):
data_type = "numeric"
elif all(isinstance(v, bool) for v in sample_values):
if idx < len(coltypes):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this not available?

Comment on lines +1102 to +1103
from superset.mcp_service.chart.tool.get_chart_data import _GENERIC_TYPE_MAP
from superset.utils.core import GenericDataType
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe module level imports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants