Skip to content

TST: new test for incorrect series assignment #29378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pandas/tests/series/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,22 @@ def test_setslice(datetime_series):
assert sl.index.is_unique is True


def test_2d_to_1d_assignment_raises():
x = np.random.randn(2, 2)
y = pd.Series(range(2))

msg = (
r"shape mismatch: value array of shape \(2,2\) could not be"
r" broadcast to indexing result of shape \(2,\)"
)
with pytest.raises(ValueError, match=msg):
y.loc[range(2)] = x

msg = r"could not broadcast input array from shape \(2,2\) into shape \(2\)"
with pytest.raises(ValueError, match=msg):
y.loc[:] = x


# FutureWarning from NumPy about [slice(None, 5).
@pytest.mark.filterwarnings("ignore:Using a non-tuple:FutureWarning")
def test_basic_getitem_setitem_corner(datetime_series):
Expand Down