Skip to content

Mixed-dtype dataframe comparison with array raises incorrectly #20090

@jbrockmendel

Description

@jbrockmendel

This came up while going through some of statsmodels tests:

arr = np.random.randn(3, 2)
arr[:, 0] = [1, 2, 3]
df = pd.DataFrame(arr)
df[0] = df[0].astype(int)
>>> df == arr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pandas/core/ops.py", line 1572, in f
    try_cast=False)
  File "pandas/core/frame.py", line 4021, in _combine_const
    try_cast=try_cast)
  File "pandas/core/internals.py", line 3644, in eval
    return self.apply('eval', **kwargs)
  File "pandas/core/internals.py", line 3538, in apply
    applied = getattr(b, f)(**kwargs)
  File "pandas/core/internals.py", line 1348, in eval
    t_shape=values.T.shape, oth_shape=other.shape))
ValueError: cannot broadcast shape [(3, 1)] with block values [(3, 2)]

I'd expect this to wrap the ndarray in a frame and return an all-True frame.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Numeric OperationsArithmetic, Comparison, and Logical operationsReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions