def test_where_use_if(self): expr = ibis.where(self.table.f > 0, self.table.e, self.table.a) assert isinstance(expr, ir.FloatValue) result = self._translate(expr) expected = "if(`f` > 0, `e`, `a`)" assert result == expected
def test_where_use_if(table): expr = ibis.where(table.f > 0, table.e, table.a) assert isinstance(expr, ir.FloatingValue) result = translate(expr) expected = "if(`f` > 0, `e`, `a`)" assert result == expected
def test_where_use_if(self): expr = ibis.where(self.table.f > 0, self.table.e, self.table.a) assert isinstance(expr, ir.FloatValue) result = self._translate(expr) expected = "if(`f` > 0, `e`, `a`)" assert result == expected
def test_where_use_if(con, alltypes, translate): expr = ibis.where(alltypes.float_col > 0, alltypes.int_col, alltypes.bigint_col) result = translate(expr) expected = "if(`float_col` > 0, `int_col`, `bigint_col`)" assert result == expected con.execute(expr)
def test_where_long(batting, batting_df): col_expr = batting['AB'] result = ibis.where(col_expr > col_expr.mean(), col_expr, 0.0).execute() ser = batting_df['AB'] expected = ser.where(ser > ser.mean(), other=0.0) tm.assert_series_equal(result, expected)
def test_where_series(t, df): col_expr = t['plain_int64'] result = ibis.where(col_expr > col_expr.mean(), col_expr, 0.0).execute() ser = df['plain_int64'] expected = ser.where(ser > ser.mean(), other=0.0) tm.assert_series_equal(result, expected)
def test_where_long(batting, batting_df): col_expr = batting['AB'] result = ibis.where(col_expr > col_expr.mean(), col_expr, 0.0).execute() ser = batting_df['AB'] expected = ser.where(ser > ser.mean(), other=0.0) tm.assert_series_equal(result, expected)
def test_where_series(t, df): col_expr = t['plain_int64'] result = ibis.where(col_expr > col_expr.mean(), col_expr, 0.0).execute() ser = df['plain_int64'] expected = ser.where(ser > ser.mean(), other=0.0) tm.assert_series_equal(result, expected)
def test_where_use_if(con, alltypes, translate): expr = ibis.where( alltypes.float_col > 0, alltypes.int_col, alltypes.bigint_col ) result = translate(expr) expected = "if(`float_col` > 0, `int_col`, `bigint_col`)" assert result == expected con.execute(expr)
def test_where_column(backend, alltypes, df): expr = ( ibis.where(alltypes["int_col"] == 0, 42, -1) .cast("int64") .name("where_col") ) result = expr.execute() expected = pd.Series( np.where(df.int_col == 0, 42, -1), name="where_col", dtype="int64", ) backend.assert_series_equal(result, expected)
def test_where_select(backend, alltypes, df): table = alltypes table = table.select( [ "int_col", ( ibis.where(table["int_col"] == 0, 42, -1) .cast("int64") .name("where_col") ), ] ) result = table.execute() expected = df.loc[:, ["int_col"]].copy() expected['where_col'] = -1 expected.loc[expected['int_col'] == 0, 'where_col'] = 42 backend.assert_frame_equal(result, expected)
def test_where_scalar(t, df, cond, expected_func): expr = ibis.where(cond, t['plain_int64'], 3.0) result = expr.execute() expected = expected_func(df) tm.assert_series_equal(result, expected)
def test_where_operator(alltypes): t = alltypes.sort_by('index').limit(10) expr = ibis.where(t.index > 4, 1, 0) counts = expr.execute().value_counts() assert counts[0] == 5 assert counts[1] == 5
def test_where_operator(alltypes): t = alltypes.sort_by('index').limit(10) expr = ibis.where(t.index > 4, 1, 0) counts = expr.execute().value_counts() assert counts[0] == 5 assert counts[1] == 5
def test_where_scalar(t, df, cond, expected_func): expr = ibis.where(cond, t['plain_int64'], 3.0) result = expr.execute() expected = expected_func(df) tm.assert_series_equal(result, expected)