Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4569,6 +4569,8 @@ def drop(
axis_name = self._get_axis_name(axis)
axes = {axis_name: labels}
elif index is not None or columns is not None:
if axis == 1 and index is not None:
raise ValueError("Cannot specify both 'axis' and 'index'")
axes = {"index": index}
if self.ndim == 2:
axes["columns"] = columns
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/methods/test_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ def test_drop_multiindex_other_level_nan(self):
)
tm.assert_frame_equal(result, expected)

def test_drop_multiindex_with_axis_and_index(self):
df = DataFrame({"a": [1, 2, 3], "b": ["foo", "foo", "bar"]})
df = pd.concat([df], keys=["foo"], axis=1)
msg = "Cannot specify both 'axis' and 'index'"
with pytest.raises(ValueError, match=msg):
df.drop(index="b", level=1, axis=1)

def test_drop_nonunique(self):
df = DataFrame(
[
Expand Down
Loading