

def test_hist():
    data = dict(x=[1, 2, 3], y=[4, 5, 6])
    viz1 = api.Viz(data).hist(x='x')
    assert (viz1.encoding.x.name == 'x')
    assert (viz1.encoding.x.bin.maxbins == 10)
    assert (viz1.encoding.y.name == 'x')
    assert (viz1.encoding.y.type == 'Q')
    assert (viz1.encoding.y.aggregate == 'count')
    viz2 = api.Viz(viz3).hist(x='x', bins=30)
    assert (viz2.encoding.x.bin.maxbins == 30)
    expected = {
        'config': {
            'gridColor': 'black',
            'gridOpacity': 0.08,
            'height': 400,
            'width': 600,
        },
        'data': {
            'formatType': 'json',
            'values': [{
                'x': 1,
                'y': 4,
            }, {
                'x': 2,
                'y': 5,
            }, {
                'x': 3,
                'y': 6,
            }],
        },
        'encoding': {
            'x': {
                'bin': {
                    'maxbins': 30,
                },
                'name': 'x',
                'type': 'Q',
            },
            'y': {
                'aggregate': 'count',
                'bin': False,
                'name': 'x',
                'type': 'Q',
            },
        },
        'marktype': 'bar',
    }
    assert (viz2.to_dict() == expected)
    viz3 = api.Viz(data).hist(x='x:O', color=api.Color(shorthand='bar', type='N'))
    assert (viz3.encoding.x.name == 'x')
    assert (viz3.encoding.x.type == 'O')
    expected = {
        'config': {
            'gridColor': 'black',
            'gridOpacity': 0.08,
            'height': 400,
            'width': 600,
        },
        'data': {
            'formatType': 'json',
            'values': [{
                'x': 1,
                'y': 4,
            }, {
                'x': 2,
                'y': 5,
            }, {
                'x': 3,
                'y': 6,
            }],
        },
        'encoding': {
            'x': {
                'bin': {
                    'maxbins': 10,
                },
                'name': 'x',
                'type': 'O',
            },
            'y': {
                'aggregate': 'count',
                'bin': False,
                'name': 'x',
                'type': 'Q',
            },
            'color': {
                'bin': False,
                'name': 'bar',
                'opacity': 1.0,
                'type': 'N',
                'value': '#4682b4',
                'legend': True,
            },
        },
        'marktype': 'bar',
    }
    assert (viz3.to_dict() == expected)
    viz4 = api.Viz(data).hist(x=api.X(shorthand='x', bin=api.Bin(maxbins=40)))
    assert (viz4.encoding.x.name == 'x')
    assert (viz4.encoding.x.bin.maxbins == 40)

dataset/ETHPy150Open ellisonbg/altair/altair/tests/test_api.py test_hist/VarMisuse@123/145 `data`->`viz3`