Skip to content

Commit 070830f

Browse files
committed
fix order
1 parent 52c6e9a commit 070830f

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

_unittests/ut_helpers/test_log_helper.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ def test_cube_logs_view(self):
130130
self.assertEqual((2, 6), view.shape)
131131
self.assertEqual(
132132
[
133-
("time_baseline", "export", "phi3"),
134-
("time_baseline", "export", "phi4"),
135-
("time_baseline", "onnx-dynamo", "phi4"),
136-
("time_latency", "export", "phi3"),
137-
("time_latency", "export", "phi4"),
138-
("time_latency", "onnx-dynamo", "phi4"),
133+
("time_baseline", "phi3", "export"),
134+
("time_baseline", "phi4", "export"),
135+
("time_baseline", "phi4", "onnx-dynamo"),
136+
("time_latency", "phi3", "export"),
137+
("time_latency", "phi4", "export"),
138+
("time_latency", "phi4", "onnx-dynamo"),
139139
],
140140
list(view.columns),
141141
)

onnx_diagnostic/helpers/log_helper.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ def view(
605605
*[o for o in corder if o in key_columns],
606606
*[c for c in key_columns if c not in view_def.order],
607607
]
608+
else:
609+
corder = None
610+
608611
if view_def.dropna:
609612
data, key_index, key_columns, values = self._dropna( # type: ignore[assignment]
610613
data,
@@ -666,10 +669,30 @@ def view(
666669
if isinstance(piv, pandas.Series):
667670
piv = piv.to_frame("VALUE")
668671
piv.sort_index(inplace=True)
672+
673+
if isinstance(piv.columns, pandas.MultiIndex):
674+
if corder:
675+
# reorder the levels for the columns with the view definition
676+
new_corder = [c for c in corder if c in piv.columns.names]
677+
new_names = [
678+
*[c for c in piv.columns.names if c not in new_corder],
679+
*new_corder,
680+
]
681+
piv.columns = piv.columns.reorder_levels(new_names)
682+
elif self.time in piv.columns.names:
683+
# put time at the end
684+
new_names = list(piv.columns.names)
685+
ind = new_names.index(self.time)
686+
if ind < len(new_names) - 1:
687+
del new_names[ind]
688+
new_names.append(self.time)
689+
piv.columns = piv.columns.reorder_levels(new_names)
690+
669691
if view_def.no_index:
670692
piv = piv.reset_index(drop=False)
671693
else:
672694
piv.sort_index(inplace=True, axis=1)
695+
673696
if verbose:
674697
print(f"[CubeLogs.view] levels {piv.index.names}, {piv.columns.names}")
675698
print(f"[CubeLogs.view] -- done view {view_def.name!r}")

0 commit comments

Comments
 (0)