question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected Broadcast error when diving string by float

See original GitHub issue

Code 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()

INSTALLED VERSIONS ------------------ commit: None python: 2.7.12.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 44 Stepping 2, GenuineIntel byteorder: little LC_ALL: None LANG: en

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:closed
  • Created 6 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gfyoungcommented, Jul 18, 2017
  1. It should not matter. I ran the code in IPython as well, and I can see both errors. It could be that your sys.tracebacklimit is too small for all the error messages to be displayed.

  2. I see you are using pandas 0.18.1. We are in fact now at 0.20.3 - perhaps the discrepancy is due to the fact that you have a very old pandas version. Could you try upgrading and see if that helps?

0reactions
gfyoungcommented, Jul 19, 2017

Closing as I can’t reproduce the issue. Please ping this issue again if it rears its head once more. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected exception being raised when trying to convert ...
When I input an integer, the error message is displayed correctly, as the conversion float() is possible. But, in case of a floating...
Read more >
Solved: Default Radeon WattMan settings has been restored
When I restart the cpu it says Default Radeon Wattman settings has been restored due to unexpected situation. I have increased the power...
Read more >
5 Most Common Floyd Rose Setup Issues Problems Solved
Problem 3 - Buzzing on the open string. Problem 4 - Sudden and complete loss os tuning. Problem 5 - Can't fine tune....
Read more >
What is an Integer Overflow Attack (with Examples)?
Integer overflow attacks exploit coding flaws and can have serious consequences. Learn about integer overflow attack examples in our guide.
Read more >
10 tricks for converting Data to a Numeric Type in Pandas
Otherwise, you may get unexpected results or errors. ... Converting string/int to int/float; Converting float to int; Converting a column of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found