Skip to content

REGR: frame/frame op with unaligned blocks + non-slice-like placement failing with assertion error #34367

Closed
@jorisvandenbossche

Description

@jorisvandenbossche
In [7]: arr = np.random.randint(0, 1000, (100, 10))  

In [8]: df1 = pd.DataFrame(arr)  

In [9]: df2 = df1.copy() 
   ...: df2.iloc[0, [1, 3, 7]] =  np.nan    

In [10]: df1 + df2  
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-10-fa4784095cc3> in <module>
----> 1 df1 + df2

~/scipy/pandas/pandas/core/ops/__init__.py in f(self, other, axis, level, fill_value)
    663         if isinstance(other, ABCDataFrame):
    664             # Another DataFrame
--> 665             new_data = self._combine_frame(other, na_op, fill_value)
    666 
    667         elif isinstance(other, ABCSeries):

~/scipy/pandas/pandas/core/frame.py in _combine_frame(self, other, func, fill_value)
   5734                 return func(left, right)
   5735 
-> 5736         new_data = ops.dispatch_to_series(self, other, _arith_op)
   5737         return new_data
   5738 

~/scipy/pandas/pandas/core/ops/__init__.py in dispatch_to_series(left, right, func, axis)
    283 
    284         array_op = get_array_op(func)
--> 285         bm = left._mgr.operate_blockwise(right._mgr, array_op)
    286         return type(left)(bm)
    287 

~/scipy/pandas/pandas/core/internals/managers.py in operate_blockwise(self, other, array_op)
    358         Apply array_op blockwise with another (aligned) BlockManager.
    359         """
--> 360         return operate_blockwise(self, other, array_op)
    361 
    362     def apply(self: T, f, align_keys=None, **kwargs) -> T:

~/scipy/pandas/pandas/core/internals/ops.py in operate_blockwise(left, right, array_op)
     34             right_ea = not isinstance(rblk.values, np.ndarray)
     35 
---> 36             lvals, rvals = _get_same_shape_values(blk, rblk, left_ea, right_ea)
     37 
     38             res_values = array_op(lvals, rvals)

~/scipy/pandas/pandas/core/internals/ops.py in _get_same_shape_values(lblk, rblk, left_ea, right_ea)
     84 
     85     # Require that the indexing into lvals be slice-like
---> 86     assert rblk.mgr_locs.is_slice_like, rblk.mgr_locs
     87 
     88     # TODO(EA2D): with 2D EAs pnly this first clause would be needed

AssertionError: BlockPlacement([0 2 4 5 6 8 9])

cc @jbrockmendel I suppose caused by the frame-frame blockwise PR (#32779), but didn't yet look into detail

Just removing the assertion seems to still work (for this case), but I don't know if that _get_same_shape_values functino relies on the is_slice_like characteristic for its implementation to be correct

Metadata

Metadata

Assignees

No one assigned

    Labels

    BlockerBlocking issue or pull request for an upcoming releaseNumeric OperationsArithmetic, Comparison, and Logical operationsRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions