Skip to content

API/BUG: Behaviour of NA in BooleanArray pow operation #34686

Open
@jorisvandenbossche

Description

@jorisvandenbossche

For IntegerArray, we have some special-case behaviour for NAs in pow operation. For example, 1 ** NA == 1 and not NA as normal NA-propagation would be.

For BooleanArray, we don't have that, but maybe we should do the same? So that the boolean power of boolean-cast-to-int8 power operations for the same?

Right now this is different:

>>> a = pd.array([True] * 3 + [False] * 3 + [None] * 3, dtype="boolean")
>>> b = pd.array([True, False, None] * 3, dtype="boolean")  
>>> a 
<BooleanArray>
[True, True, True, False, False, False, <NA>, <NA>, <NA>]
Length: 9, dtype: boolean
>>> b
<BooleanArray>
[True, False, <NA>, True, False, <NA>, True, False, <NA>]
Length: 9, dtype: boolean

>>> a ** b
<IntegerArray>
[1, 1, <NA>, 0, 1, <NA>, <NA>, <NA>, <NA>]
Length: 9, dtype: Int8

>>> a.astype("Int8") ** b.astype("Int8") 
<IntegerArray>
[1, 1, 1, 0, 1, <NA>, <NA>, 1, <NA>]
Length: 9, dtype: Int8

Metadata

Metadata

Assignees

No one assigned

    Labels

    API - ConsistencyInternal Consistency of API/BehaviorBugNA - MaskedArraysRelated to pd.NA and nullable extension arraysNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions