Skip to content

Commit bd07d3a

Browse files
committed
update set_levels docstrings
1 parent 6f6d325 commit bd07d3a

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

pandas/core/indexes/multi.py

+3-35
Original file line numberDiff line numberDiff line change
@@ -739,18 +739,6 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True):
739739
"""
740740
Set new levels on MultiIndex. Defaults to returning new index.
741741
742-
``set_levels`` passes a new value for each index in the level,
743-
where the new values to be passed in each level are defined in
744-
a list. It is assumed that a new value is provided for each
745-
code describing values in the level.
746-
747-
If the number of values passed is more than the number of index
748-
values in the level, ``set_levels`` will still pass the values
749-
to the level. The passed values are stored in the FrozenList
750-
representing the levels attribute of the MultiIndex, even
751-
though the index values may be truncated in the MultiIndex
752-
output from set_levels.
753-
754742
Parameters
755743
----------
756744
levels : sequence or list of sequence
@@ -772,14 +760,6 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True):
772760
(2, 'one'), (2, 'two'),
773761
(3, 'one'), (3, 'two')],
774762
names=['foo', 'bar'])
775-
>>> idx
776-
MultiIndex([('1', one),
777-
('1', two),
778-
('2', one),
779-
('2', two),
780-
('3', one),
781-
('3', two)],
782-
names=['foo', 'bar'])
783763
>>> idx.set_levels([['a', 'b', 'c'], [1, 2]])
784764
MultiIndex([('a', 1),
785765
('a', 2),
@@ -805,22 +785,10 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True):
805785
(3, 'b')],
806786
names=['foo', 'bar'])
807787
808-
``set_levels()`` passes values into the levels attribute that
809-
is represented by a FrozenList containing list of values for
810-
each level in the MultiIndex, even when the number of values
811-
passed for a level is more than the number of indexes
812-
available in the MultiIndex itself.
788+
If any of the levels passed to ``set_levels()`` exceeds the
789+
existing length, all of the values from that argument will
790+
be stored though truncated in the MultiIndex output.
813791
814-
>>> idx.set_levels([['a', 'b', 'c'], [1, 2]], level=[0, 1])
815-
MultiIndex([('a', 1),
816-
('a', 2),
817-
('b', 1),
818-
('b', 2),
819-
('c', 1),
820-
('c', 2)],
821-
names=['foo', 'bar'])
822-
>>> idx.set_levels([['a', 'b', 'c'], [1, 2]], level=[0, 1]).levels
823-
FrozenList([['a', 'b', 'c'], [1, 2]])
824792
>>> idx.set_levels([['a', 'b', 'c'], [1, 2, 3, 4]], level=[0, 1])
825793
MultiIndex([('a', 1),
826794
('a', 2),

0 commit comments

Comments
 (0)