Example #1
0
 def test_greatest(self):
     t = self.table
     cases = [
         (ibis.greatest(t.string_col, "foo"), "greatest(`string_col`, 'foo')"),
         (ibis.greatest(t.int_col, t.bigint_col), "greatest(`int_col`, `bigint_col`)"),
     ]
     self._check_expr_cases(cases)
Example #2
0
def test_greatest(con, alltypes, translate):
    expr = ibis.greatest(alltypes.int_col, 10)

    assert translate(expr) == "greatest(`int_col`, 10)"
    assert len(con.execute(expr))

    expr = ibis.greatest(alltypes.int_col, alltypes.bigint_col)
    assert translate(expr) == "greatest(`int_col`, `bigint_col`)"
    assert len(con.execute(expr))
Example #3
0
 def test_greatest(self):
     t = self.table
     cases = [
         (ibis.greatest(t.string_col, 'foo'),
          "greatest(string_col, 'foo')"),
         (ibis.greatest(t.int_col, t.bigint_col),
          'greatest(int_col, bigint_col)'),
     ]
     self._check_expr_cases(cases)
Example #4
0
 def test_greatest(self):
     t = self.table
     cases = [
         (ibis.greatest(t.string_col, 'foo'),
          "greatest(`string_col`, 'foo')"),
         (ibis.greatest(t.int_col, t.bigint_col),
          'greatest(`int_col`, `bigint_col`)'),
     ]
     self._check_expr_cases(cases)
Example #5
0
def test_greatest(con, alltypes, translate):
    expr = ibis.greatest(alltypes.int_col, 10)

    assert translate(expr) == "greatest(`int_col`, 10)"
    assert len(con.execute(expr))

    expr = ibis.greatest(alltypes.int_col, alltypes.bigint_col)
    assert translate(expr) == "greatest(`int_col`, `bigint_col`)"
    assert len(con.execute(expr))
Example #6
0
def test_greatest(client):
    table = client.table('basic_table')
    result = table.mutate(greatest=ibis.greatest(table.id)).compile()
    df = table.compile()
    expected = table.compile().withColumn('greatest', df.id)

    tm.assert_frame_equal(result.toPandas(), expected.toPandas())
Example #7
0
 def test_math_functions(self):
     cases = [
         (L(-5).abs(), 5),
         (L(5).abs(), 5),
         (ibis.least(L(5), L(10), L(1)), 1),
         (ibis.greatest(L(5), L(10), L(1)), 10),
         (L(5.5).round(), 6.0),
         (L(5.556).round(2), 5.56),
     ]
     self._check_e2e_cases(cases)
Example #8
0
 def test_math_functions(self):
     cases = [
         (L(-5).abs(), 5),
         (L(5).abs(), 5),
         (ibis.least(L(5), L(10), L(1)), 1),
         (ibis.greatest(L(5), L(10), L(1)), 10),
         (L(5.5).round(), 6.0),
         (L(5.556).round(2), 5.56),
     ]
     self._check_e2e_cases(cases)
Example #9
0
 def test_math_functions(self):
     cases = [
         (L(-5).abs(), 5),
         (L(5).abs(), 5),
         (ibis.least(L(5), L(10), L(1)), 1),
         (ibis.greatest(L(5), L(10), L(1)), 10),
         (L(5.5).round(), 6.0),
         (L(5.556).round(2), 5.56),
         (L(5.556).ceil(), 6.0),
         (L(5.556).floor(), 5.0),
         (L(5.556).exp(), math.exp(5.556)),
         (L(5.556).sign(), 1),
         (L(-5.556).sign(), -1),
         (L(0).sign(), 0),
         (L(5.556).sqrt(), math.sqrt(5.556)),
         (L(5.556).log(2), math.log(5.556, 2)),
         (L(5.556).ln(), math.log(5.556)),
         (L(5.556).log2(), math.log(5.556, 2)),
         (L(5.556).log10(), math.log10(5.556)),
     ]
     self._check_e2e_cases(cases)
Example #10
0
    def test_math_functions(self):
        cases = [
            (L(-5).abs(), 5),
            (L(5).abs(), 5),
            (ibis.least(L(5), L(10), L(1)), 1),
            (ibis.greatest(L(5), L(10), L(1)), 10),

            (L(5.5).round(), 6.0),
            (L(5.556).round(2), 5.56),
            (L(5.556).ceil(), 6.0),
            (L(5.556).floor(), 5.0),
            (L(5.556).exp(), math.exp(5.556)),
            (L(5.556).sign(), 1),
            (L(-5.556).sign(), -1),
            (L(0).sign(), 0),
            (L(5.556).sqrt(), math.sqrt(5.556)),
            (L(5.556).log(2), math.log(5.556, 2)),
            (L(5.556).ln(), math.log(5.556)),
            (L(5.556).log2(), math.log(5.556, 2)),
            (L(5.556).log10(), math.log10(5.556)),
        ]
        self._check_e2e_cases(cases)
Example #11
0
    result = con.execute(expr)

    if isinstance(expected, pd.Series):
        expected = backend.default_series_rename(expected)
        backend.assert_series_equal(result, expected)
    else:
        assert result == expected


@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        param(L(-5).abs(), 5, id='abs-neg'),
        param(L(5).abs(), 5, id='abs'),
        param(ibis.least(L(10), L(1)), 1, id='least'),
        param(ibis.greatest(L(10), L(1)), 10, id='greatest'),
        param(L(5.5).round(), 6.0, id='round'),
        param(L(5.556).round(2), 5.56, id='round-digits'),
        param(L(5.556).ceil(), 6.0, id='ceil'),
        param(L(5.556).floor(), 5.0, id='floor'),
        param(L(5.556).exp(), math.exp(5.556), id='expr'),
        param(L(5.556).sign(), 1, id='sign-pos'),
        param(L(-5.556).sign(), -1, id='sign-neg'),
        param(L(0).sign(), 0, id='sign-zero'),
        param(L(5.556).sqrt(), math.sqrt(5.556), id='sqrt'),
        param(L(5.556).log(2), math.log(5.556, 2), id='log-base'),
        param(L(5.556).ln(), math.log(5.556), id='ln'),
        param(L(5.556).log2(), math.log(5.556, 2), id='log2'),
        param(L(5.556).log10(), math.log10(5.556), id='log10'),
        param(L(5.556).radians(), math.radians(5.556), id='radians'),
        param(L(5.556).degrees(), math.degrees(5.556), id='degrees'),
@pytest.mark.parametrize(
    ("expr_fn", "expected"),
    [
        pytest.param(
            lambda t: ibis.coalesce(t.string_col, 'foo'),
            "coalesce(`string_col`, 'foo')",
            id="coalesce_scalar",
        ),
        pytest.param(
            lambda t: ibis.coalesce(t.int_col, t.bigint_col),
            'coalesce(`int_col`, `bigint_col`)',
            id="coalesce_columns",
        ),
        pytest.param(
            lambda t: ibis.greatest(t.string_col, 'foo'),
            "greatest(`string_col`, 'foo')",
            id="greatest_scalar",
        ),
        pytest.param(
            lambda t: ibis.greatest(t.int_col, t.bigint_col),
            'greatest(`int_col`, `bigint_col`)',
            id="greatest_columns",
        ),
        pytest.param(
            lambda t: ibis.least(t.string_col, 'foo'),
            "least(`string_col`, 'foo')",
            id="least_scalar",
        ),
        pytest.param(
            lambda t: ibis.least(t.int_col, t.bigint_col),
                          (L('foobar').like('%baz%'), False),
                          (L('foobar').like(['%bar']), True),
                          (L('foobar').like(['foo%']), True),
                          (L('foobar').like(['%baz%']), False),
                          (L('foobar').like(['%bar', 'foo%']), True),
                          (L('foobarfoo').replace('foo', 'H'), 'HbarH'),
                          (L('a').ascii_str(), ord('a'))])
def test_string_functions(con, expr, expected):
    assert con.execute(expr) == expected


@pytest.mark.parametrize(('expr', 'expected'), [
    (L(-5).abs(), 5),
    (L(5).abs(), 5),
    (ibis.least(L(5), L(10), L(1)), 1),
    (ibis.greatest(L(5), L(10), L(1)), 10),
    (L(5.5).round(), 6.0),
    (L(5.556).round(2), 5.56),
    (L(5.556).ceil(), 6.0),
    (L(5.556).floor(), 5.0),
    (L(5.556).exp(), math.exp(5.556)),
    (L(5.556).sign(), 1),
    (L(-5.556).sign(), -1),
    (L(0).sign(), 0),
    (L(5.556).sqrt(), math.sqrt(5.556)),
    (L(5.556).log(2), math.log(5.556, 2)),
    (L(5.556).ln(), math.log(5.556)),
    (L(5.556).log2(), math.log(5.556, 2)),
    (L(5.556).log10(), math.log10(5.556)),
])
def test_math_functions(con, expr, expected):
Example #14
0
    result = con.execute(expr)

    if isinstance(expected, pd.Series):
        expected = backend.default_series_rename(expected)
        backend.assert_series_equal(result, expected)
    else:
        assert result == expected


@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        param(L(-5).abs(), 5, id='abs-neg'),
        param(L(5).abs(), 5, id='abs'),
        param(ibis.least(L(10), L(1)), 1, id='least'),
        param(ibis.greatest(L(10), L(1)), 10, id='greatest'),
        param(L(5.5).round(), 6.0, id='round'),
        param(L(5.556).round(2), 5.56, id='round-digits'),
        param(L(5.556).ceil(), 6.0, id='ceil'),
        param(L(5.556).floor(), 5.0, id='floor'),
        param(L(5.556).exp(), math.exp(5.556), id='expr'),
        param(L(5.556).sign(), 1, id='sign-pos'),
        param(L(-5.556).sign(), -1, id='sign-neg'),
        param(L(0).sign(), 0, id='sign-zero'),
        param(L(5.556).sqrt(), math.sqrt(5.556), id='sqrt'),
        param(L(5.556).log(2), math.log(5.556, 2), id='log-base'),
        param(L(5.556).ln(), math.log(5.556), id='ln'),
        param(L(5.556).log2(), math.log(5.556, 2), id='log2'),
        param(L(5.556).log10(), math.log10(5.556), id='log10'),
        param(L(11) % 3, 11 % 3, id='mod'),
    ],
Example #15
0
    assert con.execute(expr) == expected


def test_str_replace(con):
    expr = L('foobarfoo').replace('foo', 'H')
    expected = 'HbarH'
    assert con.execute(expr) == expected


@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        (L(-5).abs(), 5),
        (L(5).abs(), 5),
        (ibis.least(L(5), L(10), L(1)), 1),
        (ibis.greatest(L(5), L(10), L(1)), 10),
        (L(5.5).round(), 6.0),
        (L(5.556).round(2), 5.56),
        (L(5.556).sqrt(), math.sqrt(5.556)),
        (L(5.556).ceil(), 6.0),
        (L(5.556).floor(), 5.0),
        (L(5.556).exp(), math.exp(5.556)),
        (L(5.556).sign(), 1),
        (L(-5.556).sign(), -1),
        (L(0).sign(), 0),
        (L(5.556).log(2), math.log(5.556, 2)),
        (L(5.556).ln(), math.log(5.556)),
        (L(5.556).log2(), math.log(5.556, 2)),
        (L(5.556).log10(), math.log10(5.556)),
    ],
)
Example #16
0
            backend.assert_series_equal(result, expected)


@pytest.mark.parametrize(
    ('expr', 'expected'),
    [
        param(L(-5).abs(), 5, id='abs-neg'),
        param(L(5).abs(), 5, id='abs'),
        param(
            ibis.least(L(10), L(1)),
            1,
            id='least',
            marks=pytest.mark.notimpl(["datafusion"]),
        ),
        param(
            ibis.greatest(L(10), L(1)),
            10,
            id='greatest',
            marks=pytest.mark.notimpl(["datafusion"]),
        ),
        param(L(5.5).round(), 6.0, id='round'),
        param(
            L(5.556).round(2),
            5.56,
            id='round-digits',
            marks=pytest.mark.notimpl(["datafusion"]),
        ),
        param(L(5.556).ceil(), 6.0, id='ceil'),
        param(L(5.556).floor(), 5.0, id='floor'),
        param(
            L(5.556).exp(),