Skip to content

Commit

Permalink
fix for empty result set
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterprovoost committed Oct 4, 2023
1 parent 3aa02fe commit b115ebe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
@app.get("/search")
async def search(sequence: str = None):
results = search_sequences(sequence if sequence is not None else default_sequence)
df = pd.DataFrame.from_records(results).groupby(["as", "dataset_id", "phylum", "class", "order", "family", "genus", "scientificname"]).agg({"count": "sum"}).sort_values(by="as", ascending=False).reset_index()
table = list(df.T.to_dict().values())
if len(results) > 0:
df = pd.DataFrame.from_records(results).groupby(["as", "dataset_id", "phylum", "class", "order", "family", "genus", "scientificname"]).agg({"count": "sum"}).sort_values(by="as", ascending=False).reset_index()
table = list(df.T.to_dict().values())
else:
table = []
return {
"results": results,
"table": table
Expand Down

0 comments on commit b115ebe

Please sign in to comment.