Skip to content

fix(pandas): resolve SettingWithCopyWarning across post-processing utils#39293

Open
abhyudaytomar wants to merge 1 commit intoapache:masterfrom
abhyudaytomar:fix/histogram-settingwithcopywarning
Open

fix(pandas): resolve SettingWithCopyWarning across post-processing utils#39293
abhyudaytomar wants to merge 1 commit intoapache:masterfrom
abhyudaytomar:fix/histogram-settingwithcopywarning

Conversation

@abhyudaytomar
Copy link
Copy Markdown

Summary

Fixes #36530

When loading dashboards with Histogram charts, a SettingWithCopyWarning appears in Python logs because DataFrame mutation operations are performed on potential views/slices without making an explicit copy first.

This PR adds .copy() calls before mutating DataFrames across all affected pandas post-processing utilities:

  • histogram.py: df = df.copy() before to_numeric assignment
  • boxplot.py: df = df.copy() before to_numeric loop over metrics
  • rank.py: df = df.copy() before rank column assignment
  • pivot.py: df = df.copy() before fillna on columns
  • prophet.py: df = df.copy() before timezone conversion
  • geography.py: .copy() before geohash operations
  • compare.py: .copy() before in-place rename

Root Cause

The pandas SettingWithCopyWarning is triggered when assigning to a column of a DataFrame that may be a slice/view rather than an owned copy. While functionally correct in most cases, this is a pandas anti-pattern that can mask subtle bugs and pollutes application logs.

Test Plan

  • Existing tests continue to pass (pytest tests/unit_tests/pandas_postprocessing/)
  • Load a dashboard with a Histogram chart and verify no SettingWithCopyWarning in logs
  • Verify histogram, boxplot, rank, pivot, prophet, geography, and compare post-processing outputs are unchanged

Made with Cursor

Add explicit .copy() calls before mutating DataFrames that may be
views/slices, preventing pandas SettingWithCopyWarning in logs.

Files fixed:
- histogram.py: copy before to_numeric assignment
- boxplot.py: copy before to_numeric loop
- rank.py: copy before rank column assignment
- pivot.py: copy before fillna on columns
- prophet.py: copy before tz_convert
- geography.py: copy before geohash operations
- compare.py: copy before in-place rename

Fixes apache#36530

Made-with: Cursor
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review bot commented Apr 11, 2026

Code Review Agent Run #bccc0d

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: 0fe1f17..0fe1f17
    • superset/utils/pandas_postprocessing/boxplot.py
    • superset/utils/pandas_postprocessing/compare.py
    • superset/utils/pandas_postprocessing/geography.py
    • superset/utils/pandas_postprocessing/histogram.py
    • superset/utils/pandas_postprocessing/pivot.py
    • superset/utils/pandas_postprocessing/prophet.py
    • superset/utils/pandas_postprocessing/rank.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

@dosubot dosubot bot added the change:backend Requires changing the backend label Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(low priority) Histogram throws warning in logs in 6.0.0rc4

1 participant