

def test_select_y():

    def _check(data, expected, aggregator=None):
        v = api.Viz(data)
        v.encode()
        v.encoding.x = 'col1'
        if (aggregator is None):
            v.select_y()
            assert (v.encoding.y.name == expected)
        else:
            v.select_y(None, aggregator)
            assert (v.encoding.y.name == expected)
            assert (v.encoding.y.aggregate == aggregator)
    data = dict(col1=[1.0, 2.0, 3.0], col2=['A', 'B', 'C'], col3=pd.date_range('2012', periods=3, freq='A'), col4=pd.date_range('2012', periods=3, freq='A'), col5=[1.0, 2.0, 3.0], col6=[1.0, 2.0, 3.0])
    _check(data, 'col5')
    _check(data, 'col5', 'avg')
    data = dict(col1=[1.0, 2.0, 3.0], col2=['A', 'B', 'C'], col3=pd.date_range('2012', periods=3, freq='A'), col4=['A', 'B', 'C'])
    _check(data, 'col2')
    _check(data, 'col2', 'sum')
    data = dict(col1=[1.0, 2.0, 3.0], col2=pd.date_range('2012', periods=3, freq='A'), col3=pd.date_range('2012', periods=3, freq='A'))
    _check(data, 'col2')
    _check(data, 'col2', 'sum')
    with pytest.raises(AssertionError):
        v = api.Viz(None)
        v.select_y()
    with pytest.raises(AssertionError):
        v = api.Viz(dict(col1=[1.0, 2.0]))
        v.select_y()
    with pytest.raises(AssertionError):
        v = api.Viz(dict(col1=[1.0, 2.0], col2=[1.0, 2.0]))
        v.select_y()
    with pytest.raises(AssertionError):
        v = api.Viz(dict(col1=[1.0, 2.0], col2=[1.0, 2.0]))
        v.encode()
        data.select_y()
    data = dict(col1=[1.0, 2.0, 3.0], col2=['A', 'B', 'C'], col3=pd.date_range('2012', periods=3, freq='A'), col4=pd.date_range('2012', periods=3, freq='A'), col5=[1.0, 2.0, 3.0], col6=[1.0, 2.0, 3.0])
    v = api.Viz(data)
    v.encode()
    v.encoding.x = 'col1'
    v.select_y(['N', 'T', 'Q', 'O'])
    assert (v.encoding.y.name == 'col2')

dataset/ETHPy150Open ellisonbg/altair/altair/tests/test_api.py test_select_y/VarMisuse@491/614 `v`->`data`