Skip to content

BUG: wrong errors when indexing with list that includes pd.NA #31948

@jorisvandenbossche

Description

@jorisvandenbossche

Currently, indexing with a list including pd.NA (so the list version of indexing with a BooleanArray or IntegerArray) works on the array, but not on Series:

("works" = raising the correct error message)

In [21]: a = pd.array([1, 2, 3]) In [22]: a[[True, False, pd.NA]] ... ValueError: Cannot mask with a boolean indexer containing NA values In [23]: a[[0, 1, pd.NA]] ... ValueError: Cannot index with an integer indexer containing NA values 

vs

In [24]: s = pd.Series(a) In [25]: s[[True, False, pd.NA]] ... KeyError: 'Passing list-likes to .loc or [] with any missing labels is no longer supported, see https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike' In [26]: s[[0, 1, pd.NA]] ... TypeError: boolean value of NA is ambiguous 

Because the validation of the indexer isn't yet updated to handle listlikes that include pd.NA.

And similar problems for setitem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugError ReportingIncorrect or improved errors from pandasIndexingRelated to indexing on series/frames, not to indexes themselvesNA - MaskedArraysRelated to pd.NA and nullable extension arrays

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions