def test_query_chart_by_indices(self, df_type, new_indices, result, index): bnac = BaseNonAggregate() bnac.chart_type = "test" bnac.x = "a" bnac_1 = BaseNonAggregate() bnac_1.chart_type = "test" bnac_1.x = "b" new_indices = new_indices df = initialize_df(df_type, {"a": [1, 2, 3, 4], "b": [3, 4, 5, 6]}) bnac.source = df self.result = None self.patch_update = None def t_func(data, patch_update): self.result = data self.patch_update = patch_update # creating a dummy reload chart fn as its not implemented in core # non aggregate chart class bnac.reload_chart = t_func bnac.query_chart_by_indices( active_chart=bnac_1, old_indices=[], new_indices=new_indices, datatile=None, ) result = initialize_df(df_type, result, index) assert df_equals(self.result, result) assert self.patch_update is False
def test_lasso_selection_callback(self, df_type): bnac = BaseNonAggregate() bnac.x = "a" bnac.y = "b" bnac.chart_type = "temp" def t_function(data, patch_update=False): self.result = data bnac.reload_chart = t_function df = initialize_df(df_type, {"a": [0, 1, 1, 2], "b": [0, 1, 2, 0]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) geometry = np.array([[1, 1, 2], [1, 2, 1]]) t = bnac.get_lasso_select_callback(dashboard) with mock.patch("cuspatial.point_in_polygon") as pip: if isinstance(df, 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_query_chart_by_indices(self, new_indices, result): bnac = BaseNonAggregate() bnac.chart_type = "test" bnac.x = "a" bnac_1 = BaseNonAggregate() bnac_1.chart_type = "test" bnac_1.x = "b" new_indices = new_indices df = cudf.DataFrame({"a": [1, 2, 3, 4], "b": [3, 4, 5, 6]}) bnac.source = df self.result = None self.patch_update = None def t_func(data, patch_update): self.result = data self.patch_update = patch_update # creating a dummy reload chart fn as its not implemented in core # non aggregate chart class bnac.reload_chart = t_func bnac.query_chart_by_indices( active_chart=bnac_1, old_indices=[], new_indices=new_indices, datatile=None, ) assert self.result.to_string() == result assert self.patch_update is False
def test_query_chart_by_range(self): bnac = BaseNonAggregate() bnac.chart_type = "test" bnac.x = "a" bnac_1 = BaseNonAggregate() bnac_1.chart_type = "test" bnac_1.x = "b" query_tuple = (4, 5) df = cudf.DataFrame({"a": [1, 2, 3, 4], "b": [3, 4, 5, 6]}) bnac.source = df self.result = None self.patch_update = None def t_func(data, patch_update): self.result = data self.patch_update = patch_update # creating a dummy reload chart fn as its not implemented in core # non aggregate chart class bnac.reload_chart = t_func bnac.query_chart_by_range(active_chart=bnac_1, query_tuple=query_tuple, datatile=None) assert self.result.to_string() == " a b\n1 2 4\n2 3 5" assert self.patch_update is False
def test_selection_callback(self): bnac = BaseNonAggregate() bnac.x = "a" bnac.y = "b" bnac.chart_type = "temp" self.result = None def t_function(data, patch_update=False): self.result = data bnac.reload_chart = t_function df = cudf.DataFrame({"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(data=df) dashboard._active_view = bnac.name t = bnac.get_selection_geometry_callback(dashboard) t(xmin=1, xmax=2, ymin=3, ymax=4) assert self.result.equals(df.query("1<=a<=2 and 3<=b<=4"))
def test_box_selection_callback(self): bnac = BaseNonAggregate() bnac.x = "a" bnac.y = "b" bnac.chart_type = "temp" self.result = None def t_function(data, patch_update=False): self.result = data bnac.reload_chart = t_function df = cudf.DataFrame({"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) dashboard._active_view = bnac.name class evt: geometry = dict(x0=1, x1=2, y0=3, y1=4, type="rect") t = bnac.get_selection_geometry_callback(dashboard) t(evt) assert self.result.equals(df.query("1<=a<=2 and 3<=b<=4"))
def test_box_selection_callback(self, df_type): bnac = BaseNonAggregate() bnac.x = "a" bnac.y = "b" bnac.chart_type = "temp" self.result = None def t_function(data, patch_update=False): self.result = data bnac.reload_chart = t_function df = initialize_df(df_type, {"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) dashboard._active_view = bnac class evt: bounds = (1, 2, 3, 4) x_selection = (1, 2) y_selection = (3, 4) t = bnac.get_box_select_callback(dashboard) t(evt.bounds, evt.x_selection, evt.y_selection) assert df_equals(self.result, df.query("1<=a<=2 and 3<=b<=4"))
def test_query_chart_by_range(self, df_type): bnac = BaseNonAggregate() bnac.chart_type = "test" bnac.x = "a" bnac_1 = BaseNonAggregate() bnac_1.chart_type = "test" bnac_1.x = "b" query_tuple = (4, 5) df = initialize_df(df_type, {"a": [1, 2, 3, 4], "b": [3, 4, 5, 6]}) bnac.source = df self.result = None self.patch_update = None def t_func(data, patch_update): self.result = data self.patch_update = patch_update # creating a dummy reload chart fn as its not implemented in core # non aggregate chart class bnac.reload_chart = t_func bnac.query_chart_by_range(active_chart=bnac_1, query_tuple=query_tuple, datatile=None) assert df_equals( self.result, initialize_df(df_type, { "a": [2, 3], "b": [4, 5] }, [1, 2]), ) assert self.patch_update is False
def test_lasso_election_callback(self): bnac = BaseNonAggregate() bnac.x = "a" bnac.y = "b" bnac.chart_type = "temp" def t_function(data, patch_update=False): self.result = data bnac.reload_chart = t_function df = cudf.DataFrame({"a": [1, 2, 2], "b": [3, 4, 5]}) dashboard = DashBoard(dataframe=DataFrame.from_dataframe(df)) class evt: geometry = dict(x=[1, 1, 2], y=[1, 2, 1], type="poly") final = True t = bnac.get_selection_geometry_callback(dashboard) with mock.patch("cuspatial.point_in_polygon") as pip: pip.return_value = cudf.DataFrame( {"selection": [True, False, True]}) t(evt) assert pip.called