def test_supported_input(self):
        xyvalues = OrderedDict()
        y_python = xyvalues['python'] = [2, 3, 7, 5, 26]
        y_pypy = xyvalues['pypy'] = [12, 33, 47, 15, 126]
        y_jython = xyvalues['jython'] = [22, 43, 10, 25, 26]

        xyvaluesdf = pd.DataFrame(xyvalues)

        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            hm = create_chart(Line, _xy)
            builder = hm._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(list(xyvalues.keys())))
            assert_array_equal(builder._data['x'], [0, 1, 2, 3, 4])
            assert_array_equal(builder._data['y_python'], y_python)
            assert_array_equal(builder._data['y_pypy'], y_pypy)
            assert_array_equal(builder._data['y_jython'], y_jython)

        lvalues = [[2, 3, 7, 5, 26], [12, 33, 47, 15, 126], [22, 43, 10, 25, 26]]
        for _xy in [lvalues, np.array(lvalues)]:
            hm = create_chart(Line, _xy)
            builder = hm._builders[0]
            self.assertEqual(builder._groups, ['0', '1', '2'])
            assert_array_equal(builder._data['x'], [0, 1, 2, 3, 4])
            assert_array_equal(builder._data['y_0'], y_python)
            assert_array_equal(builder._data['y_1'], y_pypy)
            assert_array_equal(builder._data['y_2'], y_jython)
    def test_supported_input(self):
        now = datetime.datetime.now()
        delta = datetime.timedelta(minutes=1)
        dts = [now + delta*i for i in range(5)]
        xyvalues = OrderedDict({'Date': dts})
        y_python = xyvalues['python'] = [2, 3, 7, 5, 26]
        y_pypy = xyvalues['pypy'] = [12, 33, 47, 15, 126]
        y_jython = xyvalues['jython'] = [22, 43, 10, 25, 26]

        xyvaluesdf = pd.DataFrame(xyvalues)
        groups = ['python', 'pypy', 'jython']
        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            ts = create_chart(TimeSeries, _xy, index='Date')
            builder = ts._builders[0]
            self.assertEqual(builder._groups, groups)
            assert_array_equal(builder._data['x_python'], dts)
            assert_array_equal(builder._data['x_pypy'], dts)
            assert_array_equal(builder._data['x_jython'], dts)
            assert_array_equal(builder._data['y_python'], y_python)
            assert_array_equal(builder._data['y_pypy'], y_pypy)
            assert_array_equal(builder._data['y_jython'], y_jython)

        lvalues = [[2, 3, 7, 5, 26], [12, 33, 47, 15, 126], [22, 43, 10, 25, 26]]
        for _xy in [lvalues, np.array(lvalues)]:
            hm = create_chart(TimeSeries, _xy, index=dts)
            builder = hm._builders[0]
            self.assertEqual(builder._groups, ['0', '1', '2'])
            assert_array_equal(builder._data['x_0'], dts)
            assert_array_equal(builder._data['x_1'], dts)
            assert_array_equal(builder._data['x_2'], dts)
            assert_array_equal(builder._data['y_0'], y_python)
            assert_array_equal(builder._data['y_1'], y_pypy)
            assert_array_equal(builder._data['y_2'], y_jython)
    def test_supported_input(self):
        xyvalues = OrderedDict()
        xyvalues['apples'] = [4,5,8]
        xyvalues['bananas'] = [1,2,4]
        xyvalues['pears'] = [6,5,4]

        xyvaluesdf = pd.DataFrame(xyvalues, index=['2009', '2010', '2011'])

        # prepare some data to check tests results...
        heights = widths = [0.95] * 9
        colors = ['#e2e2e2', '#75968f', '#cc7878', '#ddb7b1', '#a5bab7', '#ddb7b1',
            '#550b1d', '#e2e2e2', '#e2e2e2']
        catx = ['apples', 'bananas', 'pears', 'apples', 'bananas', 'pears',
                'apples', 'bananas', 'pears']
        rates = [4, 1, 6, 5, 2, 5, 8, 4, 4]

        caty = ['a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c']
        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            hm = create_chart(HeatMap, _xy, palette=colors)
            builder = hm._builders[0]
            # TODO: Fix bug
            #self.assertEqual(sorted(hm.groups), sorted(list(xyvalues.keys())))
            assert_array_equal(builder._data['height'], heights)
            assert_array_equal(builder._data['width'], widths)
            assert_array_equal(builder._data['catx'], catx)
            assert_array_equal(builder._data['rate'], rates)
            assert_array_equal(builder._source._data, builder._data)
            assert_array_equal(hm.x_range.factors, builder._catsx)
            assert_array_equal(hm.y_range.factors, builder._catsy)
            self.assertIsInstance(hm.x_range, FactorRange)
            self.assertIsInstance(hm.y_range, FactorRange)

            # TODO: (bev) not sure what correct behaviour is
            #assert_array_equal(builder._data['color'], colors)

            if i == 0: # if DataFrame
                assert_array_equal(builder._data['caty'], caty)
            else:
                _caty = ['2009']*3 + ['2010']*3 + ['2011']*3
                assert_array_equal(builder._data['caty'], _caty)


        catx = ['0', '1', '2', '0', '1', '2', '0', '1', '2']
        lvalues = [[4,5,8], [1,2,4], [6,5,4]]
        for _xy in [lvalues, np.array(lvalues)]:
            hm = create_chart(HeatMap, _xy, palette=colors)
            builder = hm._builders[0]

            # TODO: FIX bug
            #self.assertEqual(sorted(hm.groups), sorted(list(xyvalues.keys())))
            assert_array_equal(builder._data['height'], heights)
            assert_array_equal(builder._data['width'], widths)
            assert_array_equal(builder._data['catx'], catx)
            assert_array_equal(builder._data['rate'], rates)
            assert_array_equal(builder._source._data, builder._data)
            assert_array_equal(hm.x_range.factors, builder._catsx)
            assert_array_equal(hm.y_range.factors, builder._catsy)
            self.assertIsInstance(hm.x_range, FactorRange)
            self.assertIsInstance(hm.y_range, FactorRange)
            assert_array_equal(builder._data['caty'], caty)
    def test_supported_input(self):
        xyvalues = OrderedDict()
        xyvalues['python'] = [2, 5]
        xyvalues['pypy'] = [12, 40]
        xyvalues['jython'] = [22, 30]

        for i, _xy in enumerate([xyvalues,
                                 dict(xyvalues),
                                 pd.DataFrame(xyvalues)]):
            bar = create_chart(Bar, _xy)
            builder = bar._builders[0]
            np.testing.assert_array_equal(builder._data['pypy'], np.array(xyvalues['pypy']))
            np.testing.assert_array_equal(builder._data['python'], np.array(xyvalues['python']))
            np.testing.assert_array_equal(builder._data['jython'], np.array(xyvalues['jython']))

            # test mid values, that should always be y/2 ..
            np.testing.assert_array_equal(builder._data['midpython'], np.array([1, 2.5]))
            np.testing.assert_array_equal(builder._data['midpypy'], np.array([6, 20]))
            np.testing.assert_array_equal(builder._data['midjython'], np.array([11, 15]))

            # stacked values should be 0 as base and + y/2 of the column
            # skipping plain dict case as stacked values randomly fails due to
            # dictionary unordered nature
            if i != 1:
                np.testing.assert_array_equal(builder._data['stackedpython'], np.array([1, 2.5]))
                np.testing.assert_array_equal(builder._data['stackedpypy'], np.array([8, 25]))
                np.testing.assert_array_equal(builder._data['stackedjython'], np.array([25, 60]))

            np.testing.assert_array_equal(builder._data['cat'], np.array(['0', '1']))
            np.testing.assert_array_equal(builder._data['width'], np.array([0.8, 0.8]))
            np.testing.assert_array_equal(builder._data['width_cat'], np.array([0.2, 0.2]))

        lvalues = [[2, 5], [12, 40], [22, 30]]
        for i, _xy in enumerate([lvalues, np.array(lvalues)]):
            bar = create_chart(Bar, _xy)
            builder = bar._builders[0]
            np.testing.assert_array_equal(builder._data['0'], np.array(lvalues[0]))
            np.testing.assert_array_equal(builder._data['1'], np.array(lvalues[1]))
            np.testing.assert_array_equal(builder._data['2'], np.array(lvalues[2]))

            # test mid values, that should always be y/2 ..
            np.testing.assert_array_equal(builder._data['mid0'], np.array([1, 2.5]))
            np.testing.assert_array_equal(builder._data['mid1'], np.array([6, 20]))
            np.testing.assert_array_equal(builder._data['mid2'], np.array([11, 15]))

            # stacked values should be 0 as base and + y/2 of the column
            np.testing.assert_array_equal(builder._data['stacked0'], np.array([1, 2.5]))
            np.testing.assert_array_equal(builder._data['stacked1'], np.array([8, 25]))
            np.testing.assert_array_equal(builder._data['stacked2'], np.array([25, 60]))

            np.testing.assert_array_equal(builder._data['cat'], np.array(['0', '1']))
            np.testing.assert_array_equal(builder._data['width'], np.array([0.8, 0.8]))
            np.testing.assert_array_equal(builder._data['width_cat'], np.array([0.2, 0.2]))
    def test_supported_input(self):
        xyvalues = OrderedDict(
                python=[2, 3, 7, 5, 26],
                pypy=[12, 33, 47, 15, 126],
                jython=[22, 43, 10, 25, 26],
            )

        # prepare some data to check tests results...
        zeros = np.zeros(5)
        x = np.array([4,3,2,1,0,0,1,2,3,4])
        y_jython = np.hstack((zeros, np.array(xyvalues['jython'])))
        y_pypy = np.hstack((zeros, np.array(xyvalues['pypy'])))
        y_python = np.hstack((zeros, np.array(xyvalues['python'])))

        data_keys = ['x', 'y_jython', 'y_pypy', 'y_python']
        for _xy in [xyvalues, dict(xyvalues), pd.DataFrame(xyvalues)]:
            area = create_chart(Area, _xy)
            builder = area._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(list(xyvalues.keys())))
            self.assertListEqual(sorted(builder._data.keys()), data_keys)
            assert_array_equal(builder._data['x'], x)
            assert_array_equal(builder._data['y_jython'], y_jython)
            assert_array_equal(builder._data['y_pypy'], y_pypy)
            assert_array_equal(builder._data['y_python'], y_python)

            self.assertIsInstance(area.x_range, DataRange1d)
            self.assertIsInstance(area.y_range, Range1d)
            assert_array_almost_equal(area.y_range.start, -12.6, decimal=4)
            assert_array_almost_equal(area.y_range.end, 138.6, decimal=4)
            self.assertEqual(builder._source._data, builder._data)

        data_keys = ['x', 'y_0', 'y_1', 'y_2']
        lvalues = [[2, 3, 7, 5, 26], [12, 33, 47, 15, 126], [22, 43, 10, 25, 26]]
        y_0, y_1, y_2 = y_python, y_pypy, y_jython
        for _xy in [lvalues, np.array(lvalues)]:
            area = create_chart(Area, _xy)
            builder = area._builders[0]

            self.assertEqual(builder._groups, ['0', '1', '2'])
            self.assertListEqual(sorted(builder._data.keys()), data_keys)
            assert_array_equal(builder._data['x'], x)
            assert_array_equal(builder._data['y_0'], y_0)
            assert_array_equal(builder._data['y_1'], y_1)
            assert_array_equal(builder._data['y_2'], y_2)

            self.assertIsInstance(area.x_range, DataRange1d)
            self.assertIsInstance(area.y_range, Range1d)
            assert_array_almost_equal(area.y_range.start, -12.6, decimal=4)
            assert_array_almost_equal(area.y_range.end, 138.6, decimal=4)
            self.assertEqual(builder._source._data, builder._data)
    def test_histogram_params(self, histogram_mock):
        inputs = [[5, 0, 0.5, True], [3, 1, 0, False]]
        normal = [1, 2, 3, 1]
        lognormal = [5, 4, 4, 1]
        xyvalues = OrderedDict()
        xyvalues['normal'] = normal
        xyvalues['lognormal'] = lognormal

        for (bins, mu, sigma, dens) in inputs:
            histogram_mock.reset_mock()
            kws = dict(bins=bins, mu=mu, sigma=sigma, density=dens)
            hm = create_chart(Histogram, xyvalues, compute_values=False, **kws)
            builder = hm._builders[0]
            # ensure all class attributes have been correctly set
            for key, value in kws.items():
                self.assertEqual(getattr(builder, key), value)

            builder._process_data()
            # ensure we are calling numpy.histogram with the right args
            calls = histogram_mock.call_args_list
            assert_array_equal(calls[0][0][0], np.array([1, 2, 3, 1]))
            assert_array_equal(calls[1][0][0], np.array([5, 4, 4, 1]))
            self.assertEqual(calls[0][1]['bins'], bins)
            self.assertEqual(calls[1][1]['bins'], bins)
            self.assertEqual(calls[0][1]['density'], dens)
            self.assertEqual(calls[1][1]['density'], dens)
 def test_all_positive_input(self):
     source = OrderedDict()
     source['percent change 1'] = [1, 13]
     source['percent change 2'] = [12, 40]
     bar_chart = create_chart(Bar, source)
     self.assertEqual(bar_chart._builders[0].y_range.start, 0)
     self.assertEqual(bar_chart._builders[0].y_range.end, 40 * 1.1)
 def test_mixed_sign_input(self):
     source = OrderedDict()
     source['percent change 1'] = [-1, -13]
     source['percent change 2'] = [12, 40]
     bar_chart = create_chart(Bar, source)
     self.assertEqual(bar_chart._builders[0].y_range.start, -13 * 1.1)
     self.assertEqual(bar_chart._builders[0].y_range.end, 40 * 1.1)
 def test_all_negative_input(self):
     source = OrderedDict()
     source['percent change 1'] = [-1, -13]
     source['percent change 2'] = [-12, -40]
     bar_chart = create_chart(Bar, source)
     # We want the start to be negative, so that data points downwards
     self.assertEqual(bar_chart._builders[0].y_range.start, -40 * 1.1)
     self.assertEqual(bar_chart._builders[0].y_range.end, 0)
 def test_set_custom_continuous_range(self):
     # Users can specify their own y_range for cases where the
     # default guess is not what's desired.
     source = OrderedDict()
     source['percent change 1'] = [25, -13]
     source['percent change 2'] = [-12, -40]
     custom_y_range = Range1d(50, -50)
     bar_chart = create_chart(Bar, source, continuous_range=custom_y_range)
     self.assertEqual(bar_chart._builders[0].y_range, custom_y_range)
    def test_supported_input(self):
        xyvalues = OrderedDict()
        # TODO: Fix bug for donut breaking when inputs that are not float
        xyvalues["python"] = [2.0, 5.0, 3.0]
        xyvalues["pypy"] = [4.0, 1.0, 4.0]
        xyvalues["jython"] = [6.0, 4.0, 3.0]

        xyvalues_int = OrderedDict()
        for k, values in xyvalues.items():
            xyvalues_int[k] = [int(val) for val in values]

        for xyvalues in [xyvalues, xyvalues_int]:
            cat = ["sets", "dicts", "odicts"]
            start = [0, 2.3561944901923448, 4.3196898986859651]
            end = [2.3561944901923448, 4.3196898986859651, 6.2831853071795862]
            colors = ["#f22c40", "#5ab738", "#407ee7"]

            # TODO: Chart is not working with DataFrames anymore.
            #       Fix it and add test case for , pd.DataFrame(xyvalues)
            for i, _xy in enumerate([xyvalues]):
                _chart = create_chart(Donut, _xy, cat=cat)
                builder = _chart._builders[0]
                self.assertEqual(builder._groups, cat)
                assert_array_equal(builder._data["start"], start)
                assert_array_equal(builder._data["end"], end)
                assert_array_equal(builder._data["colors"], colors)

                # TODO: Test for external ring source values is missing as it needs
                #       some refactoring to expose those values calculation

        lvalues = [[2.0, 5.0, 3.0], [4.0, 1.0, 4.0], [6.0, 4.0, 3.0]]
        lvalues_int = [[2, 5, 3], [4, 1, 4], [6, 4, 3]]
        for lvalues in [lvalues, lvalues_int]:
            for i, _xy in enumerate([lvalues, np.array(lvalues)]):
                _chart = create_chart(Donut, _xy, cat=cat)
                builder = _chart._builders[0]
                self.assertEqual(builder._groups, cat)
                assert_array_equal(builder._data["start"], start)
                assert_array_equal(builder._data["end"], end)
                assert_array_equal(builder._data["colors"], colors)
    def test_supported_input(self):
        normal = [1, 2, 3, 1]
        lognormal = [5, 4, 4, 1]
        xyvalues = OrderedDict(normal=normal, lognormal=lognormal)

        xyvaluesdf = pd.DataFrame(xyvalues)

        exptected = dict(
            leftnormal=[1., 1.4, 1.8, 2.2, 2.6],
            rightnormal=[1.4, 1.8, 2.2, 2.6, 3.],
            lognormal=[5, 4, 4, 1],
            edgeslognormal=[1., 1.8, 2.6, 3.4, 4.2, 5.],
            bottomlognormal=[0, 0, 0, 0, 0],
            bottomnormal=[0, 0, 0, 0, 0],
            edgesnormal=[1., 1.4, 1.8, 2.2, 2.6, 3.],
            histlognormal=[0.3125, 0., 0., 0.625, 0.3125],
            leftlognormal=[1., 1.8, 2.6, 3.4, 4.2],
            normal=[1, 2, 3, 1],
            rightlognormal=[1.8, 2.6, 3.4, 4.2, 5.],
            histnormal=[1.25, 0., 0.625, 0., 0.625],
        )

        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            hm = create_chart(Histogram, _xy, bins=5)
            builder = hm._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(list(xyvalues.keys())))
            for key, expected_v in exptected.items():
                assert_array_almost_equal(builder._data[key], expected_v, decimal=2)

        lvalues = [[1, 2, 3, 1], [5, 4, 4, 1]]
        for i, _xy in enumerate([lvalues, np.array(lvalues)]):
            hm = create_chart(Histogram, _xy, bins=5)
            builder = hm._builders[0]
            self.assertEqual(builder._groups, ['0', '1'])
            for key, expected_v in exptected.items():
                # replace the keys because we have 0, 1 instead of normal and lognormal
                key = key.replace('lognormal', '1').replace('normal', '0')
                assert_array_almost_equal(builder._data[key], expected_v, decimal=2)
    def test_supported_input(self):
        xyvalues = OrderedDict()
        xyvalues['python'] = [(1, 2), (3, 3), (4, 7), (5, 5), (8, 26)]
        xyvalues['pypy'] = [(1, 12), (2, 23), (4, 47), (5, 15), (8, 46)]
        xyvalues['jython'] = [(1, 22), (2, 43), (4, 10), (6, 25), (8, 26)]

        xyvaluesdf = pd.DataFrame(xyvalues)

        y_python = [2, 3, 7, 5, 26]
        y_pypy = [12, 23, 47, 15, 46]
        y_jython = [22, 43, 10, 25, 26]
        x_python = [1, 3, 4, 5, 8]
        x_pypy = [1, 2, 4, 5, 8]
        x_jython = [1, 2, 4, 6, 8]

        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            hm = create_chart(Scatter, _xy)
            builder = hm._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(list(xyvalues.keys())))
            assert_array_equal(builder._data['y_python'], y_python)
            assert_array_equal(builder._data['y_jython'], y_jython)
            assert_array_equal(builder._data['y_pypy'], y_pypy)
            assert_array_equal(builder._data['x_python'], x_python)
            assert_array_equal(builder._data['x_jython'], x_jython)
            assert_array_equal(builder._data['x_pypy'], x_pypy)

        lvalues = [xyvalues['python'], xyvalues['pypy'], xyvalues['jython']]
        for _xy in [lvalues, np.array(lvalues)]:
            hm = create_chart(Scatter, _xy)
            builder = hm._builders[0]
            self.assertEqual(builder._groups, ['0', '1', '2'])
            assert_array_equal(builder._data['y_0'], y_python)
            assert_array_equal(builder._data['y_1'], y_pypy)
            assert_array_equal(builder._data['y_2'], y_jython)
            assert_array_equal(builder._data['x_0'], x_python)
            assert_array_equal(builder._data['x_1'], x_pypy)
            assert_array_equal(builder._data['x_2'], x_jython)
    def test_supported_input(self):
        now = datetime.datetime.now()
        delta = datetime.timedelta(minutes=1)
        dts = [now + delta*i for i in range(6)]
        xyvalues = OrderedDict({'Date': dts})
        # Repeat the starting and trailing points in order to
        xyvalues['python'] = [-120, -120, -30, 50, 100, 103]
        xyvalues['pypy'] = [-75, -75, -33, 15, 126, 126]

        xyvaluesdf = pd.DataFrame(xyvalues)
        groups = ['python', 'pypy']
        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            ts = create_chart(Horizon, _xy, index='Date')
            builder = ts._builders[0]

            padded_date = [x for x in _xy['Date']]
            padded_date.insert(0, padded_date[0])
            padded_date.append(padded_date[-1])

            self.assertEqual(builder.num_folds, 3)
            self.assertEqual(builder._series, groups)
            self.assertEqual(builder._fold_height, 126.0 / 3)
            self.assertEqual(builder._groups, ['42.0', '-42.0', '84.0', '-84.0', '126.0', '-126.0'])
            assert_array_equal(builder._data['x_python'], padded_date)
            assert_array_equal(builder._data['x_pypy'], padded_date)
            assert_array_equal(builder._data['y_fold-3_python'], [63, 9, 9 ,63, 63, 63, 63, 63])
            assert_array_equal(builder._data['y_fold-2_python'], [63, 0, 0, 63, 63, 63, 63, 63])
            assert_array_equal(builder._data['y_fold-1_python'], [63, 0, 0, 18, 63, 63, 63, 63])
            assert_array_equal(builder._data['y_fold1_python'], [0, 0, 0, 0, 63, 63, 63, 0])
            assert_array_equal(builder._data['y_fold2_python'], [0, 0, 0, 0, 12, 63, 63, 0])
            assert_array_equal(builder._data['y_fold3_python'], [0, 0, 0, 0, 0, 24, 28.5, 0])
            assert_array_equal(builder._data['y_fold-3_pypy'], [126, 126, 126, 126, 126, 126, 126, 126])
            assert_array_equal(builder._data['y_fold-2_pypy'], [126, 76.5, 76.5, 126, 126, 126, 126, 126])
            assert_array_equal(builder._data['y_fold-1_pypy'], [126, 63, 63, 76.5, 126, 126, 126, 126])
            assert_array_equal(builder._data['y_fold1_pypy'], [63, 63, 63, 63, 85.5, 126, 126, 63])
            assert_array_equal(builder._data['y_fold2_pypy'], [63, 63, 63, 63, 63, 126, 126, 63])
            assert_array_equal(builder._data['y_fold3_pypy'], [63, 63, 63, 63, 63, 126, 126, 63])
    def test_supported_input(self):
        xyvalues = OrderedDict()
        xyvalues["python"] = [2, 5]
        xyvalues["pypy"] = [12, 40]
        xyvalues["jython"] = [22, 30]

        xyvaluesdf = pd.DataFrame(xyvalues, index=["lists", "loops"])

        cat = ["lists", "loops"]
        catjython = ["lists:0.75", "loops:0.75"]
        catpypy = ["lists:0.5", "loops:0.5"]
        catpython = ["lists:0.25", "loops:0.25"]
        python = seg_top_python = [2, 5]
        pypy = seg_top_pypy = [12, 40]
        jython = seg_top_jython = [22, 30]
        zero = [0, 0]

        for i, _xy in enumerate([xyvalues, xyvaluesdf]):
            hm = create_chart(Dot, _xy, cat=cat)
            builder = hm._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(list(xyvalues.keys())))
            assert_array_equal(builder._data["cat"], cat)
            assert_array_equal(builder._data["catjython"], catjython)
            assert_array_equal(builder._data["catpython"], catpython)
            assert_array_equal(builder._data["catpypy"], catpypy)

            assert_array_equal(builder._data["python"], python)
            assert_array_equal(builder._data["jython"], jython)
            assert_array_equal(builder._data["pypy"], pypy)

            assert_array_equal(builder._data["seg_top_python"], seg_top_python)
            assert_array_equal(builder._data["seg_top_jython"], seg_top_jython)
            assert_array_equal(builder._data["seg_top_pypy"], seg_top_pypy)

            assert_array_equal(builder._data["z_python"], zero)
            assert_array_equal(builder._data["z_pypy"], zero)
            assert_array_equal(builder._data["z_jython"], zero)
            assert_array_equal(builder._data["zero"], zero)

        lvalues = [[2, 5], [12, 40], [22, 30]]
        for _xy in [lvalues, np.array(lvalues)]:
            hm = create_chart(Dot, _xy, cat=cat)
            builder = hm._builders[0]

            self.assertEqual(builder._groups, ["0", "1", "2"])
            assert_array_equal(builder._data["cat"], cat)
            assert_array_equal(builder._data["cat0"], catpython)
            assert_array_equal(builder._data["cat1"], catpypy)
            assert_array_equal(builder._data["cat2"], catjython)
            assert_array_equal(builder._data["0"], python)
            assert_array_equal(builder._data["1"], pypy)
            assert_array_equal(builder._data["2"], jython)

            assert_array_equal(builder._data["seg_top_0"], seg_top_python)
            assert_array_equal(builder._data["seg_top_1"], seg_top_pypy)
            assert_array_equal(builder._data["seg_top_2"], seg_top_jython)

            assert_array_equal(builder._data["z_0"], zero)
            assert_array_equal(builder._data["z_1"], zero)
            assert_array_equal(builder._data["z_2"], zero)
            assert_array_equal(builder._data["zero"], zero)
 def test_no_outliers(self):
     xyvalues = [7.0, 7.0, 8.0, 8.0, 9.0, 9.0]
     bp = create_chart(BoxPlot, xyvalues, outliers=True)
     builder = bp._builders[0]
     outliers = builder._data_scatter['out_y']
     self.assertEqual(len(outliers), 0)
 def test_non_range1d_continuous_range_raises_value_error(self):
     source = OrderedDict({'p': [0, 1]})
     non_1d_range = FactorRange(factors=['a', 'b'])
     with self.assertRaises(ValueError):
         create_chart(Bar, source, continuous_range=non_1d_range)
 def test_invalid_continuous_range_raises_error(self):
     source = OrderedDict({'p': [0, 1]})
     bad_y_range = range(0, 50)  # Not a Range object
     with self.assertRaises(ValueError):
         create_chart(Bar, source, continuous_range=bad_y_range)
    def test_supported_input(self):
        xyvalues = OrderedDict([
            ('bronze', np.array([7.0, 10.0, 8.0, 7.0, 4.0, 4.0, 1.0, 5.0, 2.0, 1.0,
                        4.0, 2.0, 1.0, 2.0, 4.0, 1.0, 0.0, 1.0, 1.0, 2.0,
                        0.0, 1.0, 0.0, 0.0, 1.0, 1.0])),
            ('silver', np.array([8., 4., 6., 4., 8., 3., 3., 2., 5., 6.,
                        1., 4., 2., 3., 2., 0., 0., 1., 2., 1.,
                        3.,  0.,  0.,  1.,  0.,  0.])),
            ('gold', np.array([6., 6., 6., 8., 4., 8., 6., 3., 2., 2.,  2.,  1.,
                      3., 1., 0., 5., 4., 2., 0., 0., 0., 1., 1., 0., 0.,
                      0.]))
        ])
        groups = ['bronze', 'silver', 'gold']
        xyvaluesdf = pd.DataFrame(xyvalues)
        xyvaluesbl = blaze.Data(xyvaluesdf)
        exptected_datarect = {
            'colors': ['#f22c40', '#5ab738', '#407ee7'],
            'groups': ['bronze', 'silver', 'gold'],
            'iqr_centers': [2.5, 2.5, 2.5],
            'iqr_lengths': [3.0, 3.0, 4.5],
            'lower_center_boxes': [1.25, 1.5, 1.125],
            'lower_height_boxes': [0.5, 1.0, 1.75],
            'upper_center_boxes': [2.75, 3.0, 3.375],
            'upper_height_boxes': [2.5, 2.0, 2.75],
            'width': [0.8, 0.8, 0.8]
        }
        expected_scatter = {
            'colors': ['#f22c40'],
            'out_x': ['bronze'],
            'out_y': [10.0]
        }
        expected_seg = {
            'lower': [-3.5, -3.5, -6.5],
             'q0': [1.0, 1.0, 0.25],
             'q2': [4.0, 4.0, 4.75],
             'upper': [8.5, 8.5, 11.5]
        }

        for i, _xy in enumerate([xyvalues, xyvaluesdf, xyvaluesbl]):
            bp = create_chart(BoxPlot, _xy, marker='circle', outliers=True)
            builder = bp._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(groups))
            for key, expected_v in exptected_datarect.items():
                self.assertEqual(builder._data_rect[key], expected_v)

            for key, expected_v in expected_scatter.items():
                self.assertEqual(builder._data_scatter[key], expected_v)

            for key, expected_v in expected_seg.items():
                self.assertEqual(builder._data_segment[key], expected_v)

        lvalues = [
            np.array([7.0, 10.0, 8.0, 7.0, 4.0, 4.0, 1.0, 5.0, 2.0, 1.0,
                    4.0, 2.0, 1.0, 2.0, 4.0, 1.0, 0.0, 1.0, 1.0, 2.0,
                    0.0, 1.0, 0.0, 0.0, 1.0, 1.0]),
            np.array([8., 4., 6., 4., 8., 3., 3., 2., 5., 6.,
                    1., 4., 2., 3., 2., 0., 0., 1., 2., 1.,
                    3.,  0.,  0.,  1.,  0.,  0.]),
            np.array([6., 6., 6., 8., 4., 8., 6., 3., 2., 2.,  2.,  1.,
                    3., 1., 0., 5., 4., 2., 0., 0., 0., 1., 1., 0., 0.,
                    0.])
        ]

        groups = exptected_datarect['groups'] = ['0', '1', '2']
        expected_scatter['out_x'] = ['0']
        for i, _xy in enumerate([lvalues, np.array(lvalues)]):
            bp = create_chart(BoxPlot, _xy, marker='circle', outliers=True)
            builder = bp._builders[0]
            self.assertEqual(sorted(builder._groups), sorted(groups))
            for key, expected_v in exptected_datarect.items():
                self.assertEqual(builder._data_rect[key], expected_v)

            for key, expected_v in expected_scatter.items():
                self.assertEqual(builder._data_scatter[key], expected_v)

            for key, expected_v in expected_seg.items():
                self.assertEqual(builder._data_segment[key], expected_v)