fix: resolve SettingWithCopyWarning in histogram postprocessing#40462
fix: resolve SettingWithCopyWarning in histogram postprocessing#40462FrancescoCastaldi wants to merge 2 commits into
Conversation
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
Code Review Agent Run #2ee8e9Actionable Suggestions - 0Review 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 |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fixes #36530
Replaces direct column assignment on a potentially-sliced DataFrame with an explicit
.copy()followed by.loc[:, column]assignment, eliminating theSettingWithCopyWarningthat appears in logs on every Histogram chart load.Before
After
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 avoidingSettingWithCopyWarning— and is future-proof for pandas 3.x Copy-on-Write semantics.Testing
tests/unit_tests/utils/pandas_postprocessing/test_histogram.pypass without modificationChecklist
pre-commithooks (black,isort,pylint,mypy)fix: ...)Fixes #36530