Exemplo n.º 1
0
    def test_data_column_lengths(self):
        # TODO: use this when soft=False
        #
        #with self.assertRaises(ValueError):
        #    ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
        #
        #ds = ColumnDataSource()
        #with self.assertRaises(ValueError):
        #    ds.data = dict(a=[10, 11], b=[20, 21, 22])
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11]))
        #with self.assertRaises(ValueError):
        #    ds.data["b"] = [20, 21, 22]
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        #with self.assertRaises(ValueError):
        #    ds.data.update(dict(a=[10, 11, 12]))

        with warnings.catch_warnings(record=True) as warns:
            ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
            self.assertEquals(len(warns), 1)
            self.assertEquals(
                str(warns[0].message),
                "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"
            )

        ds = ColumnDataSource()
        with warnings.catch_warnings(record=True) as warns:
            ds.data = dict(a=[10, 11], b=[20, 21, 22])
            self.assertEquals(len(warns), 1)
            self.assertEquals(
                str(warns[0].message),
                "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"
            )

        ds = ColumnDataSource(data=dict(a=[10, 11]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data["b"] = [20, 21, 22]
            self.assertEquals(len(warns), 1)
            self.assertEquals(
                str(warns[0].message),
                "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"
            )

        ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data.update(dict(a=[10, 11, 12]))
            self.assertEquals(len(warns), 1)
            self.assertEquals(
                str(warns[0].message),
                "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 3), ('b', 2)"
            )
Exemplo n.º 2
0
 def test_data_accepts_dataframe_arg(self, pd):
     data = dict(a=[1, 2], b=[2, 3])
     df = pd.DataFrame(data)
     ds = ColumnDataSource()
     assert ds.data == {}
     ds.data = df
     assert set(df.columns).issubset(set(ds.column_names))
     for key in data.keys():
         assert isinstance(ds.data[key], np.ndarray)
         assert list(df[key]) == list(ds.data[key])
     assert isinstance(ds.data['index'], np.ndarray)
     assert [0, 1] == list(ds.data['index'])
     assert set(ds.column_names) - set(df.columns) == set(["index"])
Exemplo n.º 3
0
 def test_data_accepts_groupby_arg(self, pd):
     from bokeh.sampledata.autompg import autompg as df
     group = df.groupby(by=['origin', 'cyl'])
     ds = ColumnDataSource()
     assert ds.data == {}
     ds.data = group
     s = group.describe()
     assert len(ds.column_names) == 49
     assert isinstance(ds.data['origin_cyl'], np.ndarray)
     for key in s.columns.values:
         k2 = "_".join(key)
         assert isinstance(ds.data[k2], np.ndarray)
         assert list(s[key]) == list(ds.data[k2])
Exemplo n.º 4
0
 def test_data_accepts_dataframe_column_categoricalindex(self, pd):
     columns = pd.CategoricalIndex(['a', 'b'])
     data = [[0, 2], [1, 3]]
     df = pd.DataFrame(columns=columns, data=data)
     ds = ColumnDataSource()
     assert ds.data == {}
     ds.data = df
     assert set(df.columns).issubset(set(ds.column_names))
     for key in columns:
         assert isinstance(ds.data[key], np.ndarray)
         assert list(df[key]) == list(ds.data[key])
     assert isinstance(ds.data['index'], np.ndarray)
     assert [0, 1] == list(ds.data['index'])
     assert set(ds.column_names) - set(df.columns) == set(["index"])
Exemplo n.º 5
0
def make_ajax_query_plot(data):
    source_query = ColumnDataSource()
    source_query.data = data

    plot = figure(plot_height=300, sizing_mode='scale_width')
    plot.line('x', 'y', source=source_query, line_width=4)
    plot.circle('x',
                'y',
                source=source_query,
                size=8,
                fill_color="white",
                color="red")

    script, div = components(plot)
    return script, div
Exemplo n.º 6
0
 def test_data_accepts_groupby_with_None_subindex_name(self, pd):
     df = pd.DataFrame({
         "A": [1, 2, 3, 4] * 2,
         "B": [10, 20, 30, 40] * 2,
         "C": range(8)
     })
     group = df.groupby(['A', [10, 20, 30, 40] * 2])
     ds = ColumnDataSource()
     assert ds.data == {}
     ds.data = group
     s = group.describe()
     assert len(ds.column_names) == 17
     assert isinstance(ds.data['index'], np.ndarray)
     for key in s.columns.values:
         k2 = "_".join(key)
         assert isinstance(ds.data[k2], np.ndarray)
         assert list(s[key]) == list(ds.data[k2])
Exemplo n.º 7
0
    def test_data_column_lengths(self):
        # TODO: use this when soft=False
        #
        #with self.assertRaises(ValueError):
        #    ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
        #
        #ds = ColumnDataSource()
        #with self.assertRaises(ValueError):
        #    ds.data = dict(a=[10, 11], b=[20, 21, 22])
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11]))
        #with self.assertRaises(ValueError):
        #    ds.data["b"] = [20, 21, 22]
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        #with self.assertRaises(ValueError):
        #    ds.data.update(dict(a=[10, 11, 12]))

        with warnings.catch_warnings(record=True) as warns:
            ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
            self.assertEquals(len(warns), 1)
            self.assertEquals(str(warns[0].message), "ColumnDataSource's columns must be of the same length")

        ds = ColumnDataSource()
        with warnings.catch_warnings(record=True) as warns:
            ds.data = dict(a=[10, 11], b=[20, 21, 22])
            self.assertEquals(len(warns), 1)
            self.assertEquals(str(warns[0].message), "ColumnDataSource's columns must be of the same length")

        ds = ColumnDataSource(data=dict(a=[10, 11]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data["b"] = [20, 21, 22]
            self.assertEquals(len(warns), 1)
            self.assertEquals(str(warns[0].message), "ColumnDataSource's columns must be of the same length")

        ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data.update(dict(a=[10, 11, 12]))
            self.assertEquals(len(warns), 1)
            self.assertEquals(str(warns[0].message), "ColumnDataSource's columns must be of the same length")
Exemplo n.º 8
0
    def test_data_column_lengths(self):
        # TODO: use this when soft=False
        #
        #with pytest.raises(ValueError):
        #    ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
        #
        #ds = ColumnDataSource()
        #with pytest.raises(ValueError):
        #    ds.data = dict(a=[10, 11], b=[20, 21, 22])
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11]))
        #with pytest.raises(ValueError):
        #    ds.data["b"] = [20, 21, 22]
        #
        #ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        #with pytest.raises(ValueError):
        #    ds.data.update(dict(a=[10, 11, 12]))

        with warnings.catch_warnings(record=True) as warns:
            ColumnDataSource(data=dict(a=[10, 11], b=[20, 21, 22]))
        assert len(warns) == 1
        assert str(warns[0].message) == "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"

        ds = ColumnDataSource()
        with warnings.catch_warnings(record=True) as warns:
            ds.data = dict(a=[10, 11], b=[20, 21, 22])
        assert len(warns) == 1
        assert str(warns[0].message) == "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"

        ds = ColumnDataSource(data=dict(a=[10, 11]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data["b"] = [20, 21, 22]
        assert len(warns) == 1
        assert str(warns[0].message) == "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 2), ('b', 3)"

        ds = ColumnDataSource(data=dict(a=[10, 11], b=[20, 21]))
        with warnings.catch_warnings(record=True) as warns:
            ds.data.update(dict(a=[10, 11, 12]))
        assert len(warns) == 1
        assert str(warns[0].message) == "ColumnDataSource's columns must be of the same length. Current lengths: ('a', 3), ('b', 2)"