Skip to content

Conversation

@Mayankvlog
Copy link

Background

  • Issue: GH#62723
  • Problem: s.iloc[0] = {} would convert the dictionary to a Series, while s[0] = {} worked correctly
  • Root Cause: CoW logic was not preserving dictionary objects during iloc assignment

Changes Made

  • Fixed the CoW mechanism to preserve dictionary identity during iloc assignment
  • Added comprehensive test suite covering edge cases and regression scenarios
  • Ensured consistency between direct assignment (s[0] = {}) and iloc assignment (s.iloc[0] = {})

Tests Added

Added tests/indexing/test_iloc_dict_assignment.py with 10 comprehensive test cases:

  • Basic dictionary preservation
  • Complex nested dictionaries
  • Multiple assignments
  • Consistency with direct assignment
  • Error handling for non-object dtypes
  • Other object type preservation
  • DataFrame iloc compatibility
  • Original bug reproduction

Verification

  • All tests pass
  • Pre-commit checks pass (ruff, formatting, etc.)
  • No breaking changes to existing functionality
  • Maintains backward compatibility

Related

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New tests added

Mayank added 9 commits October 22, 2025 18:25
…d weakrefs when clearing referenced_blocks; add regression tests
…avoid breaking external references (GH#62787)
- Tests verify iloc preserves dictionaries in object dtype Series
- Covers edge cases: nested dicts, multiple assignments, consistency with direct assignment
- Includes regression test for original bug scenario
- All tests pass pre-commit checks
- Remove unused numpy and pandas._testing imports
- Standardize string quotes to double quotes throughout
- Add trailing commas and fix whitespace
- Pre-commit formatting improvements
@mroeschke
Copy link
Member

Please refer to my prior comment #62789 (comment)

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.

BUG: assignment to Series.iloc with dtype="object" converts dictionary to Series

2 participants