Skip to content

Commit

Permalink
🙈 formatting + fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasvdd committed Feb 13, 2024
1 parent 56f71a8 commit 374a426
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plotly_resampler/aggregation/aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
MinMaxLTTBDownsampler,
NaNMinMaxDownsampler,
NaNMinMaxLTTBDownsampler,
# TODO -> integrate NANM4 (after the candlestick PR)
)

# TODO -> integrate NANM4 (after the candlestick PR)
from ..aggregation.aggregation_interface import DataAggregator, DataPointSelector


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ def _parse_get_trace_props(
if hf_y.ndim != 0: # if hf_y is an array
hf_x = pd.RangeIndex(0, len(hf_y)) # np.arange(len(hf_y))
else: # if no data as y or hf_y is passed
hf_x = np.asarray(None)
hf_x = np.asarray([])
hf_y = np.asarray([])

assert hf_y.ndim == np.ndim(hf_x), (
"plotly-resampler requires scatter data "
Expand Down
20 changes: 13 additions & 7 deletions tests/test_figure_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,9 @@ def test_replace_properties(float_series):
assert fr_fig._global_downsampler == default_downsampler


def test_nan_removed_input(float_series):
def test_nan_retained_input(float_series):
# NEW from plotly-resampler >0.9.2 => we retain the NaNs in the input data and
# the NaN handling is delegated to the aggregators
# see: https://plotly.com/python/subplots/#custom-sized-subplot-with-subplot-titles
base_fig = make_subplots(
rows=2,
Expand All @@ -431,6 +433,7 @@ def test_nan_removed_input(float_series):
),
)

# ADD nans to to the float_series
float_series = float_series.copy()
float_series.iloc[np.random.choice(len(float_series), 100, replace=False)] = np.nan
fig.add_trace(
Expand All @@ -440,9 +443,10 @@ def test_nan_removed_input(float_series):
hf_text="text",
hf_hovertext="hovertext",
)
# Check the desired behavior
assert len(fig.hf_data[0]["y"]) == len(float_series) - 100
assert ~pd.isna(fig.hf_data[0]["y"]).any()
# Check the desired behavior - normally the NaNs are retained (no changes are made
# to the input data)
assert len(fig.hf_data[0]["y"]) == len(float_series)
assert pd.isna(fig.hf_data[0]["y"]).sum() == 100

# here we test whether we are able to deal with not-nan output
float_series.iloc[np.random.choice(len(float_series), 100)] = np.nan
Expand Down Expand Up @@ -597,7 +601,9 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():
y = y_orig.copy()
y[::101] = np.nan

y_nonan = y[~np.isnan(y)]
# NEW from plotly-resampler >0.9.2 => we retain the NaNs in the input data and
# the NaN handling is delegated to the aggregators
y_nonan = y # we do not remove the NaNs anymore

fig = FigureResampler()
fig.add_trace(
Expand All @@ -612,7 +618,7 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():

assert np.all(fig.hf_data[0]["text"] == y_nonan.astype(str))
assert np.all(fig.hf_data[0]["hovertext"] == y_nonan.astype(str)[::-1])
assert np.all(fig.hf_data[0]["marker_size"] == y_nonan)
assert np.all(fig.hf_data[0]["marker_size"] == y_orig)

fig = FigureResampler()
fig.add_trace(
Expand All @@ -625,7 +631,7 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():

assert np.all(fig.hf_data[0]["text"] == y_nonan.astype(str))
assert np.all(fig.hf_data[0]["hovertext"] == y_nonan.astype(str)[::-1])
assert np.all(fig.hf_data[0]["marker_size"] == y_nonan)
assert np.all(fig.hf_data[0]["marker_size"] == y_orig)


def test_multiple_timezones():
Expand Down
18 changes: 12 additions & 6 deletions tests/test_figurewidget_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def test_replace_figure(float_series):


def test_nan_removed_input(float_series):
# NEW from plotly-resampler >0.9.2 => we retain the NaNs in the input data and
# the NaN handling is delegated to the aggregators
# see: https://plotly.com/python/subplots/#custom-sized-subplot-with-subplot-titles
base_fig = make_subplots(
rows=2,
Expand All @@ -261,6 +263,7 @@ def test_nan_removed_input(float_series):
),
)

# Add NaN's to the float series
float_series = float_series.copy()
float_series.iloc[np.random.choice(len(float_series), 100, replace=False)] = np.nan
fig.add_trace(
Expand All @@ -270,9 +273,10 @@ def test_nan_removed_input(float_series):
hf_text="text",
hf_hovertext="hovertext",
)
# Check the desired behavior
assert len(fig.hf_data[0]["y"]) == len(float_series) - 100
assert ~pd.isna(fig.hf_data[0]["y"]).any()
# Check the desired behavior - normally the NaNs are retained (no changes are made
# to the input data)
assert len(fig.hf_data[0]["y"]) == len(float_series)
assert pd.isna(fig.hf_data[0]["y"]).sum() == 100

# here we test whether we are able to deal with not-nan output
float_series.iloc[np.random.choice(len(float_series), 100)] = np.nan
Expand Down Expand Up @@ -427,7 +431,9 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():
y = y_orig.copy()
y[::101] = np.nan

y_nonan = y[~np.isnan(y)]
# NEW from plotly-resampler >0.9.2 => we retain the NaNs in the input data and
# the NaN handling is delegated to the aggregators
y_nonan = y # we do not remove the NaNs anymore

fig = FigureWidgetResampler()
fig.add_trace(
Expand All @@ -442,7 +448,7 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():

assert np.all(fig.hf_data[0]["text"] == y_nonan.astype(str))
assert np.all(fig.hf_data[0]["hovertext"] == y_nonan.astype(str)[::-1])
assert np.all(fig.hf_data[0]["marker_size"] == y_nonan)
assert np.all(fig.hf_data[0]["marker_size"] == y_orig)

fig = FigureWidgetResampler()
fig.add_trace(
Expand All @@ -455,7 +461,7 @@ def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():

assert np.all(fig.hf_data[0]["text"] == y_nonan.astype(str))
assert np.all(fig.hf_data[0]["hovertext"] == y_nonan.astype(str)[::-1])
assert np.all(fig.hf_data[0]["marker_size"] == y_nonan)
assert np.all(fig.hf_data[0]["marker_size"] == y_orig)


def test_multiple_timezones():
Expand Down

0 comments on commit 374a426

Please sign in to comment.