Skip to content

fix(recommandation): Fix chart recommandation#39886

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

fix(recommandation): Fix chart recommandation#39886
alexandrusoare wants to merge 3 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 63.87%. Comparing base (dc1c0f6) to head (879b1c2).
⚠️ Report is 37 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%   63.87%   -0.49%     
==========================================
  Files        2569     2583      +14     
  Lines      134680   136664    +1984     
  Branches    31254    31506     +252     
==========================================
+ Hits        86679    87289     +610     
- Misses      46505    47859    +1354     
- Partials     1496     1516      +20     
Flag Coverage Δ
hive 39.36% <15.58%> (?)
mysql 59.01% <15.58%> (-0.93%) ⬇️
postgres 59.09% <15.58%> (-0.94%) ⬇️
presto 41.05% <15.58%> (-0.37%) ⬇️
python 60.53% <15.58%> (-0.99%) ⬇️
sqlite 58.73% <15.58%> (-0.92%) ⬇️
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These iterate over the chart's columns — typically 2-10 items. Three passes on <10 elements is negligible; a single loop with conditional appends would be harder to read for no meaningful gain. Let me know your thoughts

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.

Yeah, my concern was about charts that have much more than that, but not sure if that is something that happens often

Comment thread superset/mcp_service/chart/tool/get_chart_data.py
Comment thread superset/mcp_service/chart/tool/get_chart_data.py
Comment thread superset/mcp_service/chart/tool/get_chart_data.py Outdated
Comment thread tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py Outdated
@alexandrusoare alexandrusoare requested a review from msyavuz May 6, 2026 10:52
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 6, 2026

Code Review Agent Run #d3843d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 81d6fc2..879b1c2
    • 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

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