Unexpected Broadcast error when diving string by float
See original GitHub issueCode Sample, a copy-pastable example if possible
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.rand(10,3))
df['col'] = 'A'
df.div(df.iloc[:, 0], axis = 0)
Problem description
This throws the following error:
Traceback (most recent call last):
File "<ipython-input-22-b922d0177cba>", line 5, in <module>
df.div(df.iloc[:, 0], axis = 0)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\ops.py", line 1062, in f
return self._combine_series(other, na_op, fill_value, axis, level)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\frame.py", line 3510, in _combine_series
fill_value=fill_value)
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\frame.py", line 3535, in _combine_match_index
return self._constructor(func(left.values.T, right.values).T,
File "C:\Users\flabriol\AppData\Local\Continuum\Anaconda2\lib\site-packages\pandas\core\ops.py", line 993, in na_op
mask = notnull(xrav) & notnull(yrav)
**ValueError: operands could not be broadcast together with shapes (40,) (10,)**
Expected Output
I had hard time understanding this error has nothing to do with the shape of the columns but with their dtypes.
Probably a TypeError like TypeError: Could not operate 1.0 with block values unsupported operand type(s) for /: 'str' and 'float'
would have been better
Output of pd.show_versions()
pandas: 0.18.1 nose: 1.3.7 pip: 9.0.1 setuptools: 27.2.0 Cython: 0.25.2 numpy: 1.11.1 scipy: 0.17.1 statsmodels: None xarray: None IPython: 4.2.0 sphinx: 1.4.1 patsy: 0.4.1 dateutil: 2.5.3 pytz: 2016.4 blosc: 1.4.4 bottleneck: 1.1.0 tables: 3.2.2 numexpr: 2.6.0 matplotlib: 2.0.0 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.2 lxml: 3.6.0 bs4: 4.4.1 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.0.13 pymysql: None psycopg2: None jinja2: 2.8 boto: 2.40.0 pandas_datareader: None
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
It should not matter. I ran the code in
IPython
as well, and I can see both errors. It could be that yoursys.tracebacklimit
is too small for all the error messages to be displayed.I see you are using
pandas
0.18.1. We are in fact now at0.20.3
- perhaps the discrepancy is due to the fact that you have a very oldpandas
version. Could you try upgrading and see if that helps?Closing as I can’t reproduce the issue. Please ping this issue again if it rears its head once more. Thanks!