Skip to content

Commit

Permalink
feat: correctly handle dataframes passed as dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirman committed Nov 12, 2024
1 parent 8cf566d commit bb1c876
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/aind_qc_portal/panel/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,19 @@ def metric_panel(self):
value_widget = pn.pane.DataFrame(df)
auto_value = True
elif isinstance(value, dict):
try:
custom_value = CustomMetricValue(value, self._set_value, self._set_status)
auto_value = True
auto_state = custom_value.auto_state
value_widget = custom_value.panel
except ValueError as e:
print(e)
value_widget = pn.widgets.JSONEditor(name=name)
# first, check if every key/value pair has the same length, if so coerce to a dataframe
if all([len(v) == len(value[list(value.keys())[0]]) for v in value.values()]):
df = pd.DataFrame(value)
value_widget = pn.pane.DataFrame(df)
else:
try:
custom_value = CustomMetricValue(value, self._set_value, self._set_status)
auto_value = True
auto_state = custom_value.auto_state
value_widget = custom_value.panel
except ValueError as e:
print(e)
value_widget = pn.widgets.JSONEditor(name=name)
else:
value_widget = pn.pane(f"Can't deal with type {type(value)}")

Expand Down

0 comments on commit bb1c876

Please sign in to comment.