Skip to content

BUG: __rmatmul__ error handling #21581

Closed
@minggli

Description

@minggli

Code Sample, a copy-pastable example if possible

when dataframe.__rmatmul__ is triggered, the DataFrame.dot is called. However, the error message doesn't seem to align with numpy.

import numpy as np
from pandas import *

a = np.random.rand(10, 4)
b = np.random.rand(5, 3)

df = DataFrame(b)
# a.__matmul__ is called
a @ df

# df.__rmatmul__ is called
a.tolist() @ df

Problem description

>>> # a.__matmul__ is called
... a @ df
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ValueError: shapes (10,4) and (5,3) not aligned: 4 (dim 1) != 5 (dim 0)
>>>
>>> # df.__rmatmul__ is called
... a.tolist() @ df
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/mingli/GitHub/open/pandas/pandas/core/frame.py", line 901, in __rmatmul__
    return self.T.dot(np.transpose(other)).T
  File "/Users/mingli/GitHub/open/pandas/pandas/core/frame.py", line 879, in dot
    r=rvals.shape))
ValueError: Dot product shape mismatch, (3, 5) vs (4, 10)

Expected Output

ValueError: Dot product shape mismatch, (10, 4) vs (5, 3)

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: 7a74af7 python: 3.5.5.final.0 python-bits: 64 OS: Darwin OS-release: 17.4.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8

pandas: 0.24.0.dev0+147.g7a74af7ec
pytest: 3.6.1
pip: 10.0.1
setuptools: 28.8.0
Cython: 0.28.3
numpy: 1.14.5
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: 1.7.5
patsy: None
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNumeric OperationsArithmetic, Comparison, and Logical operations

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions