Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ def load_data(db):
exp_data["_id"] = exp_data["_id"].astype(str)
if "_id" in sim_data.columns:
sim_data["_id"] = sim_data["_id"].astype(str)
# Convert 'date' field from datetime object to string
if "date" in exp_data.columns:
exp_data["date"] = exp_data["date"].astype(str)
if "date" in sim_data.columns:
sim_data["date"] = sim_data["date"].astype(str)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be done with less code. Would this be equivalent?

# Store '_id', 'date' as string
for key in ["_id", "date"]:
    if key in exp_data.columns:
        exp_data[key] = exp_data[key].astype(str)
    if key in sim_data.columns:
        sim_data[key] = sim_data[key].astype(str)

return (exp_data, sim_data)


Expand Down Expand Up @@ -207,10 +212,18 @@ def hover_section(title, cols, hover_data):
if not cols:
return []
section = [f"<br><b>{title}</b>"]
section += [
f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}"
for col in cols
]
for col in cols:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves a previously existing issue, where the hover box would show date=NaN, because the code attempted to format a string (e.g. 2026-01-16 12:00:00) with .4g which is for numerical values (displaying them with 4 significant digits).

# Check if column is "date"
if col == "date":
# For string/date columns, use no format specifier (displays as-is)
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]}}"
)
else:
# Use numeric formatting for numeric columns
section.append(
f"{col}=%{{customdata[{hover_data.index(col)}]:.4g}}"
)
return section

# Determine which data is shown when hovering over the plot
Expand Down