Skip to content

Fix silent coordinate substitution in comp_data with duplicate index labels - #4040

Open
gr-0x076 wants to merge 1 commit into
mwaskom:masterfrom
gr-0x076:fix-comp-data-duplicate-index-nan
Open

gr-0x076 wants to merge 1 commit into
mwaskom:masterfrom
gr-0x076:fix-comp-data-duplicate-index-nan

Conversation

@gr-0x076

@gr-0x076 gr-0x076 commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #4036

Problem

When plotting a DataFrame that has duplicate index labels and contains missing values (`NaN`) in coordinate variables, `VectorPlotter.comp_data` drops missing values per-coordinate and inserts the converted Series into `comp_data`. Because `comp_data` retains the original duplicate index, pandas aligns on index labels, duplicating valid coordinate values across rows with duplicate index labels and silently fabricating points that do not exist in the input data.

Solution

Temporarily set `comp_data.index = pd.RangeIndex(len(comp_data))` and convert coordinates using matching integer range indices on `col` and `converters`. This ensures that pandas performs 1-to-1 positional assignment without label broadcasting during column insertion. The original user index is restored at the end of `comp_data`.

Testing

  • Added regression test `test_scatterplot_duplicate_index_with_na` in `tests/test_relational.py`.
  • Verified that all 121 tests in `tests/test_relational.py` and 165 tests in `tests/test_base.py` pass cleanly.

AI Disclosure

I used an AI coding assistant (Google Antigravity) to help investigate the pandas index alignment mechanism and draft the fix and regression test. I have reviewed and verified all code changes and test runs locally.

…labels

Avoid pandas label-based alignment during comp_data insertion by
temporarily using RangeIndex during coordinate conversion, restoring
the original index at the end.
Fixes mwaskom#4036
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scatterplot silently substitutes missing coordinates when the DataFrame index contains duplicates

1 participant