Skip to content

Commit

Permalink
Initialize empty columns for an empty DataFrame in job list page (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Apr 27, 2024
1 parent ec06baa commit a6ca843
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/aiidalab_qe/app/utils/search_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,22 @@ def load_data(self):
results = qb.all()

df = pd.DataFrame(results, columns=headers)
for index, row in df.iterrows():
df.at[index, "Creation time"] = row["ctime"].strftime("%Y-%m-%d %H:%M:%S")
df.at[index, "Delete"] = (
f"""<a href="./delete.ipynb?pk={row['PK']}" target="_blank">Delete</a>"""
# Check if DataFrame is not empty
if not df.empty:
df["Creation time"] = df["ctime"].apply(
lambda x: x.strftime("%Y-%m-%d %H:%M:%S")
)
df.at[index, "Inspect"] = (
f"""<a href="./qe.ipynb?pk={row['PK']}" target="_blank">Inspect</a>"""
df["Delete"] = df["PK"].apply(
lambda pk: f'<a href="./delete.ipynb?pk={pk}" target="_blank">Delete</a>'
)
df["Inspect"] = df["PK"].apply(
lambda pk: f'<a href="./qe.ipynb?pk={pk}" target="_blank">Inspect</a>'
)
else:
# Initialize empty columns for an empty DataFrame
df["Creation time"] = pd.Series(dtype="str")
df["Delete"] = pd.Series(dtype="str")
df["Inspect"] = pd.Series(dtype="str")
return df[
[
"PK",
Expand Down

0 comments on commit a6ca843

Please sign in to comment.