Closed
Description
df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': ['111', '222', '333']})
df.loc[df.b.isnull(), 'a'] = df.b
The filtering condition is always false (b is never null) and the above code produces this error:
Array is not broadcastable to correct shape
.
If, however, I change the type for column 'c' - which is not even mentioned in the assignment expression (!) - from str to int,
df = pd.DataFrame({'a': ['1', '2', '3'],
'b': ['11', '22', '33'],
'c': [111, 222, 333]}) # Type changed to int
df.loc[df.b.isnull(), 'a'] = df.b
No errors are produced.
Would be nice to have consistent behaviour and not have any errors - could not find anything in the documentation saying that applying .loc on empty filter is considered illegal?