nitishagar opened a new pull request, #36605:
URL: https://github.com/apache/superset/pull/36605
### SUMMARY
Fix the Pandas `SettingWithCopyWarning` that appears in logs when loading
dashboards with Histogram and Box Plot charts.
**Root Cause:** When `df.dropna()` is called, Pandas cannot guarantee
whether it returns a view or a copy. Subsequent direct column assignment
`df[column] = value` on a potential view triggers the warning.
**Fix:** Use the `.loc[]` accessor for column assignment (`df.loc[:,
column] = value`), which is the Pandas-recommended approach to avoid this
warning.
**Changes:**
- `superset/utils/pandas_postprocessing/histogram.py:57` - Use `.loc[]`
accessor
- `superset/utils/pandas_postprocessing/boxplot.py:130` - Use `.loc[]`
accessor (same pattern)
This is a cosmetic fix that eliminates warnings without changing any
functionality.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
**Before (in logs):**
superset_app | /app/superset/utils/pandas_postprocessing/histogram.py:57:
SettingWithCopyWarning:
superset_app | A value is trying to be set on a copy of a slice from a
DataFrame.
superset_app | Try using .loc[row_indexer,col_indexer] = value instead
**After:** No warning in logs.
### TESTING INSTRUCTIONS
1. Start Superset: `docker compose up`
2. Login at `http://localhost:8088` with admin credentials
3. Create or load a dashboard with a Histogram chart
4. Check logs: `docker compose logs superset_app | grep
SettingWithCopyWarning`
5. Confirm no warning appears
**Automated tests:**
```bash
pytest tests/unit_tests/pandas_postprocessing/test_histogram.py
tests/unit_tests/pandas_postprocessing/test_boxplot.py -v
All 16 tests pass.
```
**ADDITIONAL INFORMATION**
- Has associated issue: Fixes #36530
- Required feature flags:
- Changes UI
- Includes DB Migration (follow approval process in
https://github.com/apache/superset/issues/13351)
- 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
--
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]