def test_box_selection_callback(self, inspect_neighbors, result): nodes = cudf.DataFrame({ "vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0] }) edges = cudf.DataFrame({ "source": [1, 1, 1, 1], "target": [0, 1, 2, 3] }) dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges))) bg = BaseGraph() bg.chart_type = "temp" bg.nodes = nodes bg.edges = edges bg.inspect_neighbors = inspect_neighbors self.result = None def t_function(nodes, edges=None, patch_update=False): self.result = nodes.reset_index(drop=True) bg.reload_chart = t_function dashboard._active_view = bg.name class evt: geometry = dict(x0=1, x1=3, y0=0, y1=1, type="rect") t = bg.get_selection_geometry_callback(dashboard) t(evt) assert self.result.equals(result)
def test_lasso_election_callback(self): nodes = cudf.DataFrame({ "vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0] }) edges = cudf.DataFrame({ "source": [1, 1, 1, 1], "target": [0, 1, 2, 3] }) dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges))) bg = BaseGraph() bg.chart_type = "temp" bg.nodes = nodes bg.edges = edges bg.inspect_neighbors = CustomInspectTool(_active=False) def t_function(nodes, edges=None, patch_update=False): pass bg.reload_chart = t_function class evt: geometry = dict(x=[1, 1, 2], y=[1, 2, 1], type="poly") final = True t = bg.get_selection_geometry_callback(dashboard) with mock.patch("cuspatial.point_in_polygon") as pip: pip.return_value = cudf.DataFrame( {"selection": [True, False, True, False]}) t(evt) assert pip.called
def test_lasso_selection_callback(self, df_type): nodes = initialize_df( df_type, {"vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0]}, ) edges = initialize_df( df_type, {"source": [1, 1, 1, 1], "target": [0, 1, 2, 3]} ) dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges))) bg = BaseGraph() bg.chart_type = "temp" bg.nodes = nodes bg.edges = edges bg.inspect_neighbors = CustomInspectTool(_active=False) def t_function(data, edges=None, patch_update=False): self.result = data bg.reload_chart = t_function geometry = np.array([[1, 1, 2], [1, 2, 1]]) t = bg.get_lasso_select_callback(dashboard) with mock.patch("cuspatial.point_in_polygon") as pip: if isinstance(nodes, dask_cudf.DataFrame): # point in polygon is called per partition, # in this case 2 partitions of length 2 each pip.return_value = cudf.DataFrame({"selection": [True, False]}) else: pip.return_value = cudf.DataFrame( {"selection": [True, False, True, False]} ) t(geometry) assert pip.called assert isinstance(self.result, df_type)
def test_box_selection_callback( self, df_type, inspect_neighbors, result, index ): nodes = initialize_df( df_type, {"vertex": [0, 1, 2, 3], "x": [0, 1, 1, 2], "y": [0, 1, 2, 0]}, ) edges = initialize_df( df_type, {"source": [1, 1, 1, 1], "target": [0, 1, 2, 3]} ) dashboard = DashBoard(dataframe=DataFrame.load_graph((nodes, edges))) bg = BaseGraph() bg.chart_type = "temp" bg.nodes = nodes bg.edges = edges bg.inspect_neighbors = inspect_neighbors self.result = None def t_function(data, edges=None, patch_update=False): self.result = data.reset_index(drop=True) bg.reload_chart = t_function dashboard._active_view = bg class evt: bounds = (1, 3, 0, 1) x_selection = (1, 3) y_selection = (0, 1) t = bg.get_box_select_callback(dashboard) t(evt.bounds, evt.x_selection, evt.y_selection) result = initialize_df(df_type, result, index) assert df_equals(self.result, result)