Exemplo n.º 1
0
def test_list_to_numpy():
    ds = datashape.dshape('3 * int32')
    x = list_to_numpy([1, 2, 3], dshape=ds)
    assert (x == [1, 2, 3]).all()
    assert isinstance(x, np.ndarray)

    ds = datashape.dshape('3 * ?int32')
    x = list_to_numpy([1, None, 3], dshape=ds)
    assert np.isnan(x[1])
Exemplo n.º 2
0
def test_list_to_numpy():
    ds = datashape.dshape('3 * int32')
    x = list_to_numpy([1, 2, 3], dshape=ds)
    assert (x == [1, 2, 3]).all()
    assert isinstance(x, np.ndarray)

    ds = datashape.dshape('3 * ?int32')
    x = list_to_numpy([1, None, 3], dshape=ds)
    assert np.isnan(x[1])
Exemplo n.º 3
0
def test_list_to_numpy_on_dicts():
    data = [{'name': 'Alice', 'amount': 100}, {'name': 'Bob', 'amount': 200}]
    ds = datashape.dshape('var * {name: string[5], amount: int}')
    x = list_to_numpy(data, dshape=ds)
    assert convert(list, x) == [('Alice', 100), ('Bob', 200)]
Exemplo n.º 4
0
def test_list_to_numpy_on_tuples():
    data = [['a', 1], ['b', 2], ['c', 3]]
    ds = datashape.dshape('var * (string[1], int32)')
    x = list_to_numpy(data, dshape=ds)
    assert convert(list, x) == [('a', 1), ('b', 2), ('c', 3)]
Exemplo n.º 5
0
def test_list_to_numpy_on_dicts():
    data = [{'name': 'Alice', 'amount': 100},
            {'name': 'Bob', 'amount': 200}]
    ds = datashape.dshape('var * {name: string[5], amount: int}')
    x = list_to_numpy(data, dshape=ds)
    assert convert(list, x) == [('Alice', 100), ('Bob', 200)]
Exemplo n.º 6
0
def test_list_to_numpy_on_tuples():
    data = [['a', 1], ['b', 2], ['c', 3]]
    ds = datashape.dshape('var * (string[1], int32)')
    x = list_to_numpy(data, dshape=ds)
    assert convert(list, x) == [('a', 1), ('b', 2), ('c', 3)]