Skip to content

Fix KeyError: 0 on pandas 3 by using .iloc for positional access - #45

Merged
carloscinelli merged 2 commits into
nlapier2:mainfrom
1106maxi:fix/series-iloc
Oct 18, 2026
Merged

carloscinelli merged 2 commits into
nlapier2:mainfrom
1106maxi:fix/series-iloc

Conversation

@1106maxi

Copy link
Copy Markdown
Contributor

Summary

Fixes KeyError: 0 when running with pandas 3.x.

Cause

Series[0] on a string-indexed Series (e.g. model.tvalues, indexed by variable name) used to fall back to positional access. That fallback was deprecated in pandas 2.1 and removed in 3.0, so partial_r2 and extract_from_model now raise KeyError: 0.

Changes

  • Use .iloc[0] for positional access in sensitivity_statistics.py and sensitivity_plots.py.

Testing

Environment: macOS, Python 3.14.0, pandas 3.0.6
(run with pytest --continue-on-collection-errors for "before", since
tests/test_ovb_plots.py otherwise aborts collection)

  • Before: 19 failed, 28 passed, 2 errors (mostly KeyError: 0; a few
    SystemExit: [...] must be numeric). Coverage 67%.
  • After: 49 passed. Coverage 94%.

Fix KeyError: 0 on pandas 3.x by using .iloc[0] for positional access
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (a45d7f0) to head (2a66d6f).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #45      +/-   ##
==========================================
- Coverage   94.97%   94.36%   -0.62%     
==========================================
  Files          12       12              
  Lines        1235     1243       +8     
==========================================
  Hits         1173     1173              
- Misses         62       70       +8     

☔ 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.

@carloscinelli
carloscinelli merged commit 8f88d01 into nlapier2:main Oct 18, 2026
6 checks passed
@1106maxi
1106maxi deleted the fix/series-iloc branch October 23, 2026 11:39
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.

3 participants