示例#1
0
def test_widget_selection(flush_guard):
    df = vaex.example()
    with pytest.raises(ValueError) as e:
        selection_widget_default = df.widget.selection_expression()
    assert "'default'" in str(e.value)

    counts = {'default': 0, 'pos': 0}

    @df.signal_selection_changed.connect
    def update(df, name):
        nonlocal counts
        counts[name] += 1

    count_pos = df.count(selection=df.x > 0)

    df.select(df.x > 0)
    selection_widget_default = df.widget.selection_expression()
    assert selection_widget_default.value.expression == '(x > 0)'

    selection_widget = df.widget.selection_expression(df.x > 0, name='pos')
    assert selection_widget_default.value.expression == '(x > 0)'
    # selection_widget = df.widget.selection(df.x > 0, name='pos')
    assert counts == {'default': 2, 'pos': 1}
    assert df.count(selection='pos') == count_pos
    selection_widget.v_model = 'x < 0'
    assert selection_widget.error_messages is None
    assert counts == {'default': 2, 'pos': 2}
    flush(all=True)
示例#2
0
def test_heatmap_model_passes(df, flush_guard):
    passes = df.executor.passes
    x = vaex.jupyter.model.Axis(df=df, expression='x')
    y = vaex.jupyter.model.Axis(df=df, expression='y')
    model = vaex.jupyter.model.Heatmap(df=df, x=x, y=y, shape=5)
    assert df.executor.passes == passes
    flush()
    # this will do two minmaxes in 1 pass
    assert df.executor.passes == passes + 1

    # now will will manually do the grid
    grid = vaex.jupyter.model.GridCalculator(df, [model])
    grid.computation()
    flush()
    assert df.executor.passes == passes + 2

    # once a minmax and a new grid
    x.expression = 'y'
    assert df.executor.passes == passes + 2
    flush()
    assert df.executor.passes == passes + 2 + 2

    # twice a minmax in 1 pass, followed by a gridding
    x.expression = 'x*2'
    y.expression = 'y*2'
    assert df.executor.passes == passes + 2 + 2
    flush()
    assert df.executor.passes == passes + 2 + 2 + 2

    # once a minmax and a new grid
    x.expression = 'x*3'
    assert df.executor.passes == passes + 2 + 2 + 2
    flush(all=True)
    assert df.executor.passes == passes + 2 + 2 + 2 + 2
示例#3
0
def test_expression():
    df = vaex.example()
    expression = df.widget.expression()
    assert expression.value is None
    expression.value = 'x'
    assert expression.value.expression == 'x'
    assert expression.valid
    assert expression.error_messages is None
    assert "good" in expression.success_messages
    flush(all=True)
    assert expression.error_messages is None
    assert expression.success_messages is None

    expression.v_model = 'x+'
    assert not expression.valid
    assert expression.error_messages is not None
    assert expression.success_messages is None
    flush()
    assert expression.error_messages is not None
    assert expression.success_messages is None

    expression = df.widget.expression(df.y)
    assert expression.value == 'y'

    axis = vaex.jupyter.model.Axis(df=df, expression=df.x + 2)
    expression = df.widget.expression(axis)
    assert str(expression.value) == '(x + 2)'
    axis.expression = df.x + 3
    assert str(expression.value) == '(x + 3)'
示例#4
0
def test_widget_counter_selection(flush_guard):
    df = vaex.example()
    c = df.widget.counter_selection('test', lazy=True)
    assert c.value == 0
    # we don't want to *cause* an execution
    df.select(df.x > 0, name='test')
    assert c.value == 0
    # flush()
    # but will update when once happens
    df.sum(df.x)
    count_pos = df.count(selection='test')
    assert c.value == count_pos

    df.select(df.x < 0, name='test')
    assert c.value == count_pos
    df.sum(df.x)
    count_neg = df.count(selection='test')
    assert c.value == count_neg

    # existing selection, and non-lazy
    c = df.widget.counter_selection('test')
    assert c.value == count_neg
    df.select(df.x > 0, name='test')
    assert c.value == count_pos
    df.select(df.x < 0, name='test')
    assert c.value == count_neg
    flush(all=True)
示例#5
0
def test_data_array_view(flush_guard):
    df = vaex.example()

    x = vaex.jupyter.model.Axis(df=df, expression='x')
    y = vaex.jupyter.model.Axis(df=df, expression='y')
    view = df.widget.data_array(axes=[x, y])
    flush(all=True)
    assert view.model.grid is not None
示例#6
0
def test_plot_widget_bqplot(flush_guard):
    # basic coverage for now
    df = vaex.example()
    df.plot_widget(df.x, df.y)
    df.plot_widget(df.x.astype('float32'), df.y.astype('float32'))
    df.plot_widget(df.x.astype('float32'),
                   df.y.astype('float32'),
                   limits='minmax')
    flush(all=True)
示例#7
0
def test_column(flush_guard):
    df = vaex.example()
    column = df.widget.column()
    assert column.value is None
    column = df.widget.column(df.y)
    assert column.value == 'y'

    axis = vaex.jupyter.model.Axis(df=df, expression=df.x)
    column_widget = df.widget.column(axis)
    assert str(column_widget.value) == 'x'
    axis.expression = df.y
    assert str(column_widget.value) == 'y'
    flush(all=True)
示例#8
0
def test_histogram_selections(df, flush_guard):
    g1 = vaex.jupyter.model.Axis(df=df, expression='g1')
    g2 = vaex.jupyter.model.Axis(df=df, expression='g2')
    df.select(df.g1 == 1)
    model1 = vaex.jupyter.model.Histogram(df=df, x=g1, selections=[None, True])
    model2 = vaex.jupyter.model.Histogram(df=df, x=g2, selections=[None, True])
    grid = vaex.jupyter.model.GridCalculator(df, [model1, model2])  # noqa
    flush(all=True)
    assert model1.grid.data.tolist() == [[1, 2, 3], [0, 2, 0]]
    assert model2.grid.data.tolist() == [[2, 2, 1, 1], [1, 1, 0, 0]]

    viz = vaex.jupyter.view.Histogram(model=model1, groups='selections')
    assert viz.plot.mark.y.tolist() == [[1, 2, 3], [0, 2, 0]]
示例#9
0
def test_heatmap_model_basics(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression='x', min=0, max=5)
    g1 = vaex.jupyter.model.Axis(df=df, expression='g1')
    model = vaex.jupyter.model.Heatmap(df=df, x=x, y=g1, shape=2)
    grid = vaex.jupyter.model.GridCalculator(df, [model])
    flush()
    assert model.x.min == 0
    assert model.x.max == 5
    assert model.y.min == -0.5
    assert model.y.max == 2.5
    assert model.shape == 2
    assert model.x.shape is None
    assert model.y.shape == 3
    assert model.grid.data.tolist() == [[[1, 2, 0], [0, 0, 2]]]

    viz = vaex.jupyter.view.Heatmap(model=model)
    flush()
    # TODO: if we use bqplot-image-gl we can test the data again
    # assert viz.heatmap.color.T.tolist() == [[1, 2, 0], [0, 0, 2]]
    assert viz.plot.x_label == 'x'
    assert viz.plot.y_label == 'g1'

    model.x.expression = 'g2'
    flush()
    assert model.x.min == -0.5
    assert model.x.max == 3.5
    assert model.x.shape == 4
    assert model.shape == 2
    grid = [[1, 1, 0], [0, 1, 1], [0, 0, 1], [0, 0, 1]]
    assert model.grid.data.tolist() == [grid]
    flush(all=True)
示例#10
0
def test_model_selection(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression='g1')
    df.select(df.x > 0)
    model = vaex.jupyter.model.Histogram(df=df,
                                         x=x,
                                         selection=[None, 'default'])
    grid = vaex.jupyter.model.GridCalculator(df, [model])
    flush()
    assert model.x.min == -0.5
    assert model.x.max == 2.5
    assert model.x.shape == 3
    assert model.grid.data.tolist() == [[1, 2, 3], [0, 2, 3]]
    assert model.grid.dims == ('selection', 'g1')
    assert model.grid.coords['selection'].data.tolist() == [None, 'default']
    assert model.grid.coords['g1'].data.tolist() == [0, 1, 2]
示例#11
0
def test_data_array_attrs(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression='x', min=0, max=1)
    y = vaex.jupyter.model.Axis(df=df, expression='y')
    model = vaex.jupyter.model.Heatmap(df=df, x=x, y=y, shape=5)
    assert x.min == 0
    assert x.max == 1
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    assert x.min == 0
    assert x.max == 1
    flush(all=True)
    assert x.min == 0
    assert x.max == 1
    assert model.grid.coords['x'].attrs['min'] == 0
    assert model.grid.coords['x'].attrs['max'] == 1
    assert model.grid.coords['y'].attrs['min'] == y.min
    assert model.grid.coords['y'].attrs['max'] == y.max
示例#12
0
def test_histogram_sliced(df, flush_guard):
    g1 = vaex.jupyter.model.Axis(df=df, expression='g1')
    g2 = vaex.jupyter.model.Axis(df=df, expression='g2')
    model1 = vaex.jupyter.model.Histogram(df=df, x=g1)
    model2 = vaex.jupyter.model.Histogram(df=df, x=g2)
    grid = vaex.jupyter.model.GridCalculator(df, [model1, model2])  # noqa
    flush(all=True)
    assert model1.grid.data is not None
    assert model1.x.centers.tolist() == [0, 1, 2]

    assert model1.grid.data.tolist() == [[1, 2, 3]]
    assert model2.grid.data.tolist() == [[2, 2, 1, 1]]

    viz = vaex.jupyter.view.Histogram(model=model1, dimension_groups='slice')
    assert viz.plot.mark.y.tolist() == [[1, 2, 3]]
    assert model1.grid_sliced is None
    model2.x.slice = 0
    assert model1.grid.data.tolist() == [[1, 2, 3]]
    assert model1.grid_sliced.data.tolist() == [[1, 1, 0]]
    assert viz.plot.mark.y.tolist() == [[1, 2, 3], [1, 1, 0]]
示例#13
0
def test_two_model_passes(df, flush_guard):
    passes = df.executor.passes
    x1 = vaex.jupyter.model.Axis(df=df, expression='x')
    x2 = vaex.jupyter.model.Axis(df=df, expression='x')
    model1 = vaex.jupyter.model.Histogram(df=df, x=x1)
    model2 = vaex.jupyter.model.Histogram(df=df, x=x2)
    assert df.executor.passes == passes
    flush()
    # this will do the minmax for both in 1 pass
    assert df.executor.passes == passes + 1

    # now we will manually do the gridding, both in 1 pass
    grid1 = vaex.jupyter.model.GridCalculator(df, [model1])
    grid2 = vaex.jupyter.model.GridCalculator(df, [model2])
    grid1.computation()
    grid2.computation()
    assert model1.grid is None
    assert model2.grid is None
    flush(all=True)
    assert df.executor.passes == passes + 1 + 1
示例#14
0
def test_widget_heatmap(flush_guard):
    df = vaex.example()
    df.select_rectangle('x', 'y', [[-10, 10], [-50, 50]], name='check')
    check_rectangle = df.count(selection='check')

    df.select(df.x > 0)
    check_positive = df.count(selection=True)
    heatmap = df.widget.heatmap('x', 'y', selection=[None, True])

    flush()
    assert heatmap.model.grid[1].sum().item() == check_positive - 1
    toolbar = heatmap.toolbar
    toolbar.interact_value = "pan-zoom"
    assert isinstance(heatmap.plot.figure.interaction,
                      bqplot.interacts.PanZoom)
    toolbar.interact_value = "select-rect"
    assert isinstance(heatmap.plot.figure.interaction,
                      bqplot.interacts.BrushSelector)

    heatmap.plot.figure.interaction.selected_x = [-10, 10]
    heatmap.plot.figure.interaction.selected_y = [-50, 50]
    assert heatmap.model.grid.shape[0] == 2
    flush()
    assert heatmap.model.grid[1].sum().item() == check_rectangle

    toolbar.interact_value = "doesnotexit"
    assert heatmap.plot.figure.interaction is None

    # vizdata = heatmap.plot.mark.image.tolist()
    # heatmap.model.x_slice = 10
    # assert heatmap.plot.mark.image.tolist() != vizdata
    vizdata = heatmap.plot.mark.image.value
    heatmap.model.x.max = 10
    flush(all=True)
    assert heatmap.plot.mark.image.value != vizdata, "image should change"
示例#15
0
def test_widget_histogram(flush_guard, no_vaex_cache):
    df = vaex.example()
    assert df.widget is df.widget
    df.select_box(['x'], [[-10, 20]], name='check')

    check_range = df.count(selection='check')

    df.select(df.x > 0)
    check_positive = df.count(selection='default')
    histogram = df.widget.histogram('x',
                                    selection=[None, "default"],
                                    toolbar=True)

    flush()
    assert histogram.model.grid[1].sum(
    ) == check_positive  # for some reason, because 'x' it float32, we don't need -1
    toolbar = histogram.toolbar
    toolbar.interact_value = "pan-zoom"
    assert isinstance(histogram.plot.figure.interaction,
                      bqplot.interacts.PanZoom)
    toolbar.interact_value = "select-x"
    assert isinstance(histogram.plot.figure.interaction,
                      bqplot.interacts.BrushIntervalSelector)

    histogram.plot.figure.interaction.selected = [-10, 20]
    flush(all=True)
    assert histogram.model.grid.shape[0] == 2
    assert histogram.model.grid[1].sum() == check_range

    toolbar.interact_value = "doesnotexit"
    assert histogram.plot.figure.interaction is None
    # coverage
    histogram.plot.highlight(0)
    histogram.plot.highlight(None)

    vizdata = histogram.plot.mark.y.tolist()
    histogram.model.x_slice = 10
    assert histogram.plot.mark.y.tolist() == vizdata
    histogram.dimension_groups = 'slice'
    assert histogram.plot.mark.y.tolist() != vizdata
示例#16
0
def test_histogram_model(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression='g1')
    model = vaex.jupyter.model.Histogram(df=df, x=x)
    grid = vaex.jupyter.model.GridCalculator(df, [model])
    flush()
    assert model.x.min == -0.5
    assert model.x.max == 2.5
    assert model.x.shape == 3
    assert model.grid.data.tolist() == [[1, 2, 3]]
    assert model.grid.dims == ('selection', 'g1')
    assert model.grid.coords['selection'].data.tolist() == [None]
    assert model.grid.coords['g1'].data.tolist() == [0, 1, 2]

    viz = vaex.jupyter.view.Histogram(model=model, dimension_groups='slice')
    assert viz.plot.mark.y.tolist() == [[1, 2, 3]]
    assert viz.plot.x_axis.label == 'g1'
    assert viz.plot.y_axis.label == 'count'

    model.x.expression = 'g2'
    flush()
    assert model.x.min == -0.5
    assert model.x.max == 3.5
    assert model.x.shape == 4
    assert model.grid.data.tolist() == [[2, 2, 1, 1]]
    assert model.grid.dims == ('selection', 'g2')
    assert model.grid.coords['selection'].data.tolist() == [None]
    assert model.grid.coords['g2'].data.tolist() == [0, 1, 2, 3]
    assert viz.plot.x_axis.label == 'g2'

    x = vaex.jupyter.model.Axis(df=df, expression='x', min=-0.5, max=5.5)
    model = vaex.jupyter.model.Histogram(df=df, x=x, shape=6)
    flush()
    assert model.x.centers.tolist() == [0, 1, 2, 3, 4, 5]
    assert model.x.min == -0.5
    assert model.x.max == 5.5
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    assert model.x.shape is None
    assert model.shape == 6
    flush(all=True)
示例#17
0
def test_axis_minmax(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression=df.x)
    model = vaex.jupyter.model.DataArray(df=df, axes=[x])
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    flush()
    assert x.min == df.x.min()
    assert x.max == df.x.max()

    x = vaex.jupyter.model.Axis(df=df, expression=df.x, min=1, max=2)
    model = vaex.jupyter.model.DataArray(df=df, axes=[x])
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    flush()
    assert x.min == 1
    assert x.max == 2

    # with 2 axes
    x = vaex.jupyter.model.Axis(df=df, expression=df.x, min=1, max=2)
    y = vaex.jupyter.model.Axis(df=df, expression=df.y, min=2, max=3)
    model = vaex.jupyter.model.DataArray(df=df, axes=[x, y])
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    flush()
    assert x.min == 1
    assert x.max == 2
    assert y.min == 2
    assert y.max == 3

    # with 2 axes, one with min/max
    x = vaex.jupyter.model.Axis(df=df, expression=df.x, min=1, max=2)
    y = vaex.jupyter.model.Axis(df=df, expression=df.y)
    model = vaex.jupyter.model.DataArray(df=df, axes=[x, y])
    grid = vaex.jupyter.model.GridCalculator(df, [model])  # noqa
    flush(all=True)
    assert x.min == 1
    assert x.max == 2
    assert y.min == df.y.min()
    assert y.max == df.y.max()
示例#18
0
def test_histogram_model_passes(df, flush_guard):
    passes = df.executor.passes
    x = vaex.jupyter.model.Axis(df=df, expression='x')
    model = vaex.jupyter.model.Histogram(df=df, x=x)
    assert df.executor.passes == passes
    flush()
    # this will do the minmax
    assert df.executor.passes == passes + 1

    # now will will manually do the grid
    grid = vaex.jupyter.model.GridCalculator(df, [model])
    grid.computation()
    flush()
    assert df.executor.passes == passes + 2

    # a minmax and a new grid
    model.x.expression = 'y'
    assert df.executor.passes == passes + 2
    flush(all=True)
    assert df.executor.passes == passes + 2 + 2
示例#19
0
def test_axis_basics(df, flush_guard):
    x = vaex.jupyter.model.Axis(df=df, expression=df.x)
    flush()
    assert x.min == df.x.min()
    assert x.max == df.x.max()
    assert x.centers.shape[0] == x.shape_default

    center_last = x.centers[-1]
    x.max += 1
    flush()
    assert x.centers[-1] > center_last

    x.shape = 5
    flush()
    assert x.centers.shape[0] == 5

    x.shape = 6
    flush()
    assert x.centers.shape[0] == 6

    x.shape_default = 7
    flush()
    assert x.centers.shape[0] == 6

    x.shape = None
    flush(all=True)
    assert x.centers.shape[0] == 7