Skip to content

[codex] Fix facet grid categorical missing IDs#1092

Merged
has2k1 merged 2 commits into
has2k1:mainfrom
EltonChang1:codex/fix-facet-grid-categorical-na
Jul 3, 2026
Merged

[codex] Fix facet grid categorical missing IDs#1092
has2k1 merged 2 commits into
has2k1:mainfrom
EltonChang1:codex/fix-facet-grid-categorical-na

Conversation

@EltonChang1

Copy link
Copy Markdown
Contributor

Summary

  • Fix categorical ID assignment for drop=True so missing categorical values receive a positive panel id after the used categories instead of 0.
  • Add regression coverage for facet_grid with missing categorical facet values and for the underlying ninteraction helper.

Fixes #1086.

Why

When a categorical facet variable contained missing values, _id_var(..., drop=True) converted pandas category code -1 to 0. facet_grid then built layout rows with column 0 while ncol was based on the positive category IDs, so strip setup tried to access more panel entries than there were axes and raised IndexError.

Validation

  • Reporter reproducer with facet_grid("R ~ C") now draws successfully.
  • .venv/bin/python -m pytest tests/test_utils.py -k "ninteraction" -q
  • .venv/bin/python -m pytest tests/test_facets.py -k "missing_categorical or unused_categories" -q
  • .venv/bin/python -m pytest tests/test_utils.py tests/test_facets.py -q
  • .venv/bin/python -m ruff check plotnine/_utils/__init__.py tests/test_utils.py tests/test_facets.py
  • .venv/bin/python -m ruff format --check plotnine/_utils/__init__.py tests/test_utils.py tests/test_facets.py
  • git diff --check

Limitations

Full repository test suite was not run locally; this change was validated with the affected utility and facet test files plus targeted lint/format checks.

AI Disclosure

This draft PR was prepared with assistance from OpenAI Codex/ChatGPT. Codex helped reproduce the issue, inspect the facet layout code, implement the focused fix, add tests, and run validation. The final diff and PR text were reviewed in this local checkout before submission.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.46%. Comparing base (3f63b24) to head (8f228ad).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1092      +/-   ##
==========================================
+ Coverage   87.29%   87.46%   +0.16%     
==========================================
  Files         208      208              
  Lines       14602    14703     +101     
  Branches     1825     1834       +9     
==========================================
+ Hits        12747    12860     +113     
+ Misses       1282     1274       -8     
+ Partials      573      569       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@has2k1 has2k1 marked this pull request as ready for review July 3, 2026 11:56
Both the drop and no-drop paths now share one recoding of the
categorical codes, and the non-categorical path uses match(start=1)
instead of a manual increment.
@has2k1 has2k1 force-pushed the codex/fix-facet-grid-categorical-na branch from af6d551 to 8f228ad Compare July 3, 2026 12:36
Copilot AI review requested due to automatic review settings July 3, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@has2k1

has2k1 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

@EltonChang1, thank you.

@has2k1 has2k1 merged commit bb60820 into has2k1:main Jul 3, 2026
8 checks passed
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.

Facet_grid(drop=True)) + nan in categorical -> IndexErorr

3 participants