FrancescoCastaldi opened a new pull request, #40462:
URL: https://github.com/apache/superset/pull/40462

   ### 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
   ```python
   df[column] = to_numeric(df[column], errors="coerce")
   ```
   
   ### After
   ```python
   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
   - [x] Verified the warning no longer appears when loading a dashboard 
containing a Histogram chart
   - [x] Existing unit tests in 
`tests/unit_tests/utils/pandas_postprocessing/test_histogram.py` pass without 
modification
   - [x] No behavioral change — only log noise removed
   
   ### Checklist
   - [x] Added/updated tests
   - [x] Linted with `pre-commit` hooks (`black`, `isort`, `pylint`, `mypy`)
   - [x] PR title follows the [Conventional 
Commits](https://www.conventionalcommits.org/) spec (`fix: ...`)
   - [x] Issue linked via `Fixes #36530`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to