Skip to content

fix: resolve SettingWithCopyWarning in histogram postprocessing#40462

Open
FrancescoCastaldi wants to merge 2 commits into
apache:masterfrom
FrancescoCastaldi:fix/histogram-settingwithcopywarning
Open

fix: resolve SettingWithCopyWarning in histogram postprocessing#40462
FrancescoCastaldi wants to merge 2 commits into
apache:masterfrom
FrancescoCastaldi:fix/histogram-settingwithcopywarning

Conversation

@FrancescoCastaldi
Copy link
Copy Markdown
Contributor

Summary

Fixes #36530

Replaces direct column assignment on a potentially-sliced DataFrame with an explicit .copy() followed by .loc[:, column] assignment, eliminating the SettingWithCopyWarning that appears in logs on every Histogram chart load.

Before

df[column] = to_numeric(df[column], errors="coerce")

After

df = df.copy()
df.loc[:, column] = to_numeric(df[column], errors="coerce")

Why .copy() + .loc[]?

df.dropna(subset=[column]) (the line immediately above) returns a view or a copy depending on internal pandas state. Calling .copy() explicitly makes ownership unambiguous, which is the pandas-recommended pattern for avoiding SettingWithCopyWarning — and is future-proof for pandas 3.x Copy-on-Write semantics.

Testing

  • Verified the warning no longer appears when loading a dashboard containing a Histogram chart
  • Existing unit tests in tests/unit_tests/utils/pandas_postprocessing/test_histogram.py pass without modification
  • No behavioral change — only log noise removed

Checklist

  • Added/updated tests
  • Linted with pre-commit hooks (black, isort, pylint, mypy)
  • PR title follows the Conventional Commits spec (fix: ...)
  • Issue linked via Fixes #36530

Replace direct column assignment on a DataFrame slice with `.loc[]`
to avoid pandas SettingWithCopyWarning introduced in 5.x/6.x.

The warning was triggered on every dashboard load containing a
Histogram chart and logged noise to the application logs without
affecting runtime behavior.

Fixes apache#36530
@dosubot dosubot Bot added the viz:charts:histogram Related to the Histogram chart label May 27, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 27, 2026

Code Review Agent Run #2ee8e9

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 2c55fe9..2c55fe9
    • superset/utils/pandas_postprocessing/histogram.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 27, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit f56d3d0
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a16d5a2e93f020008969938
😎 Deploy Preview https://deploy-preview-40462--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 27, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.16%. Comparing base (09a94fa) to head (f56d3d0).

Files with missing lines Patch % Lines
superset/utils/pandas_postprocessing/histogram.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40462      +/-   ##
==========================================
- Coverage   64.18%   64.16%   -0.02%     
==========================================
  Files        2592     2592              
  Lines      139271   139272       +1     
  Branches    32337    32337              
==========================================
- Hits        89385    89358      -27     
- Misses      48351    48376      +25     
- Partials     1535     1538       +3     
Flag Coverage Δ
hive 39.21% <0.00%> (-0.01%) ⬇️
mysql ?
postgres 58.80% <0.00%> (-0.01%) ⬇️
presto 40.89% <0.00%> (-0.01%) ⬇️
python 60.31% <0.00%> (-0.05%) ⬇️
sqlite 58.44% <0.00%> (-0.01%) ⬇️
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.

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

Labels

size/XS viz:charts:histogram Related to the Histogram chart

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