def test_least(self): t = self.table cases = [ (ibis.least(t.string_col, "foo"), "least(`string_col`, 'foo')"), (ibis.least(t.int_col, t.bigint_col), "least(`int_col`, `bigint_col`)"), ] self._check_expr_cases(cases)
def test_least(con, alltypes, translate): expr = ibis.least(alltypes.int_col, 10) assert translate(expr) == "least(`int_col`, 10)" assert len(con.execute(expr)) expr = ibis.least(alltypes.int_col, alltypes.bigint_col) assert translate(expr) == "least(`int_col`, `bigint_col`)" assert len(con.execute(expr))
def test_least(self): t = self.table cases = [ (ibis.least(t.string_col, 'foo'), "least(string_col, 'foo')"), (ibis.least(t.int_col, t.bigint_col), 'least(int_col, bigint_col)'), ] self._check_expr_cases(cases)
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)
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)
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'),
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), 'least(`int_col`, `bigint_col`)', id="least_columns", ), ], ) def test_varargs_functions(table, expr_fn, expected): t = table expr = expr_fn(t) result = translate(expr) assert result == expected
(L('foobar').like('foo%'), True), (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)), ])
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'),
def test_string_like(con, expr, expected): 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)), ],
expected = backend.default_series_rename(expected) backend.assert_series_equal(result, expected) else: try: assert result == expected except ValueError: 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',