Skip to content

BUG: Index.get_indexer matches pd.NA against NaN for list input but not ndarray input #65419#65442

Open
sayantancodex wants to merge 16 commits into
pandas-dev:mainfrom
sayantancodex:fix-65419
Open

BUG: Index.get_indexer matches pd.NA against NaN for list input but not ndarray input #65419#65442
sayantancodex wants to merge 16 commits into
pandas-dev:mainfrom
sayantancodex:fix-65419

Conversation

@sayantancodex
Copy link
Copy Markdown

Description

This PR fixes an inconsistency in Index.get_indexer where pd.NA was not matched against NaN labels in object-dtype indexes when the target was an ndarray or an Index.

The fix involves normalizing pd.NA to np.nan in _maybe_cast_listlike_indexer for object-dtype indexes, which aligns the behavior of array-like inputs with the existing behavior for list-like inputs and get_loc scalar lookups.

Changes

  • Updated pandas/core/indexes/base.py to ensure consistent null normalization during indexer casting.
  • Added regression tests in pandas/tests/indexes/base/test_get_indexer_na.py.
  • Added a news entry in the v3.1.0.rst whatsnew file.

@sayantancodex sayantancodex requested a review from mroeschke as a code owner May 1, 2026 12:50
@jbrockmendel
Copy link
Copy Markdown
Member

Can you get the tests passing

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: Index.get_indexer matches pd.NA against NaN for list input but not ndarray input

2 participants