@@ -130,34 +130,39 @@ Backwards incompatible API changes
130
130
131
131
.. _whatsnew_1000.api_breaking.MultiIndex._names :
132
132
133
- ``MultiIndex.levels `` do not hold level names any longer
134
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133
+ Avoid using names from ``MultiIndex.levels ``
134
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135
135
136
- - A :class: `MultiIndex ` previously stored the level names as attributes of each of its
137
- :attr: ` MultiIndex.levels `. From Pandas 1.0, the names are only accessed through
138
- :attr: `MultiIndex.names ` (which was also possible previously). This is done in order to
139
- make :attr: ` MultiIndex.levels ` more similar to :attr: ` CategoricalIndex.categories ` ( :issue: ` 27242 `:) .
136
+ As part of a larger refactor to :class: `MultiIndex ` the level names are now
137
+ stored separately from the levels ( :issue: ` 27242 `). We recommend using
138
+ :attr: `MultiIndex.names ` to access the names, and :meth: ` Index.set_names `
139
+ to update the names .
140
140
141
- * pandas 0.25.x *
141
+ For backwards compatibility, you can still * access * the names via the levels.
142
142
143
- .. code-block :: ipython
143
+ .. ipython :: python
144
144
145
- In [1]: mi = pd.MultiIndex.from_product([[1, 2], ['a', 'b']], names=['x', 'y'])
146
- Out[2]: mi
147
- MultiIndex([(1, 'a'),
148
- (1, 'b'),
149
- (2, 'a'),
150
- (2, 'b')],
151
- names=['x', 'y'])
152
- Out[3]: mi.levels[0].name
153
- 'x'
145
+ mi = pd.MultiIndex.from_product([[1 , 2 ], [' a' , ' b' ]], names = [' x' , ' y' ])
146
+ mi.levels[0 ].name
154
147
155
- *pandas 1.0.0 *
148
+ However, it is no longer possible to *update * the names of the ``MultiIndex ``
149
+ via the name of the level. The following will **silently ** fail to update the
150
+ name of the ``MultiIndex ``
156
151
157
152
.. ipython :: python
158
153
159
- mi = pd.MultiIndex.from_product([[1 , 2 ], [' a' , ' b' ]], names = [' x' , ' y' ])
160
- mi.levels[0 ].name
154
+ mi.levels[0 ].name = " new name"
155
+ mi.names
156
+
157
+ To update, use ``MultiIndex.set_names ``, which returns a new ``MultiIndex ``.
158
+
159
+ .. ipython :: python
160
+
161
+ mi2 = mi.set_names(" new name" , level = 0 )
162
+ mi2.names
163
+
164
+ New repr for :class: `pandas.core.arrays.IntervalArray `
165
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161
166
162
167
- :class: `pandas.core.arrays.IntervalArray ` adopts a new ``__repr__ `` in accordance with other array classes (:issue: `25022 `)
163
168
0 commit comments