def test_set_color(self): bc = BaseChart() library_specific_params = {"color": "blue"} bc.library_specific_params = library_specific_params bc.set_color() assert bc.color == "blue"
def test_variables(self): bc = BaseChart() assert bc.chart_type is None assert bc.x is None assert bc.y is None assert bc.aggregate_fn == "count" assert bc.color is None assert bc.height == 0 assert bc.width == 0 assert bc.add_interaction is True assert bc.chart is None assert bc.source is None assert bc.source_backup is None assert bc.data_points == 0 assert bc._library_specific_params == {} assert bc._stride is None assert bc.stride_type == int assert bc.min_value == 0.0 assert bc.max_value == 0.0 assert bc.x_label_map == {} assert bc.y_label_map == {} bc.x = "test_x" bc.chart_type = "test_chart_type" assert bc.name == "test_x_test_chart_type"
def test_calc_data_tile(): df = cudf.DataFrame({ "key": [float(i) for i in range(5)] * 5, "val": [float(i * 2) for i in range(5, 0, -1)] * 5, }) active_chart, passive_chart = BaseChart(), BaseChart() active_chart.x, active_chart.min_value = "key", df["key"].min() active_chart.max_value, active_chart.stride = df["key"].max(), 1 passive_chart.x, passive_chart.min_value = "val", df["val"].min() passive_chart.max_value, passive_chart.stride = df["val"].max(), 1 cumsum = True return_result = gpu_datatile.calc_data_tile( df=df, active_view=active_chart, passive_view=passive_chart, cumsum=cumsum, ) result = pd.DataFrame({ 0: { 0: 0.0, 2: 0.0, 4: 0.0, 6: 0.0, 8: 5.0 }, 1: { 0: 0.0, 2: 0.0, 4: 0.0, 6: 5.0, 8: 5.0 }, 2: { 0: 0.0, 2: 0.0, 4: 5.0, 6: 5.0, 8: 5.0 }, 3: { 0: 0.0, 2: 5.0, 4: 5.0, 6: 5.0, 8: 5.0 }, 4: { 0: 5.0, 2: 5.0, 4: 5.0, 6: 5.0, 8: 5.0 }, }) assert return_result.equals(result)
def test_label_mappers(self): bc = BaseChart() library_specific_params = { "x_label_map": {"a": 1, "b": 2}, "y_label_map": {"a": 1, "b": 2}, } bc.library_specific_params = library_specific_params bc.extract_mappers() assert bc.x_label_map == {"a": 1, "b": 2} assert bc.y_label_map == {"a": 1, "b": 2}
def test_add_event(self): bc = BaseChart() from bokeh.events import ButtonClick from bokeh.models import Button def callback(event): print("Python:Click") bc.chart = Button() bc.add_event(ButtonClick, callback) assert ButtonClick.event_name in bc.chart.subscribed_events
def test_calc_groupby(aggregate_fn, result): df = cudf.DataFrame({ "key": [float(i) for i in range(5)] * 5, "val": [float(i * 2) for i in range(5, 0, -1)] * 5, }) bc = BaseChart() bc.x = "key" bc.y = "val" bc.stride = 1.0 bc.max_value = 4.0 bc.min_value = 0.0 bc.data_points = 25 bc.aggregate_fn = aggregate_fn assert np.array_equal(gpu_histogram.calc_groupby(bc, df), result)
def test_set_dimensions(self): bc = BaseChart() bc.chart = 1 bc.filter_widget = (BaseChart() ) # setting filter_widget to some chart object bc.width = 400 bc.height = 400 assert bc.width == 400 assert bc.filter_widget.width == 400 assert bc.height == 400
def test_aggregated_column_unique(): df = cudf.DataFrame({ "key": cuda.to_device( np.array([ 1, 5, 10, 15, 25, 27, 30, 23, 22, 35, 39, 99, 109, 109, 104, 11, 23, ] * 50)) }) bc = BaseChart() bc.x = "key" bc.stride = 1.0 bc.max_value = df["key"].max() bc.min_value = df["key"].min() assert np.array_equal( gpu_histogram.aggregated_column_unique(bc, df), np.array([0, 4, 9, 10, 14, 21, 22, 24, 26, 29, 34, 38, 98, 103, 108]), )
def test_calc_groupby_for_nulls(x, y, aggregate_fn, result): df = cudf.DataFrame({"key": [1, 2], "val": [np.NaN, 3]}) bc = BaseChart() bc.x = x bc.y = y bc.stride = 1.0 bc.min_value = df[x].min() bc.max_value = df[x].max() bc.aggregate_fn = aggregate_fn assert np.allclose( gpu_histogram.calc_groupby(bc, df).astype(np.float32), result.astype(np.float32), equal_nan=True, )
def test_calc_1d_data_tile(): df = cudf.DataFrame({ "key": [float(i) for i in range(5)] * 5, "val": [float(i * 2) for i in range(5, 0, -1)] * 5, }) active_chart, passive_chart = BaseChart(), BaseChart() active_chart.x = "key" active_chart.min_value = df["key"].min() active_chart.max_value = df["key"].max() active_chart.stride = 1 cumsum = True return_result = gpu_datatile.calc_1d_data_tile( df=df, active_view=active_chart, passive_view=passive_chart, cumsum=cumsum, ) result = pd.DataFrame({0: {0: 5.0, 1: 10.0, 2: 15.0, 3: 20.0, 4: 25.0}}) assert return_result.equals(result)
def test_umimplemented_fns(self): bc = BaseChart() assert bc.update_dimensions() == -1 assert bc.calculate_source(data={}) == -1 assert bc.generate_chart() == -1 assert bc.add_reset_event() == -1 assert bc.compute_query_dict(query_dict={}) == -1 assert bc.reset_chart() == -1 assert bc.reload_chart(data={}, patch_update=False) == -1 assert bc.reload_chart(data={}, patch_update=True) == -1 assert bc.format_source_data(source_dict={}, patch_update=False) == -1 assert bc.format_source_data(source_dict={}, patch_update=True) == -1 assert bc.apply_mappers() == -1 assert bc.get_source_y_axis() == []
def test_view(self, chart, _chart): bc = BaseChart() bc.chart = chart assert bc.view() == _chart
def test_stride(self, stride, _stride): bc = BaseChart() bc.stride = stride assert bc._stride == _stride