Skip to content

REF: prelims for single-path setitem_with_indexer #37588

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 1 commit into from
Nov 2, 2020
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
8 changes: 7 additions & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,11 @@ def _setitem_with_indexer(self, indexer, value):
return

# add a new item with the dtype setup
self.obj[key] = infer_fill_value(value)
if com.is_null_slice(indexer[0]):
# We are setting an entire column
self.obj[key] = value
else:
self.obj[key] = infer_fill_value(value)

new_indexer = convert_from_missing_indexer_tuple(
indexer, self.obj.axes
Expand Down Expand Up @@ -1641,6 +1645,8 @@ def _setitem_with_indexer_split_path(self, indexer, value):

if not isinstance(indexer, tuple):
indexer = _tuplify(self.ndim, indexer)
if len(indexer) > self.ndim:
raise IndexError("too many indices for array")

if isinstance(value, ABCSeries):
value = self._align_series(indexer, value)
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ def test_setitem_ndarray_3d(self, index, obj, idxr, idxr_id):
idxr = idxr(obj)
nd3 = np.random.randint(5, size=(2, 2, 2))

if (len(index) == 0) and (idxr_id == "iloc") and isinstance(obj, pd.DataFrame):
# gh-32896
pytest.skip("This is currently failing. There's an xfailed test below.")

if idxr_id == "iloc":
err = ValueError
msg = f"Cannot set values with ndim > {obj.ndim}"
Expand All @@ -140,7 +136,6 @@ def test_setitem_ndarray_3d(self, index, obj, idxr, idxr_id):
idxr[nd3] = 0

def test_setitem_ndarray_3d_does_not_fail_for_iloc_empty_dataframe(self):
# when fixing this, please remove the pytest.skip in test_setitem_ndarray_3d
i = Index([])
obj = DataFrame(np.random.randn(len(i), len(i)), index=i, columns=i)
nd3 = np.random.randint(5, size=(2, 2, 2))
Expand Down