-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: GH #12223, GH #15262. Allow ints for names in MultiIndex #15478
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,11 +185,12 @@ Other enhancements | |
- ``Series/DataFrame.asfreq()`` have gained a ``fill_value`` parameter, to fill missing values (:issue:`3715`). | ||
- ``Series/DataFrame.resample.asfreq`` have gained a ``fill_value`` parameter, to fill missing values during resampling (:issue:`3715`). | ||
- ``pandas.tools.hashing`` has gained a ``hash_tuples`` routine, and ``hash_pandas_object`` has gained the ability to hash a ``MultiIndex`` (:issue:`15224`) | ||
- ``Series/DataFrame.squeeze()`` have gained the ``axis`` parameter. (:issue:`15339`) | ||
- ``Series/DataFrame.squeeze()`` have gained the ``axis`` parameter. (:issue:`15339`)<<<<<<< f4edb053e17e51e8c2bed7c16755c4f7f3222117 | ||
- ``DataFrame.to_excel()`` has a new ``freeze_panes`` parameter to turn on Freeze Panes when exporting to Excel (:issue:`15160`) | ||
- HTML table output skips ``colspan`` or ``rowspan`` attribute if equal to 1. (:issue:`15403`) | ||
- ``pd.TimedeltaIndex`` now has a custom datetick formatter specifically designed for nanosecond level precision (:issue:`8711`) | ||
- ``pd.types.concat.union_categoricals`` gained the ``ignore_ordered`` argument to allow ignoring the ordered attribute of unioned categoricals (:issue:`13410`). See the :ref:`categorical union docs <categorical.union>` for more information. | ||
- Using numerical names in ``MultiIndex`` causes less errors. (:issue:`12223`) (:issue:`15262`) | ||
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. say instead about the bug report about output formatting with a MI under certain conditions. 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.
|
||
|
||
.. _ISO 8601 duration: https://en.wikipedia.org/wiki/ISO_8601#Durations | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2352,6 +2352,11 @@ def get_level_values(self, level): | |
self._validate_index_level(level) | ||
return self | ||
|
||
def _get_level_values(self, num): | ||
# Used to mirror implementation for MultiIndex | ||
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. better to add an actual doc-string |
||
# GH #10461 | ||
return self.get_level_values(num) | ||
|
||
_index_shared_docs['get_indexer'] = """ | ||
Compute indexer and mask for new index given the current index. The | ||
indexer should be then used as an input to ndarray.take to align the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -846,7 +846,7 @@ def _try_mi(k): | |
|
||
raise InvalidIndexError(key) | ||
|
||
def _get_level_values(self, level): | ||
def _get_level_values(self, level, copy=True): | ||
""" | ||
Return vector of label values for requested level, | ||
equal to the length of the index | ||
|
@@ -856,6 +856,7 @@ def _get_level_values(self, level): | |
Parameters | ||
---------- | ||
level : int level | ||
copy : bool whether copy of results should be done | ||
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. why are you adding this? this is a whole different ball game. 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. @jreback What I needed When I first looked at this, there was no 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. still its not clear why you would actually be making this change, it just adds too much complexity. show an example of why you think you need it (or simply take it out) 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. @jreback I'll try an alternate implementation and let you review that. |
||
|
||
Returns | ||
------- | ||
|
@@ -866,7 +867,11 @@ def _get_level_values(self, level): | |
labels = self.labels[level] | ||
filled = algos.take_1d(unique._values, labels, | ||
fill_value=unique._na_value) | ||
return filled | ||
if copy: | ||
values = unique._shallow_copy(filled) | ||
else: | ||
values = filled | ||
return values | ||
|
||
def get_level_values(self, level): | ||
""" | ||
|
@@ -882,7 +887,7 @@ def get_level_values(self, level): | |
values : Index | ||
""" | ||
level = self._get_level_number(level) | ||
values = self._get_level_values(level) | ||
values = self._get_level_values(level, copy=False) | ||
return self.levels[level]._shallow_copy(values) | ||
|
||
def format(self, space=2, sparsify=None, adjoin=True, names=False, | ||
|
@@ -966,7 +971,8 @@ def to_frame(self, index=True): | |
""" | ||
|
||
from pandas import DataFrame | ||
result = DataFrame({(name or level): self.get_level_values(level) | ||
result = DataFrame({(name or level): | ||
self._get_level_values(level) | ||
for name, level in | ||
zip(self.names, range(len(self.levels)))}, | ||
copy=False) | ||
|
@@ -1301,8 +1307,8 @@ def append(self, other): | |
for o in other): | ||
arrays = [] | ||
for i in range(self.nlevels): | ||
label = self.get_level_values(i) | ||
appended = [o.get_level_values(i) for o in other] | ||
label = self._get_level_values(i) | ||
appended = [o._get_level_values(i) for o in other] | ||
arrays.append(label.append(appended)) | ||
return MultiIndex.from_arrays(arrays, names=self.names) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge residual :>