Skip to content

Commit edfd8d1

Browse files
committed
fix mypy
1 parent 6f1b0ca commit edfd8d1

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/pyBiodatafuse/analyzer/explorer/patent.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"""
77

88
import time
9-
from typing import Literal
9+
from typing import Literal, Union
1010

1111
import pandas as pd
1212
import requests
1313
from tqdm import tqdm
14-
14+
import plotly.express as px
15+
import matplotlib.pyplot as plt
1516
from pyBiodatafuse.analyzer.utils import (
1617
plot_hbarplot_chart,
1718
plot_pie_chart,
@@ -104,15 +105,15 @@ def plot_patent_summary(
104105
fig_size: tuple = (10, 5),
105106
interactive: bool = True,
106107
plot_style: Literal["bar", "pie"] = "bar",
107-
) -> None:
108+
) -> Union[px.Figure, plt.Figure, str]:
108109
"""Plot patent summary data.
109110
110111
:param data_df: A dataframe with two columns: "label" and "value"
111112
:param compound_id: The compound identifier for the title
112113
:param fig_size: A tuple with the size of the figure
113114
:param interactive: Whether to create an interactive plotly plot or a static matplotlib plot
114-
:param plot_style: The style of the plot, either "bar" or "pie
115-
:returns: A bar plot
115+
:param plot_style: The style of the plot, either "bar" or "pie"
116+
:returns: A plotly or matplotlib plot depending on the interactive parameter
116117
"""
117118
if compound_id == "":
118119
return "Please provide a compound identifier for the title."
@@ -139,7 +140,7 @@ def plot_patent_summary(
139140
)
140141
fig.update_layout(title_text=f"Patent summary for {compound_id}", showlegend=True)
141142

142-
return fig.show()
143+
return fig
143144

144145
elif plot_style == "bar" and interactive:
145146
fig = plotly_barplot_chart(
@@ -151,7 +152,7 @@ def plot_patent_summary(
151152
)
152153
fig.update_layout(title_text=f"Patent summary for {compound_id}", showlegend=False)
153154

154-
return fig.show()
155+
return fig
155156

156157
elif plot_style == "pie" and not interactive:
157158
return plot_pie_chart(
@@ -168,3 +169,5 @@ def plot_patent_summary(
168169
fig_size=fig_size,
169170
fig_title=f"Patent summary for {compound_id}",
170171
)
172+
173+
return "No patent data available to plot."

0 commit comments

Comments
 (0)