Skip to content

NaN values impact binary or operations asymmetrically #6528

Closed
@behzadnouri

Description

@behzadnouri

I am not sure if this is on purpose, but as far as I know, or operation should be symmetric ( I mean a | b == b | a ); not in pandas:

>>> a = pd.Series( [True] )
>>> b = pd.Series( [np.nan] )
>>> a | b
0    True
dtype: bool
>>> b | a
0    False
dtype: bool

is there any reason pandas is treating NaN values asymmetrically in here?

also, this is a weird outcome as well:

>>> ( b == True ) | ( a == True )
0    True
dtype: bool

and this:

 >>> b.astype( bool )
 0    True
 dtype: bool

this even has internal inconsistency; so before in b | a, NaN was treated as False, but now here it is True;

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions