Skip to content

Commit

Permalink
BUG: Incorrect index label displayed on MultiIndex DataFrame
Browse files Browse the repository at this point in the history
closes #14882
closes #14975
  • Loading branch information
Dr-Irv authored and jreback committed Jan 21, 2017
1 parent 2540d5a commit 2fa33fb
Show file tree
Hide file tree
Showing 3 changed files with 576 additions and 3 deletions.
10 changes: 10 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,14 @@ Bug Fixes

- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
- Bug in ``pd.pivot_table()`` where no error was raised when values argument was not in the columns (:issue:`14938`)

- Bug in ``.to_json()`` where ``lines=True`` and contents (keys or values) contain escaped characters (:issue:`15096`)

- Bug in ``DataFrame.groupby().describe()`` when grouping on ``Index`` containing tuples (:issue:`14848`)
- Bug in creating a ``MultiIndex`` with tuples and not passing a list of names; this will now raise ``ValueError`` (:issue:`15110`)

- Bug in catching an overflow in ``Timestamp`` + ``Timedelta/Offset`` operations (:issue:`15126`)
- Bug in the HTML display with with a ``MultiIndex`` and truncation (:issue:`14882`)


- Bug in ``pd.merge_asof()`` where ``left_index``/``right_index`` together caused a failure when ``tolerance`` was specified (:issue:`15135`)
Expand All @@ -445,4 +447,12 @@ Bug Fixes

- Bug in ``pd.read_csv()`` with ``float_precision='round_trip'`` which caused a segfault when a text entry is parsed (:issue:`15140`)









- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)
21 changes: 18 additions & 3 deletions pandas/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,16 +1248,25 @@ def _write_hierarchical_rows(self, fmt_values, indent):
# Insert ... row and adjust idx_values and
# level_lengths to take this into account.
ins_row = self.fmt.tr_row_num
inserted = False
for lnum, records in enumerate(level_lengths):
rec_new = {}
for tag, span in list(records.items()):
if tag >= ins_row:
rec_new[tag + 1] = span
elif tag + span > ins_row:
rec_new[tag] = span + 1
dot_row = list(idx_values[ins_row - 1])
dot_row[-1] = u('...')
idx_values.insert(ins_row, tuple(dot_row))

# GH 14882 - Make sure insertion done once
if not inserted:
dot_row = list(idx_values[ins_row - 1])
dot_row[-1] = u('...')
idx_values.insert(ins_row, tuple(dot_row))
inserted = True
else:
dot_row = list(idx_values[ins_row])
dot_row[inner_lvl - lnum] = u('...')
idx_values[ins_row] = tuple(dot_row)
else:
rec_new[tag] = span
# If ins_row lies between tags, all cols idx cols
Expand All @@ -1267,6 +1276,12 @@ def _write_hierarchical_rows(self, fmt_values, indent):
if lnum == 0:
idx_values.insert(ins_row, tuple(
[u('...')] * len(level_lengths)))

# GH 14882 - Place ... in correct level
elif inserted:
dot_row = list(idx_values[ins_row])
dot_row[inner_lvl - lnum] = u('...')
idx_values[ins_row] = tuple(dot_row)
level_lengths[lnum] = rec_new

level_lengths[inner_lvl][ins_row] = 1
Expand Down
Loading

0 comments on commit 2fa33fb

Please sign in to comment.