Skip to content

BUG: __rmatmul__ error handling #21581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
minggli opened this issue Jun 21, 2018 · 1 comment · Fixed by #36792
Closed

BUG: __rmatmul__ error handling #21581

minggli opened this issue Jun 21, 2018 · 1 comment · Fixed by #36792
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Milestone

Comments

@minggli
Copy link
Contributor

minggli commented Jun 21, 2018

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

@gfyoung gfyoung added Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff Bug labels Jun 22, 2018
@gfyoung
Copy link
Member

gfyoung commented Jun 22, 2018

xref #21530 #21578 (blocked by this it seems based on #21578 (comment))

cc @jreback

@jbrockmendel jbrockmendel added the Numeric Operations Arithmetic, Comparison, and Logical operations label Aug 3, 2019
@mroeschke mroeschke removed the Algos Non-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diff label May 13, 2020
@jreback jreback added this to the 1.2 milestone Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants