Beispiel #1
0
def test_array_concat_scalar(client, op, op_raw):
    raw_left = np.array([1, 2, 3])
    raw_right = np.array([3, 4])
    left = ibis.array(raw_left)
    right = ibis.array(raw_right)
    expr = op(left, right)
    result = client.execute(expr)
    expected = op_raw(raw_left, raw_right)
    tm.assert_numpy_array_equal(result, expected)
Beispiel #2
0
def test_series_to_ibis_literal(core_client):
    values = [1, 2, 3, 4]
    s = dd.from_pandas(pd.Series(values), npartitions=1)

    expr = ibis.array(s)

    assert expr.equals(ibis.array(values))

    assert core_client.execute(expr) == pytest.approx([1, 2, 3, 4])
Beispiel #3
0
def test_array_length_scalar(client):
    raw_value = np.array([1, 2, 4])
    value = ibis.array(raw_value)
    expr = value.length()
    result = client.execute(expr)
    expected = len(raw_value)
    assert result == expected
Beispiel #4
0
def test_array_index_scalar(client, index):
    raw_value = np.array([-10, 1, 2, 42])
    value = ibis.array(raw_value)
    expr = value[index]
    result = client.execute(expr)
    expected = raw_value[index] if index < len(raw_value) else None
    assert result == expected
Beispiel #5
0
def test_array_slice_scalar(client, start, stop):
    raw_value = np.array([-11, 42, 10])
    value = ibis.array(raw_value)
    expr = value[start:stop]
    result = client.execute(expr)
    expected = raw_value[start:stop]
    tm.assert_numpy_array_equal(result, expected)
Beispiel #6
0
def test_array_repeat_scalar(client, n, mul):
    raw_array = np.array([1, 2])
    array = ibis.array(raw_array)
    expr = mul(array, n)
    result = client.execute(expr)
    if n > 0:
        expected = np.tile(raw_array, n)
    else:
        expected = np.array([], dtype=raw_array.dtype)
    tm.assert_numpy_array_equal(result, expected)
Beispiel #7
0
def test_array_scalar(con):
    expr = ibis.array([1.0, 2.0, 3.0])
    assert isinstance(expr, ir.ArrayScalar)

    result = con.execute(expr)
    expected = np.array([1.0, 2.0, 3.0])

    # This does not check whether `result` is an np.array or a list,
    # because it varies across backends and backend configurations
    assert np.array_equal(result, expected)
Beispiel #8
0
def test_array_column(backend, alltypes, df):
    expr = ibis.array([alltypes['double_col'], alltypes['double_col']])
    assert isinstance(expr, ir.ArrayColumn)

    result = expr.execute()
    expected = df.apply(
        lambda row: [row['double_col'], row['double_col']],
        axis=1,
    )
    backend.assert_series_equal(result, expected, check_names=False)
Beispiel #9
0
def test_unnest_unnamed(con):
    array_types = con.table("array_types")
    df = array_types.execute()
    expr = (
        array_types.x.cast("!array<int64>")
        + ibis.array([1], type="!array<int64>")
    ).unnest()
    assert not expr.has_name()
    result = expr.name("x").execute()
    expected = df.x.map(lambda x: x + [1]).explode("x")
    tm.assert_series_equal(result, expected.astype("float64"))