Skip to content

Commit 82bf940

Browse files
committed
BUG: GH14882 Incorrect index label displayed on MultiIndex DataFrame
1 parent 8b497e4 commit 82bf940

File tree

3 files changed

+568
-3
lines changed

3 files changed

+568
-3
lines changed

doc/source/whatsnew/v0.20.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,5 @@ Bug Fixes
300300
- Bug in ``Series.unique()`` in which unsigned 64-bit integers were causing overflow (:issue:`14721`)
301301
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
302302
- Bug in converting object elements of array-like objects to unsigned 64-bit integers (:issue:`4471`)
303+
- Bug in HTML display with MultiIndex and truncation (:issue:`14882`)
304+

pandas/formats/format.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -1248,16 +1248,25 @@ def _write_hierarchical_rows(self, fmt_values, indent):
12481248
# Insert ... row and adjust idx_values and
12491249
# level_lengths to take this into account.
12501250
ins_row = self.fmt.tr_row_num
1251+
inserted = False
12511252
for lnum, records in enumerate(level_lengths):
12521253
rec_new = {}
12531254
for tag, span in list(records.items()):
12541255
if tag >= ins_row:
12551256
rec_new[tag + 1] = span
12561257
elif tag + span > ins_row:
12571258
rec_new[tag] = span + 1
1258-
dot_row = list(idx_values[ins_row - 1])
1259-
dot_row[-1] = u('...')
1260-
idx_values.insert(ins_row, tuple(dot_row))
1259+
1260+
# GH 14882 - Make sure insertion done once
1261+
if not inserted:
1262+
dot_row = list(idx_values[ins_row - 1])
1263+
dot_row[-1] = u('...')
1264+
idx_values.insert(ins_row, tuple(dot_row))
1265+
inserted = True
1266+
else:
1267+
dot_row = list(idx_values[ins_row])
1268+
dot_row[inner_lvl - lnum] = u('...')
1269+
idx_values[ins_row] = tuple(dot_row)
12611270
else:
12621271
rec_new[tag] = span
12631272
# If ins_row lies between tags, all cols idx cols
@@ -1267,6 +1276,12 @@ def _write_hierarchical_rows(self, fmt_values, indent):
12671276
if lnum == 0:
12681277
idx_values.insert(ins_row, tuple(
12691278
[u('...')] * len(level_lengths)))
1279+
1280+
# GH 14882 - Place ... in correct level
1281+
elif inserted:
1282+
dot_row = list(idx_values[ins_row])
1283+
dot_row[inner_lvl - lnum] = u('...')
1284+
idx_values[ins_row] = tuple(dot_row)
12701285
level_lengths[lnum] = rec_new
12711286

12721287
level_lengths[inner_lvl][ins_row] = 1

0 commit comments

Comments
 (0)