Ejemplo n.º 1
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
Ejemplo n.º 2
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']
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_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.º 5
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.º 6
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.º 7
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.º 8
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