Skip to content

2D assignment does not reshape correctly #2537

@vnlitvinov

Description

@vnlitvinov

Describe the problem

Seems #318 is broken again.

Source code / logs

import modin.pandas as pd
import numpy as np
df = pd.DataFrame({'a': [1,2], 'b':[3,4]})
df.loc[df['a'] > 1, 'b'] = np.log(df['b'])
print(df)

raises:

Traceback (most recent call last):
  File "c:\foo\modin\pandas\indexing.py", line 407, in _broadcast_item
    return np.broadcast_to(item, to_shape)
  File "<__array_function__ internals>", line 6, in broadcast_to
  File "C:\miniconda3\envs\foo\lib\site-packages\numpy\lib\stride_tricks.py", line 182, in broadcast_to
    return _broadcast_to(array, shape, subok=subok, readonly=True)
  File "C:\miniconda3\envs\foo\lib\site-packages\numpy\lib\stride_tricks.py", line 127, in _broadcast_to
    op_flags=['readonly'], itershape=shape, order='C')
ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (2,) and requested shape (1,1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\foo\modin\pandas\indexing.py", line 609, in __setitem__
    row_lookup, col_lookup, row_scaler, col_scaler
  File "c:\foo\modin\pandas\indexing.py", line 360, in __setitem__
    item = self._broadcast_item(row_lookup, col_lookup, item, to_shape)
  File "c:\foo\modin\pandas\indexing.py", line 412, in _broadcast_item
    "{to_shape}".format(from_shape=from_shape, to_shape=to_shape)
ValueError: could not broadcast input array from shape (2,) into shape (1, 1)

Expected output (as Pandas show it):

   a         b
0  1  3.000000
1  2  1.386294

Metadata

Metadata

Assignees

No one assigned

    Labels

    Regression ↩️Something that used to work but doesn't anymorebug 🦗Something isn't workingpandas concordance 🐼Functionality that does not match pandaspandas.dataframeRelated to pandas.dataframe module

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions