def test_with_data_source(mpg_df):
    from pandas_visual_analysis import VisualAnalysis, DataSource

    df = mpg_df

    ds = DataSource(df)
    VisualAnalysis(ds)
Example #2
0
    def test_normalize_select_false(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        hw = HistogramWidget(ds, 0, 0, 1.0, 400)
        hw.normalize.value = False

        assert hw.figure_widget.data[0].histnorm == ""
        assert hw.figure_widget.data[1].histnorm == ""
    def test_brush_indices_change(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)
        bp.build()
        ds.brushed_indices = [1, 2, 3]

        assert bp.figure_widget.data[0].selectedpoints == ds.brushed_indices
Example #4
0
    def test_brush_indices_change(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        hw = HistogramWidget(ds, 0, 0, 1.0, 400)
        hw.build()
        ds.brushed_indices = [1, 2, 3]

        assert hw.figure_widget.data[1].selectedpoints == ds.brushed_indices
        assert hw.figure_widget.data[0].visible
    def test_on_selection(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)

        points = PointsObject([1, 2, 3])
        bp.on_selection(None, points, None)

        assert ds.brushed_indices == set(points.point_inds)
    def test_on_selection(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)

        points = PointsObject([1, 2, 3])
        ps.on_selection(None, points, None)

        assert sum(list(ps.figure_widget.data[0].line.color)) == 3
        assert ds.brushed_indices == set(points.point_inds)
Example #7
0
    def test_plot_invisible_with_no_data(self, small_df, populated_config):
        ds = DataSource(small_df)
        hw = HistogramWidget(ds, 0, 0, 1.0, 400)
        ds.brushed_indices = []

        assert not hw.figure_widget.data[1].visible

        ds.brushed_indices = [0]
        assert hw.figure_widget.data[1].visible
    def test_on_selection_constraint_ranges_reset(self, small_df,
                                                  populated_config):
        ds = DataSource(small_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)

        dimensions = ps.figure_widget.data[0].dimensions
        assert len(dimensions) != 0
        dimensions = fill_sample_constraint_range(dimensions, "a", [2, 5])
        ps._on_selection_helper(None, dimensions)

        ds.brushed_indices = [1, 2]
        assert ps.constraint_ranges == {}
    def test_constraint_range_reset_data_source(self, small_df,
                                                populated_config, type):
        ds = DataSource(small_df)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
        ds.selection_type = type

        dimensions = ps.figure_widget.data[0].dimensions
        assert len(dimensions) != 0
        dimensions = fill_sample_constraint_range(dimensions, "a", [2, 5])
        ps._on_selection_helper(None, dimensions)

        assert ps.constraint_ranges == {}
def test_base_widget_abstract_methods(small_df):
    BaseWidget.__abstractmethods__ = set()

    class Dummy(BaseWidget):
        pass

    d = Dummy(DataSource(small_df), 0, 0, 1.0, 400)

    d.on_deselection(None, None)
    d.observe_brush_indices_change(None)
    d.build()
    d.on_selection(None, None, None)
    d.set_observers()
    def test_on_selection_helper_no_ranges_deselect(self, small_df,
                                                    populated_config):
        ds = DataSource(small_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
        ds.brushed_indices = [1, 2]

        old_dimensions = deepcopy(
            ps.figure_widget.data[0].dimensions)  # no constraint ranges
        dimensions = ps.figure_widget.data[0].dimensions
        dimensions = fill_sample_constraint_range(dimensions, "a", [2, 5])
        ps._on_selection_helper(None, dimensions)
        assert len(ds) != 0
        ps._on_selection_helper(None, old_dimensions)  # trigger deselect

        assert len(ds.brushed_indices) == ds.len
    def test_on_selection_helper_int_range(self, small_df, populated_config):
        def on_selection_assert(trace, points, state):
            assert len(points.point_inds) == 4
            assert isinstance(points.point_inds, list)
            assert 0 not in points.point_inds

        ds = DataSource(small_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
        old_dimensions = deepcopy(
            ps.figure_widget.data[0].dimensions)  # no constraint ranges
        assert len(old_dimensions) != 0
        dimensions = fill_sample_constraint_range(old_dimensions, "a", [2, 5])
        print(dimensions)

        ps.on_selection = on_selection_assert
        ps._on_selection_helper(None, dimensions)
    def test_brush_indices_change(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)

        dimensions = ps.figure_widget.data[0].dimensions
        assert len(dimensions) != 0
        dimensions = fill_sample_constraint_range(dimensions, "a", [1.5, 5])
        ps.figure_widget.data[0].dimensions = dimensions

        ps.change_initiated = False

        ds.brushed_indices = [1, 2, 3]

        assert sum(list(ps.figure_widget.data[0].line.color)) == 3
        dimensions = ps.figure_widget.data[0].dimensions
        for dimension in dimensions:
            if dimension.label == "a":
                assert dimension["constraintrange"] is None
                break
    def test_redraw_plot_keep_old_constraint_ranges(self, rand_float_df,
                                                    populated_config):
        ds = DataSource(rand_float_df, None)
        ps = ParallelCoordinatesWidget(ds, 0, 0, 0.2, 400)

        dimensions = ps.figure_widget.data[0].dimensions
        assert len(dimensions) != 0
        dimensions = fill_sample_constraint_range(dimensions, "A", [1.5, 5])
        ps.figure_widget.data[0].dimensions = dimensions

        ps.selected_columns = ["A", "B"]
        ps._redraw_plot()

        updated_ranges = {
            dim["label"]: dim["constraintrange"]
            for dim in ps.figure_widget.data[0].dimensions
            if dim["constraintrange"]
        }

        assert list(updated_ranges["A"]) == [1.5, 5]
 def test_normal_few_cols_html(self, small_df, populated_config):
     df = small_df.drop(columns=["a", "c"])
     ds = DataSource(df, None)
     with pytest.raises(ValueError):
         ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
 def test_object_creation(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
 def test_multi_select(self, rand_float_df, populated_config):
     ds = DataSource(rand_float_df, None)
     ps = ParallelCoordinatesWidget(ds, 0, 0, 0.2, 400)
     ps.multi_select.selected_options = ["A", "B"]
 def test_basic_multi_select(self, rand_float_df, populated_config):
     ds = DataSource(rand_float_df, None)
     ps = ParallelCoordinatesWidget(ds, 0, 0, 0.2, 400)
     assert ps.multi_select is not None
 def test_object_creation(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     BoxPlotWidget(ds, 0, 0, 1.0, 400)
Example #20
0
 def test_column_select(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     hw = HistogramWidget(ds, 0, 0, 1.0, 400)
     hw.column_select.value = "b"
     assert list(hw.figure_widget.data[0].x) == list(small_df["b"].values)
Example #21
0
 def test_on_deselection(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     ds.brushed_indices = [0]
     hw = HistogramWidget(ds, 0, 0, 1.0, 400)
     hw.on_deselection(None, None)
     assert len(ds.brushed_indices) == len(small_df)
    def test_box_points(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)
        bp.box_point_select.value = "outliers"

        assert bp.figure_widget.data[0].boxpoints == "outliers"
Example #23
0
 def test_init_with_data_source(self, small_df):
     ds = DataSource(small_df, None)
     assert VisualAnalysis(data=ds)
 def test_column_select(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)
     bp.column_select.value = "c"
     assert list(bp.figure_widget.data[0].y) == list(small_df["c"].values)
Example #25
0
 def test_basic_multi_select(self, rand_cat_df, populated_config):
     ds = DataSource(rand_cat_df, None)
     ParallelCategoriesWidget(ds, 0, 0, 0.2, 400)
 def test_on_deselection(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     ds.brushed_indices = [0]
     bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)
     bp.on_deselection(None, None)
     assert len(ds.brushed_indices) == len(small_df)
 def test_normal_build(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     ps = ParallelCoordinatesWidget(ds, 0, 0, 1.0, 400)
     root_widget = ps.build()
     assert isinstance(root_widget, widgets.HBox)
Example #28
0
 def test_normal_build(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     hw = HistogramWidget(ds, 0, 0, 1.0, 400)
     root_widget = hw.build()
     assert isinstance(root_widget, widgets.VBox)
Example #29
0
    def test_brush_indices_change(self, small_df, populated_config):
        ds = DataSource(small_df, None)
        pc = ParallelCategoriesWidget(ds, 0, 0, 1.0, 400)
        ds.brushed_indices = [1, 2, 3]

        assert sum(list(pc.figure_widget.data[0].line.color)) == 3
 def test_normal_build(self, small_df, populated_config):
     ds = DataSource(small_df, None)
     bp = BoxPlotWidget(ds, 0, 0, 1.0, 400)
     root_widget = bp.build()
     assert isinstance(root_widget, widgets.VBox)