Skip to content

Commit 73a69f8

Browse files
committed
add incorrect series assignment
1 parent 0de9955 commit 73a69f8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/series/indexing/test_indexing.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ def test_setslice(datetime_series):
391391
assert sl.index.is_unique is True
392392

393393

394+
def test_incorrect_assigment():
395+
x = np.random.randn(2, 2)
396+
y = pd.Series(range(2))
397+
398+
msg = r"shape mismatch: value array of shape \(2,2\) could not be broadcast to indexing result of shape \(2,\)"
399+
with pytest.raises(ValueError, match=msg):
400+
y.loc[range(2)] = x
401+
402+
msg = r"could not broadcast input array from shape \(2,2\) into shape \(2\)"
403+
with pytest.raises(ValueError, match=msg):
404+
y.loc[:] = x
405+
406+
394407
# FutureWarning from NumPy about [slice(None, 5).
395408
@pytest.mark.filterwarnings("ignore:Using a non-tuple:FutureWarning")
396409
def test_basic_getitem_setitem_corner(datetime_series):

0 commit comments

Comments
 (0)