Skip to content

Commit

Permalink
✨ altering tests (to reduce false negatives)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasvdd committed Feb 14, 2024
1 parent 634bbfc commit 09695fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 3 additions & 4 deletions tests/test_aggregators.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_arg_downsample_no_x_empty_series(downsampler, series):
def test_wrap_aggregate(downsampler, gap_handler, series, index_type):
series = series.copy()
series.index = construct_index(series, index_type)
for n in np.random.randint(100, len(series), 6):
for n in np.random.randint(100, len(series) // 2, 6):
# make sure n is even (required for MinMax downsampler)
n = n - (n % 2)
x_agg, y_agg, indices = wrap_aggregate(
Expand Down Expand Up @@ -234,11 +234,10 @@ def test_wrap_aggregate_range_index_data_point_selection(

# ------------------------------- NAN handling -------------------------------
@pytest.mark.parametrize("downsampler", [MinMaxLTTB, MinMaxAggregator])
@pytest.mark.parametrize("gap_handler", [MedDiffGapHandler, NoGapHandler])
@pytest.mark.parametrize("series", [lf("float_series")])
def test_nan_behavior(series, downsampler, gap_handler):
def test_nan_behavior(series, downsampler):
series = series.copy()
series.iloc[np.random.choice(len(series), 100)] = np.nan
series.iloc[1 + np.random.choice(len(series) - 2, 100, replace=False)] = np.nan

# OMIT -> no NaNs in the output
for n in np.random.randint(100, len(series), 6):
Expand Down
14 changes: 10 additions & 4 deletions tests/test_figure_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ def test_nan_retained_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
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scatter(x=float_series.index, y=float_series, name="float_series"),
row=1,
Expand All @@ -449,7 +451,9 @@ def test_nan_retained_input(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
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scatter(
x=float_series.index, y=float_series
Expand All @@ -459,7 +463,9 @@ def test_nan_retained_input(float_series):
col=1,
)

float_series.iloc[np.random.choice(len(float_series), 100)] = np.nan
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scattergl(
x=float_series.index,
Expand Down Expand Up @@ -599,7 +605,7 @@ def test_hf_text_and_hf_marker_color():
def test_hf_text_and_hf_hovertext_and_hf_marker_size_nans():
y_orig = np.arange(10_000).astype(float)
y = y_orig.copy()
y[::101] = np.nan
y[1::101] = np.nan

# NEW from plotly-resampler >0.9.2 => we retain the NaNs in the input data and
# the NaN handling is delegated to the aggregators
Expand Down
12 changes: 9 additions & 3 deletions tests/test_figurewidget_resampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ 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
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scatter(x=float_series.index, y=float_series, name="float_series"),
row=1,
Expand All @@ -279,7 +281,9 @@ def test_nan_removed_input(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
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scatter(
x=float_series.index, y=float_series
Expand All @@ -289,7 +293,9 @@ def test_nan_removed_input(float_series):
col=1,
)

float_series.iloc[np.random.choice(len(float_series), 100)] = np.nan
float_series.iloc[
1 + np.random.choice(len(float_series) - 2, 100, replace=False)
] = np.nan
fig.add_trace(
go.Scattergl(
x=float_series.index,
Expand Down

0 comments on commit 09695fc

Please sign in to comment.