Ejemplo n.º 1
0
def test_groupby(test_data):
    ds = ChartDataSource(df=test_data.auto_data)
    groups = list(ds.groupby(**test_data.single_col_spec))
    assert len(groups) == 5

    ds = ChartDataSource(df=test_data.auto_data)
    groups = list(ds.groupby(**test_data.multi_col_spec))
    assert len(groups) == 9
Ejemplo n.º 2
0
def test_pandas(test_data):
    """Test creating chart data source from existing dataframe."""
    ds = ChartDataSource.from_data(test_data.pd_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4

    ds = ChartDataSource(test_data.pd_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4
def test_pandas(test_data):
    """Test creating chart data source from existing dataframe."""
    pd_data = test_data.pd_data.copy()
    ds = ChartDataSource.from_data(pd_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4

    ds = ChartDataSource(pd_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4

    # Test for issue #3899
    # ChartDataSource shouldn't modify the input DataFrame
    assert pd_data.equals(test_data.pd_data)
Ejemplo n.º 4
0
def test_custom_derived_cols_from_df(test_data):
    """Wide dataframe columns assigned to y dimension for the chart.

    This tests using the NumericalColumnsAssigner, which is used for charts
    that prefer behavior of expecting series-like data. Typically the x axis
    is used as an index, then the y axis will be assigned multiple columns.
    """
    ds = ChartDataSource.from_data(test_data.pd_data, dims=('x', 'y'),
                                   column_assigner=NumericalColumnsAssigner)
    assert ds['y'] == ['col1', 'col2']
Ejemplo n.º 5
0
def test_groupby(test_data):
    ds = ChartDataSource(df=test_data.auto_data)
    groups = list(ds.groupby(**test_data.single_col_spec))
    assert len(groups) == 5

    ds = ChartDataSource(df=test_data.auto_data)
    groups = list(ds.groupby(**test_data.multi_col_spec))
    assert len(groups) == 9
Ejemplo n.º 6
0
    def _generate_items(self, df, columns):
        """Produce list of unique tuples that identify each item."""
        if not self.bin:
            super(ColorAttr, self)._generate_items(df, columns)
        else:

            if len(columns) == 1 and ChartDataSource.is_number(df[columns[0]]):

                self.bins = Bins(source=ColumnDataSource(df), column=columns[0],
                                 bin_count=len(self.iterable), aggregate=False)

                if self.sort:
                    self.bins.sort(ascending=self.ascending)

                self.items = [bin.label[0] for bin in self.bins]
            else:
                raise ValueError('Binned colors can only be created for one column of \
                                 numerical data.')
Ejemplo n.º 7
0
def test_groupby(test_data):
    # Note: this works because MarkerAttr and DashAttr are permissive in
    # what is accepted for iterable, i.e. List(String)
    for cls in (ColorAttr, MarkerAttr, DashAttr):
        single_col_spec = {'test': cls(df=test_data.auto_data, columns='cyl',
                                            name='test', iterable=['red', 'blue'])}
        multi_col_spec = {'test': cls(df=test_data.auto_data,
                                           columns=('cyl', 'origin'),
                                           name='test', iterable=['red', 'blue'])}

        ds = ChartDataSource(df=test_data.auto_data)
        groups = list(ds.groupby(**single_col_spec))
        assert len(groups) == 5

        ds = ChartDataSource(df=test_data.auto_data)
        groups = list(ds.groupby(**multi_col_spec))
        assert len(groups) == 9
Ejemplo n.º 8
0
def test_derived_cols_from_lists(test_data):
    """List of lists for dimension results in column derivation."""
    ds = ChartDataSource.from_data(test_data.array_data, dims=('y', 'x'))
    assert ds['y'] == ['a', 'b']
Ejemplo n.º 9
0
def test_derived_selections(test_data):
    ds = ChartDataSource.from_data(*test_data.array_data)
    try:
        [[ds[dim] for dim in req_dims] for req_dims in ds._required_dims]
    except KeyError:
        pytest.fail('Required dimension not correctly set by ChartDataSource.')
Ejemplo n.º 10
0
def test_records(test_data):
    """Test creating chart data source from array of dicts."""
    ds = ChartDataSource.from_data(test_data.records_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4
Ejemplo n.º 11
0
def test_dict(test_data):
    """Test creating chart data source from dict of arrays."""
    ds = ChartDataSource.from_data(test_data.dict_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4
Ejemplo n.º 12
0
def test_array(test_data):
    """Test creating chart data source from array-like numpy data."""
    ds = ChartDataSource.from_data(*test_data.array_data)
    assert len(ds.columns) == 2
    assert len(ds.index) == 4