Skip to content

BUG: DataFrame.loc/iloc setitem with empty or boolean column indexer on EA dtypes (GH#66255)#66304

Open
chang-pro wants to merge 2 commits into
pandas-dev:mainfrom
chang-pro:fix-ea-setitem-empty-bool-column-mask
Open

BUG: DataFrame.loc/iloc setitem with empty or boolean column indexer on EA dtypes (GH#66255)#66304
chang-pro wants to merge 2 commits into
pandas-dev:mainfrom
chang-pro:fix-ea-setitem-empty-bool-column-mask

Conversation

@chang-pro

Copy link
Copy Markdown

EABackedBlock._unwrap_setitem_indexer interpreted a boolean column indexer as a positional one: indexer[1][0] == 0 is true for np.array([False]), so an all-False column mask unwrapped to the row indexer and set the entire column. The same branch raised IndexError for an empty positional indexer (iloc[:, []]) and NotImplementedError for an all-True mask. All three now behave like the numpy-dtype path:

df = pd.DataFrame({"col": [1, 2, 3, 4]}, dtype="Float64")
df.loc[:, df.columns == "nope"] = pd.NA   # before: whole column set to NA; after: no-op
df.iloc[:, []] = 99                        # before: IndexError; after: no-op
df.loc[:, np.array([True])] = 99           # before: NotImplementedError; after: sets the column

Affects all extension array dtypes (masked and arrow-backed). The bool handling is restricted to length-1 masks so multi-column 2D EA blocks keep their current behavior. loc/iloc/masked/internals suites pass (8089 tests).

Copilot AI review requested due to automatic review settings July 12, 2026 18:12

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 has reached their quota limit.

…EA setitem

Follow-up hardening for GH#66255: empty slices, list-like row indexers
with empty column lists, and 2-D empty indexers from maybe_convert_ix
are now no-ops that skip value validation entirely, matching
numpy-backed columns. Object-dtype indexer arrays raise IndexError the
same way numpy does instead of silently selecting the whole column.
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: Float64 vs float64 incorrect result when using empty slice

2 participants