Skip to content

Commit ea7c93a

Browse files
committed
Update doc-string in .rename
1 parent 2a2d1cf commit ea7c93a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pandas/core/indexes/base.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,17 +1340,39 @@ def set_names(self, names, level=None, inplace=False):
13401340
def rename(self, name, inplace=False):
13411341
"""
13421342
Set new names on index. Defaults to returning new index.
1343+
Length of names must match number of levels in MultiIndex.
13431344
13441345
Parameters
13451346
----------
1346-
name : str or list
1347-
name to set
1347+
name : str or sequence
1348+
name(s) to set
13481349
inplace : bool
13491350
if True, mutates in place
13501351
13511352
Returns
13521353
-------
13531354
new index (of same type and class...etc) [if inplace, returns None]
1355+
1356+
Examples
1357+
-------
1358+
>>> idx = Index([1, 2, 3, 4], name = 'foo')
1359+
Int64Index([1, 2, 3, 4], dtype='int64', name='foo')
1360+
>>> idx.rename('bar')
1361+
Int64Index([1, 2, 3, 4], dtype='int64', name='bar')
1362+
>>> idx = MultiIndex.from_tuples([(1, u'one'), (1, u'two'),
1363+
(2, u'one'), (2, u'two')],
1364+
names=['foo', 'bar'])
1365+
>>> idx.rename(['bar', None], inplace=True)
1366+
>>> idx
1367+
MultiIndex(levels=[[1, 2], ['one', 'two']],
1368+
labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
1369+
names=['bar', None])
1370+
>>> idx.rename(['bar'])
1371+
ValueError: Length of names must match number of levels in MultiIndex.
1372+
1373+
See also
1374+
--------
1375+
set_names : able to set new names partially and by level
13541376
"""
13551377
return self.set_names([name], inplace=inplace)
13561378

0 commit comments

Comments
 (0)