Exemplo n.º 1
0
def test_table_specials():
    table = wandb.Table(
        columns=["image", "table"],
        optional=False,
        dtype=[data_types.Image, data_types.Table],
    )
    with pytest.raises(TypeError):
        table.add_data(None, None)

    # Infers specific types from first valid row
    table.add_data(
        data_types.Image(
            np.random.rand(10, 10),
            boxes=box_annotation,
            masks=mask_annotation,
        ),
        data_types.Table(data=[[1, True, None]]),
    )

    # Denies conflict
    with pytest.raises(TypeError):
        table.add_data(
            "hello",
            data_types.Table(data=[[1, True, None]]),
        )

    # Denies conflict
    with pytest.raises(TypeError):
        table.add_data(
            data_types.Image(
                np.random.rand(10, 10),
                boxes=box_annotation,
                masks=mask_annotation,
            ),
            data_types.Table(data=[[1, "True", None]]),
        )

    # allows further refinement
    table.add_data(
        data_types.Image(
            np.random.rand(10, 10),
            boxes=box_annotation,
            masks=mask_annotation,
        ),
        data_types.Table(data=[[1, True, 1]]),
    )

    # allows addition
    table.add_data(
        data_types.Image(
            np.random.rand(10, 10),
            boxes=box_annotation,
            masks=mask_annotation,
        ),
        data_types.Table(data=[[1, True, 1]]),
    )
Exemplo n.º 2
0
def test_table(history):
    history.add({"tbl": data_types.Table(
        rows=[["a", "b", "c"], ["d", "e", "f"]])})
    h = disk_history()
    assert h[0]["tbl"] == {'_type': 'table',
                           'columns': [u'Input', u'Output', u'Expected'],
                           'data': [[u'a', u'b', u'c'], [u'd', u'e', u'f']]}
Exemplo n.º 3
0
def test_table(history):
    history.add(
        {"tbl": data_types.Table(rows=[["a", "b", "c"], ["d", "e", "f"]])})
    h = disk_history(history)[0]["tbl"]
    assert h["_type"] == "table-file"
    path = h["path"]
    data = open(os.path.join(history._run.dir, path)).read()
    table_data = json.loads(data)
    assert table_data == {
        'columns': [u'Input', u'Output', u'Expected'],
        'data': [[u'a', u'b', u'c'], [u'd', u'e', u'f']]
    }