Skip to content

Conversation

@MaxGhenis
Copy link
Collaborator

Summary

  • Fixed pandas 3.0 compatibility by changing how MicroSeries are handled in MicroDataFrame
  • The previous approach of modifying __class__ on DataFrame columns no longer works due to Copy-on-Write behavior in pandas 3.0
  • Now __getitem__ wraps all Series results as MicroSeries on access, rather than trying to modify columns in-place
  • Removed the broken _link_weights and catch_series_relapse logic that relied on class mutation

Test plan

  • All 46 existing tests pass with pandas 3.0.0
  • Tests verify MicroSeries methods like set_weights() are accessible after DataFrame column access
  • Tests verify weighted operations (sum, mean, count) work correctly
  • Tests verify Copy-on-Write compatibility (copies are independent)
  • Tests verify groupby operations preserve weights

Fixes the "AttributeError: 'Series' object has no attribute 'set_weights'" error that was occurring in policyengine-uk tests with pandas 3.0.

🤖 Generated with Claude Code

MaxGhenis and others added 4 commits January 25, 2026 08:21
The previous approach of modifying `__class__` on DataFrame columns no longer
works in pandas 3.0 due to Copy-on-Write behavior. Each column access returns
a new copy, so class modifications don't persist.

This fix changes the strategy:
- `__getitem__` now wraps all Series results as MicroSeries on access
- Removed the broken `_link_weights` and `catch_series_relapse` logic
- Simplified `_link_all_weights` since columns are wrapped on access

This resolves the "AttributeError: 'Series' object has no attribute
'set_weights'" error that occurred when using MicroDataFrame with pandas 3.0.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This test specifically verifies the fix for the issue where
`mdf["column"].set_weights()` would fail with AttributeError
in pandas 3.0 with Copy-on-Write enabled, because each column
access returned a new copy instead of the wrapped MicroSeries.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@MaxGhenis MaxGhenis merged commit 216e2dc into main Jan 25, 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.

2 participants