Skip to content

Commit 7e735f1

Browse files
committed
✨ improve try-except blocks, see #113
1 parent 5352bb2 commit 7e735f1

File tree

6 files changed

+7
-9
lines changed

6 files changed

+7
-9
lines changed

plotly_resampler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
from google.colab import output
2828

2929
output.enable_custom_widget_manager()
30-
except ImportError:
30+
except (ImportError, ModuleNotFoundError):
3131
pass

plotly_resampler/aggregation/aggregators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
try:
2020
# The efficient c version of the LTTB algorithm
2121
from .algorithms.lttb_c import LTTB_core_c as LTTB_core
22-
except:
22+
except (ImportError, ModuleNotFoundError):
2323
import warnings
2424
warnings.warn("Could not import lttbc; will use a (slower) python alternative.")
2525
from .algorithms.lttb_py import LTTB_core_py as LTTB_core

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import base64
1818
import dash
1919
import plotly.graph_objects as go
20-
from dash import Dash
2120
from flask_cors import cross_origin
2221
from jupyter_dash import JupyterDash
2322
from plotly.basedatatypes import BaseFigure
@@ -320,7 +319,7 @@ def __init__(
320319
self.data[idx].update(graph_dict["data"][idx])
321320

322321
# The FigureResampler needs a dash app
323-
self._app: JupyterDash | Dash | None = None
322+
self._app: JupyterDash | dash.Dash | None = None
324323
self._port: int | None = None
325324
self._host: str | None = None
326325

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ def _parse_get_trace_props(
697697
# not will be transformed to an array of ints (0, 1))
698698
try:
699699
hf_y = pd.to_numeric(hf_y, errors="raise")
700-
except:
700+
except ValueError:
701701
hf_y = hf_y.astype("str")
702702

703703
# orjson encoding doesn't like to encode with uint8 & uint16 dtype

plotly_resampler/figure_resampler/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import pandas as pd
55

66
from plotly.basedatatypes import BaseFigure
7-
try:
7+
try: # Fails when IPywidgets is not installed
88
from plotly.basewidget import BaseFigureWidget
9-
except ImportError:
9+
except (ImportError, ModuleNotFoundError):
1010
BaseFigureWidget = None
1111

1212
from typing import Any
@@ -32,7 +32,6 @@ def is_figure(figure: Any) -> bool:
3232
bool
3333
True if the figure is a plotly go.Figure or a FigureResampler.
3434
"""
35-
3635
return isinstance(figure, BaseFigure) and (not isinstance(figure, BaseFigureWidget))
3736

3837

plotly_resampler/registering.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _is_ipython_env():
5454
from IPython import get_ipython
5555

5656
return "IPKernelApp" in get_ipython().config
57-
except Exception:
57+
except (ImportError, AttributeError):
5858
return False
5959

6060

0 commit comments

Comments
 (0)