diff --git a/api/main.py b/api/main.py index 67db7d9..3f32ad2 100644 --- a/api/main.py +++ b/api/main.py @@ -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