Skip to content

Commit 022c6f5

Browse files
KhemkaranKhemkaran
authored andcommitted
removed index check from the raise condition, axis==1 will suffice
1 parent 8bfa3eb commit 022c6f5

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4569,8 +4569,8 @@ def drop(
45694569
axis_name = self._get_axis_name(axis)
45704570
axes = {axis_name: labels}
45714571
elif index is not None or columns is not None:
4572-
if axis == 1 and index is not None:
4573-
raise ValueError("Cannot specify both 'axis' and 'index'")
4572+
if axis == 1:
4573+
raise ValueError("Cannot specify both 'axis' and 'index'/'columns'")
45744574
axes = {"index": index}
45754575
if self.ndim == 2:
45764576
axes["columns"] = columns

pandas/tests/frame/methods/test_drop.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,12 +346,11 @@ def test_drop_multiindex_other_level_nan(self):
346346
)
347347
tm.assert_frame_equal(result, expected)
348348

349-
def test_drop_multiindex_with_axis_and_index(self):
349+
def test_drop_with_both_axis_and_index(self):
350350
df = DataFrame({"a": [1, 2, 3], "b": ["foo", "foo", "bar"]})
351-
df = pd.concat([df], keys=["foo"], axis=1)
352-
msg = "Cannot specify both 'axis' and 'index'"
351+
msg = "Cannot specify both 'axis' and 'index'/'columns'"
353352
with pytest.raises(ValueError, match=msg):
354-
df.drop(index="b", level=1, axis=1)
353+
df.drop(index="b", axis=1)
355354

356355
def test_drop_nonunique(self):
357356
df = DataFrame(

0 commit comments

Comments
 (0)