Skip to content

BUG: DataFrame.loc setitem with list-like value on single-column EA DataFrame#65241

Merged
mroeschke merged 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-44103
Apr 21, 2026
Merged

BUG: DataFrame.loc setitem with list-like value on single-column EA DataFrame#65241
mroeschke merged 2 commits intopandas-dev:mainfrom
jbrockmendel:bug-44103

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

Summary

  • Fix df.loc[row, [col]] = [val] raising ValueError on single-column DataFrames with ExtensionArray dtypes (e.g. string, Int64)
  • The single-block path in _setitem_single_block now processes column-by-column when the indexer selects a scalar row and array-like columns with a list-like value, matching the split-path behavior

closes #44103

Test plan

  • Added test_loc_setitem_single_column_listlike_value — sets with a plain list
  • Added test_loc_setitem_single_column_ea_value — sets with a pd.array
  • Existing indexing tests pass (test_loc, test_iloc, frame/indexing)

🤖 Generated with Claude Code

@jbrockmendel jbrockmendel marked this pull request as ready for review April 15, 2026 18:07
…ataFrame (pandas-dev#44103)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
def test_loc_setitem_single_column_listlike_value(self):
# GH#44103
df = DataFrame({"a": [None, "two"]}, index=[0, 1], dtype="string")
df.loc[0, ["a"]] = ["one"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have tests with assignment across multiple columns e.g. ["a", "b"]] = ["1", "2"]?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated with a new test

Comment thread pandas/core/indexing.py
and len(indexer) == 2
and is_integer(indexer[0])
and not is_integer(indexer[1])
and is_list_like(value)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to check that len(values) == len(indexer) - 1?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i think that is already handled within the split path

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mroeschke mroeschke added this to the 3.1 milestone Apr 21, 2026
@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves ExtensionArray Extending pandas with custom dtypes or arrays. labels Apr 21, 2026
@mroeschke mroeschke merged commit 5fef3cd into pandas-dev:main Apr 21, 2026
54 of 55 checks passed
@mroeschke
Copy link
Copy Markdown
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the bug-44103 branch April 21, 2026 17:28
Sharl0tteIsTaken added a commit to Sharl0tteIsTaken/pandas that referenced this pull request Apr 22, 2026
…h-origin

* upstream/main: (31 commits)
  DOC:Missing r in your (pandas-dev#65323)
  DOC: fix grammar in the .dt accessor section (pandas-dev#65325)
  REGR: restore rank() for ExtensionArrays with custom values for sorting (pandas-dev#64976)
  BUG: MultiIndex.get_loc returns scalar for unique key in non-unique index (pandas-dev#65234)
  BUG/TST: add test for _cast_pointwise_result robustness + fix some cases (pandas-dev#65318)
  BUG: fix .loc with tuple key on MultiIndex with IntervalIndex level (pandas-dev#65239)
  BUG: permit building from source with mingw (pandas-dev#64849)
  BUG: DataFrame.loc setitem with list-like value on single-column EA DataFrame (pandas-dev#65241)
  PERF: preserve block memory layout in Block.copy (GH#60469) (pandas-dev#65302)
  PERF: short-circuit sort_index(level=...) on monotonic non-MultiIndex (pandas-dev#65279)
  BUG: fix FloatingArray.astype(str) crash with distinguish_nan_and_na=True (pandas-dev#65038)
  BUG: fix to_timedelta ignoring unit for mixed round/non-round floats (pandas-dev#65170)
  BUG: DataFrame.loc preserves original index name when key is an Index (pandas-dev#65229)
  REF: continue moving freq management off DatetimeArray/TimedeltaArray (GH#24566) (pandas-dev#65285)
  REF: remove redundant BaseMaskedArray.map override (pandas-dev#65297)
  Bump github/codeql-action from 4.35.1 to 4.35.2 (pandas-dev#65310)
  Bump actions/setup-node from 6.3.0 to 6.4.0 (pandas-dev#65309)
  BUG: Fix formatters applied to wrong columns in truncated DataFrame.to_string (GH#35410) (pandas-dev#65288)
  PERF: optimize block consolidation (pandas-dev#64574)
  CLN: Replace no_default signature with False for allow_duplicates in insert and reset_index (pandas-dev#65146)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug ExtensionArray Extending pandas with custom dtypes or arrays. Indexing Related to indexing on series/frames, not to indexes themselves

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Unable to set StringArray for DataFrame with single column and dtype string

2 participants