Skip to content

Commit 2fa33fb

Browse files
Dr-Irvjreback
authored andcommitted
BUG: Incorrect index label displayed on MultiIndex DataFrame
closes #14882 closes #14975
1 parent 2540d5a commit 2fa33fb

File tree

3 files changed

+576
-3
lines changed

3 files changed

+576
-3
lines changed

doc/source/whatsnew/v0.20.0.txt

+10
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,14 @@ Bug Fixes
421421

422422
- Require at least 0.23 version of cython to avoid problems with character encodings (:issue:`14699`)
423423
- Bug in ``pd.pivot_table()`` where no error was raised when values argument was not in the columns (:issue:`14938`)
424+
424425
- Bug in ``.to_json()`` where ``lines=True`` and contents (keys or values) contain escaped characters (:issue:`15096`)
425426

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

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

431433

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

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

450+
451+
452+
453+
454+
455+
456+
457+
448458
- Bug in ``DataFrame.boxplot`` where ``fontsize`` was not applied to the tick labels on both axes (:issue:`15108`)

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)