-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Separate MultiIndex names from levels #27242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,37 @@ source, you should no longer need to install Cython into your build environment | |
Backwards incompatible API changes | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
- :class:`pandas.core.groupby.GroupBy.transform` now raises on invalid operation names (:issue:`27489`). | ||
.. _whatsnew_1000.api_breaking.MultiIndex._names: | ||
|
||
``MultiIndex.levels`` do not hold level names any longer | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
- A :class:`MultiIndex` previously stored the level names as attributes of each of its | ||
:attr:`MultiIndex.levels`. From Pandas 1.0, the names are only accessed through | ||
:attr:`MultiIndex.names` (which was also possible previously). This is done in order to | ||
make :attr:`MultiIndex.levels` more similar to :attr:`CategoricalIndex.categories` (:issue:`27242`:). | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can u show the previous way in a code block and the new way in an ipython block |
||
*pandas 0.25.x* | ||
|
||
.. code-block:: ipython | ||
|
||
In [1]: mi = pd.MultiIndex.from_product([[1, 2], ['a', 'b']], names=['x', 'y']) | ||
Out[2]: mi | ||
MultiIndex([(1, 'a'), | ||
(1, 'b'), | ||
(2, 'a'), | ||
(2, 'b')], | ||
names=['x', 'y']) | ||
Out[3]: mi.levels[0].name | ||
'x' | ||
|
||
*pandas 1.0.0* | ||
|
||
.. ipython:: python | ||
|
||
mi = pd.MultiIndex.from_product([[1, 2], ['a', 'b']], names=['x', 'y']) | ||
mi.levels[0].name | ||
|
||
- :class:`pandas.core.arrays.IntervalArray` adopts a new ``__repr__`` in accordance with other array classes (:issue:`25022`) | ||
|
||
*pandas 0.25.x* | ||
|
@@ -149,6 +179,7 @@ Backwards incompatible API changes | |
Other API changes | ||
^^^^^^^^^^^^^^^^^ | ||
|
||
- :class:`pandas.core.groupby.GroupBy.transform` now raises on invalid operation names (:issue:`27489`) | ||
- :meth:`pandas.api.types.infer_dtype` will now return "integer-na" for integer and ``np.nan`` mix (:issue:`27283`) | ||
- :meth:`MultiIndex.from_arrays` will no longer infer names from arrays if ``names=None`` is explicitly provided (:issue:`27292`) | ||
- In order to improve tab-completion, Pandas does not include most deprecated attributes when introspecting a pandas object using ``dir`` (e.g. ``dir(df)``). | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,10 +259,10 @@ def get_new_values(self): | |
def get_new_columns(self): | ||
if self.value_columns is None: | ||
if self.lift == 0: | ||
return self.removed_level | ||
return self.removed_level._shallow_copy(name=self.removed_name) | ||
|
||
lev = self.removed_level | ||
return lev.insert(0, lev._na_value) | ||
lev = self.removed_level.insert(0, item=self.removed_level._na_value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use .rename() |
||
return lev.rename(self.removed_name) | ||
|
||
stride = len(self.removed_level) + self.lift | ||
width = len(self.value_columns) | ||
|
@@ -298,10 +298,10 @@ def get_new_index(self): | |
|
||
# construct the new index | ||
if len(self.new_index_levels) == 1: | ||
lev, lab = self.new_index_levels[0], result_codes[0] | ||
if (lab == -1).any(): | ||
lev = lev.insert(len(lev), lev._na_value) | ||
return lev.take(lab) | ||
level, level_codes = self.new_index_levels[0], result_codes[0] | ||
if (level_codes == -1).any(): | ||
level = level.insert(len(level), level._na_value) | ||
return level.take(level_codes).rename(self.new_index_names[0]) | ||
|
||
return MultiIndex( | ||
levels=self.new_index_levels, | ||
|
@@ -661,7 +661,8 @@ def _convert_level_number(level_num, columns): | |
new_names = this.columns.names[:-1] | ||
new_columns = MultiIndex.from_tuples(unique_groups, names=new_names) | ||
else: | ||
new_columns = unique_groups = this.columns.levels[0] | ||
new_columns = this.columns.levels[0]._shallow_copy(name=this.columns.names[0]) | ||
unique_groups = new_columns | ||
|
||
# time to ravel the values | ||
new_data = {} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.