- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 19.2k
Description
Feature Type
- 
Adding new functionality to pandas 
- 
Changing existing functionality in pandas 
- 
Removing existing functionality in pandas 
Problem Description
When performing bitwise operations &, |, ^,  between two DataFrame objects of the same shape, pandas currently aligns by index and column labels rather than performing elementwise operations in a coordinate-to-coordinate manner.
This causes unintuitive behavior when users expect DataFrame operations to behave like Series operations, where & is applied positionally.
>>>  import pandas as pd
>>>  x = pd.DataFrame({
           "a": [True, False, True],
           "b": [10, 20, 30] 
         })
>>> y = pd.DataFrame({
         "c": [False, True, True],
        })
>>> x[["a"]] & y
a | c
-- | --
False | False
False | False
False | False
False | False
Feature Description
Add an option or mechanism to perform coordinate-wise (elementwise) bitwise operations between two DataFrames when their shapes are compatible but labels differ.
Specifically, when performing df1 & df2
Rationale
- Aligns behavior with user expectations and Series semantics.
- Reduces surprising “matrix-like” outputs that almost never match intended use. Which may result in a big memory allocation
Alternative Solutions
If both DataFrames are of the same shape, automatically cast them to their underlying .to_numpy() values or equivalent Series-like behavior before applying the operation.
Additional Context
No response