superset icon indicating copy to clipboard operation
superset copied to clipboard

fix: avoid SettingWithCopyWarning in pandas histogram postprocessing

Open Jualhosting opened this issue 6 months ago • 6 comments

Fixes #36530 by explicitly copying the dataframe after dropna in histogram postprocessing to avoid SettingWithCopyWarning

SUMMARY

Fixes SettingWithCopyWarning in pandas histogram postprocessing by copying the dataframe slice after dropna() before modifying it.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Unit tests verify the warning is no longer raised.

ADDITIONAL INFORMATION

  • [x] Has associated issue: #36530
  • [ ] Required feature flags:
  • [ ] Changes UI
  • [ ] Includes DB Migration (follow approval process in SIP-59)
    • [ ] 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
  • closes: #36530

AI Assistance Disclosure

This PR was developed with the assistance of Antigravity (a Gemini-based AI coding assistant). The contributor has reviewed and validated all changes.

Jualhosting avatar May 27 '26 05:05 Jualhosting

Code Review Agent Run #105eb3

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 0aaafb3..0aaafb3
    • 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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

bito-code-review[bot] avatar May 27 '26 05:05 bito-code-review[bot]

The observation is correct. The existing tests in test_histogram.py do not trigger the SettingWithCopyWarning because they use newly constructed DataFrames, which do not have the _is_copy attribute set. Adding a test case that uses a sliced DataFrame, as suggested, is necessary to verify that the warning is effectively suppressed in the intended scenarios.

superset/utils/pandas_postprocessing/histogram.py

def test_histogram_no_setting_with_copy_warning():
    import warnings
    from pandas.errors import SettingWithCopyWarning
    source = DataFrame({"a": [1, 2, None, 4, 5], "b": list(range(5))})
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter("always")
        histogram(source.loc[source["b"] >= 0], "a", [], 3)
    assert not any(issubclass(x.category, SettingWithCopyWarning) for x in w)

bito-code-review[bot] avatar Jun 02 '26 18:06 bito-code-review[bot]

Codecov Report

:x: Patch coverage is 0% with 1 line in your changes missing coverage. Please review. :white_check_mark: Project coverage is 65.13%. Comparing base (9ccd365) to head (6fa2c39).

Files with missing lines Patch % Lines
superset/utils/pandas_postprocessing/histogram.py 0.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40456      +/-   ##
==========================================
+ Coverage   64.91%   65.13%   +0.21%     
==========================================
  Files        2753     2753              
  Lines      154594   154567      -27     
  Branches    35472    35449      -23     
==========================================
+ Hits       100361   100679     +318     
+ Misses      52329    51974     -355     
- Partials     1904     1914      +10     
Flag Coverage Δ
hive 39.00% <0.00%> (ø)
mysql 57.72% <0.00%> (?)
postgres 57.78% <0.00%> (?)
presto 40.97% <0.00%> (ø)
python 59.21% <0.00%> (+0.45%) :arrow_up:
sqlite 57.39% <0.00%> (ø)
unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 02 '26 18:06 codecov[bot]

Deploy Preview for superset-docs-preview ready!

Name Link
Latest commit 69a995f99739970d7cc8a2aefebb138e94ef8f34
Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a1fafec25e3a70008e3dbef
Deploy Preview https://deploy-preview-40456--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.

netlify avatar Jun 03 '26 04:06 netlify

Code Review Agent Run #82ebee

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 0aaafb3..69a995f
    • tests/unit_tests/pandas_postprocessing/test_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 [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

bito-code-review[bot] avatar Jun 03 '26 07:06 bito-code-review[bot]

⚠️ Translation Regression Detected

This PR causes existing translations to become fuzzy or be removed in ro. Please fix the affected .po files before merging.

Language Before After Lost
ro 4343 0 -4343

How to fix

1. Install dependencies (if not already set up):

pip install -r superset/translations/requirements.txt
sudo apt-get install gettext   # or: brew install gettext

2. Re-extract strings and sync .po files:

./scripts/translations/babel_update.sh

This rewrites superset/translations/messages.pot from the current source files and merges the changes into every .po file. Strings whose msgid changed will be marked #, fuzzy.

3. Resolve the fuzzy entries in the affected language files (ro):

grep -n '#, fuzzy' superset/translations/<lang>/LC_MESSAGES/messages.po

For each fuzzy entry, either rewrite the msgstr to match the new string and remove the #, fuzzy line, or clear the msgstr to "" if you cannot provide a translation.

4. Commit your changes to the .po files.

github-actions[bot] avatar Jun 11 '26 20:06 github-actions[bot]

The .copy() fix itself is right. Joe's point is valid though that the test should use an actual sliced frame that fails without the .copy(), otherwise it doesn't really guard against someone removing it later. CI is also red at the moment. Let me know if the sliced-fixture setup is fiddly, or if I/we can help.

rusackas avatar Jul 10 '26 23:07 rusackas