Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ def _ensure_listlike_indexer(self, key, axis=None, value=None):
if k not in self.obj:
if value is None:
self.obj[k] = np.nan
elif is_array_like(value) and value.ndim == 2:
# GH#37964 have to select columnwise in case of array
self.obj[k] = value[:, i]
elif is_list_like(value):
self.obj[k] = value[i]
else:
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/frame/indexing/test_setitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,21 @@ def test_setitem_periodindex(self):
assert isinstance(rs.index, PeriodIndex)
tm.assert_index_equal(rs.index, rng)

def test_setitem_complete_column_with_array(self):
# GH#37954
df = DataFrame({"a": ["one", "two", "three"], "b": [1, 2, 3]})
arr = np.array([[1, 1], [3, 1], [5, 1]])
df[["c", "d"]] = arr
expected = DataFrame(
{
"a": ["one", "two", "three"],
"b": [1, 2, 3],
"c": [1, 3, 5],
"d": [1, 1, 1],
}
)
tm.assert_frame_equal(df, expected)


class TestDataFrameSetItemSlicing:
def test_setitem_slice_position(self):
Expand Down