Skip to content

Commit e35841f

Browse files
ganevgvsimonjayhawkins
authored andcommitted
TST: new test for incorrect series assignment (#29378)
* add incorrect series assignment * add incorrect series assignment * passes git diff upstream * change test name * change name test Co-Authored-By: Simon Hawkins <[email protected]>
1 parent 7e6d509 commit e35841f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pandas/tests/series/indexing/test_indexing.py

+16
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,22 @@ def test_setslice(datetime_series):
391391
assert sl.index.is_unique is True
392392

393393

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

0 commit comments

Comments
 (0)