Skip to content

Commit 44b03d3

Browse files
authored
🙈 first iteration of bugfix for #144 (#145)
1 parent 17913ed commit 44b03d3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def _parse_get_trace_props(
625625
626626
"""
627627
hf_x: np.ndarray = (
628-
trace["x"]
628+
(np.asarray(trace["x"]) if trace["x"] is not None else None)
629629
if hasattr(trace, "x") and hf_x is None
630630
else hf_x.values
631631
if isinstance(hf_x, pd.Series)
@@ -641,7 +641,7 @@ def _parse_get_trace_props(
641641
if isinstance(hf_y, (pd.Series, pd.Index))
642642
else hf_y
643643
)
644-
hf_y : np.ndarray = np.asarray(hf_y)
644+
hf_y: np.ndarray = np.asarray(hf_y)
645645

646646
hf_text = (
647647
hf_text
@@ -696,9 +696,7 @@ def _parse_get_trace_props(
696696
hf_hovertext = hf_hovertext[not_nan_mask]
697697

698698
# Try to parse the hf_x data if it is of object type or
699-
if len(hf_x) and (
700-
hf_x.dtype.type is np.str_ or hf_x.dtype == "object"
701-
):
699+
if len(hf_x) and (hf_x.dtype.type is np.str_ or hf_x.dtype == "object"):
702700
try:
703701
# Try to parse to numeric
704702
hf_x = pd.to_numeric(hf_x, errors="raise")
@@ -901,7 +899,7 @@ def add_trace(
901899
As this is a costly operation, it is recommended to set this parameter to
902900
False if you are sure that your data does not contain NaNs (or when the
903901
downsampler can handle NaNs, e.g., EveryNthPoint). This should considerably
904-
speed up the graph construction time.
902+
speed up the graph construction time.
905903
**trace_kwargs: dict
906904
Additional trace related keyword arguments.
907905
e.g.: row=.., col=..., secondary_y=...
@@ -973,7 +971,9 @@ def add_trace(
973971

974972
# construct the hf_data_container
975973
# TODO in future version -> maybe regex on kwargs which start with `hf_`
976-
dc = self._parse_get_trace_props(trace, hf_x, hf_y, hf_text, hf_hovertext, check_nans)
974+
dc = self._parse_get_trace_props(
975+
trace, hf_x, hf_y, hf_text, hf_hovertext, check_nans
976+
)
977977

978978
# These traces will determine the autoscale its RANGE!
979979
# -> so also store when `limit_to_view` is set.
@@ -1069,7 +1069,7 @@ def add_traces(
10691069
limit_to_views : None | List[bool] | bool, optional
10701070
List of limit_to_view booleans for the added traces. If set to True the
10711071
trace's datapoints will be cut to the corresponding front-end view, even if
1072-
the total number of samples is lower than ``max_n_samples``.
1072+
the total number of samples is lower than ``max_n_samples``.
10731073
If a single boolean is passed, all to be added traces will use this value,
10741074
by default False.\n
10751075
Remark that setting this parameter to True ensures that low frequency traces

tests/test_figure_resampler.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,14 @@ def test_proper_copy_of_wrapped_fig(float_series):
621621
assert len(plotly_resampler_fig.data[0].y) == 500
622622

623623

624+
def test_low_dim_input():
625+
fig = go.Figure()
626+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name='a'))
627+
628+
fig = FigureResampler(go.Figure())
629+
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[1, 2, 3], name='a'))
630+
fig.add_trace(go.Scatter(), hf_x=[1, 2, 3], hf_y=[1, 2, 3])
631+
624632
def test_2d_input_y():
625633
# Create some dummy dataframe with a nan
626634
df = pd.DataFrame(

0 commit comments

Comments
 (0)