Skip to content

Commit 4193223

Browse files
Saba9gradio-pr-botabidlabs
authored
fix: table slider crash (#434)
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Abubakar Abid <islamrealm@gmail.com>
1 parent 3a2d11d commit 4193223

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

.changeset/tender-dryers-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trackio": minor
3+
---
4+
5+
feat:fix: table slider crash

trackio/ui/media_page.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def extract_media(logs: list[dict]) -> dict[str, list[MediaData]]:
4646
return media_by_key
4747

4848

49+
def is_table(value) -> bool:
50+
return isinstance(value, dict) and value.get("_type") == Table.TYPE
51+
52+
4953
def refresh_runs_dropdown(project: str | None):
5054
if project is None:
5155
runs: list[str] = []
@@ -102,13 +106,7 @@ def display_media_and_tables(project: str | None, selected_run: str | None):
102106

103107
table_cols = df.select_dtypes(include="object").columns
104108
table_cols = [c for c in table_cols if c not in utils.RESERVED_KEYS]
105-
table_cols = [
106-
c
107-
for c in table_cols
108-
if not (metric_df := df.dropna(subset=[c])).empty
109-
and isinstance(first_value := metric_df[c].iloc[0], dict)
110-
and first_value.get("_type") == Table.TYPE
111-
]
109+
table_cols = [c for c in table_cols if any(is_table(x) for x in df[c])]
112110
has_tables = len(table_cols) > 0
113111

114112
if not has_media and not has_tables:
@@ -169,7 +167,7 @@ def display_media_and_tables(project: str | None, selected_run: str | None):
169167
with gr.Accordion(f"Tables ({len(table_cols)})", open=True):
170168
with gr.Row(key="row"):
171169
for metric_idx, metric_name in enumerate(table_cols):
172-
metric_df = df.dropna(subset=[metric_name])
170+
metric_df = df[df[metric_name].apply(is_table)]
173171
if not metric_df.empty:
174172
value = metric_df[metric_name]
175173
first_value = value.iloc[0]
@@ -202,16 +200,27 @@ def display_media_and_tables(project: str | None, selected_run: str | None):
202200
preserved_by_key=None,
203201
)
204202

205-
def get_table_at_index(index: int):
206-
value = metric_df[metric_name]
207-
processed_data = Table.to_display_format(
208-
value.iloc[index - 1]["_value"]
209-
)
210-
df_ = pd.DataFrame(processed_data)
211-
return gr.DataFrame(
212-
df_,
213-
label=f"{metric_name} (index {index})",
214-
)
203+
def make_table_renderer(
204+
capture_df, capture_name
205+
):
206+
def get_table_at_index(index: int):
207+
value = capture_df[capture_name]
208+
processed_data = (
209+
Table.to_display_format(
210+
value.iloc[index - 1]["_value"]
211+
)
212+
)
213+
df_ = pd.DataFrame(processed_data)
214+
return gr.DataFrame(
215+
df_,
216+
label=f"{capture_name} (index {index})",
217+
)
218+
219+
return get_table_at_index
220+
221+
get_table_at_index = make_table_renderer(
222+
metric_df, metric_name
223+
)
215224

216225
s.input(
217226
get_table_at_index,

0 commit comments

Comments
 (0)