Skip to content

Commit 2415e46

Browse files
committed
Cleaned up test cases
1 parent b66e9e2 commit 2415e46

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,10 +1147,10 @@ def rename(
11471147
if mapper is None and index is None and columns is None:
11481148
raise TypeError("must pass an index to rename")
11491149

1150-
if (index or columns):
1150+
if (index is not None or columns is not None):
11511151
if axis is not None:
11521152
raise TypeError("Cannot specify both 'axis' and any of 'index' or 'columns'")
1153-
elif mapper:
1153+
elif mapper is not None:
11541154
raise TypeError("Cannot specify both 'mapper' and any of 'index' or 'columns'")
11551155
else:
11561156
# use the mapper argument

pandas/tests/frame/test_alter_axes.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,11 +1358,42 @@ def test_reindex_api_equivalence(self):
13581358
tm.assert_frame_equal(res1, res)
13591359

13601360
def test_rename_positional_raises(self):
1361+
# GH 29136
13611362
df = DataFrame(columns=["A", "B"])
13621363
msg = r"rename\(\) takes from 1 to 2 positional arguments"
1364+
13631365
with pytest.raises(TypeError, match=msg):
13641366
df.rename(None, str.lower)
13651367

1368+
def test_rename_no_mappings_raises(self):
1369+
# GH 29136
1370+
df = DataFrame([[1]])
1371+
msg = "must pass an index to rename"
1372+
with pytest.raises(TypeError, match=msg):
1373+
df.rename()
1374+
1375+
with pytest.raises(TypeError, match=msg):
1376+
df.rename(None, index=None)
1377+
1378+
with pytest.raises(TypeError, match=msg):
1379+
df.rename(None, columns=None)
1380+
1381+
with pytest.raises(TypeError, match=msg):
1382+
df.rename(None, columns=None, index=None)
1383+
1384+
def test_rename_mapper_and_positional_arguments_raises(self):
1385+
# GH 29136
1386+
df = DataFrame([[1]])
1387+
msg = "Cannot specify both 'mapper' and any of 'index' or 'columns'"
1388+
with pytest.raises(TypeError, match=msg):
1389+
df.rename({}, index={})
1390+
1391+
with pytest.raises(TypeError, match=msg):
1392+
df.rename({}, columns={})
1393+
1394+
with pytest.raises(TypeError, match=msg):
1395+
df.rename({}, columns={}, index={})
1396+
13661397
def test_assign_columns(self, float_frame):
13671398
float_frame["hi"] = "there"
13681399

0 commit comments

Comments
 (0)