def test_category_label(alltypes, df): bins = [0, 10, 25, 50, 100] labels = ['a', 'b', 'c', 'd'] expr = alltypes.double_col.bucket(bins).label(labels) result = expr.execute() result = pd.Series(pd.Categorical(result, ordered=True)) result.name = 'double_col' expected = pd.cut(df.double_col, bins, labels=labels, right=False) tm.assert_series_equal(result, expected) @pytest.mark.xfail( get_version(sqlite3.sqlite_version) < get_version('3.8.3'), raises=sa.exc.OperationalError, reason='SQLite versions < 3.8.3 do not support the WITH statement', ) def test_union(alltypes): t = alltypes expr = (t.group_by('string_col').aggregate( t.double_col.sum().name('foo')).sort_by('string_col')) t1 = expr.limit(4) t2 = expr.limit(4, offset=4) t3 = expr.limit(8) result = t1.union(t2).execute() expected = t3.execute()
labels = ['a', 'b', 'c', 'd'] expr = alltypes.double_col.bucket(bins).label(labels) result = expr.execute() with warnings.catch_warnings(): warnings.simplefilter('ignore') result = result.astype('category', ordered=True) result.name = 'double_col' expected = pd.cut(df.double_col, bins, labels=labels, right=False) tm.assert_series_equal(result, expected) @pytest.mark.xfail( get_version(sqlite3.sqlite_version) < get_version('3.8.3'), raises=sa.exc.OperationalError, reason='SQLite versions < 3.8.3 do not support the WITH statement', ) def test_union(alltypes): t = alltypes expr = ( t.group_by('string_col') .aggregate(t.double_col.sum().name('foo')) .sort_by('string_col') ) t1 = expr.limit(4) t2 = expr.limit(4, offset=4) t3 = expr.limit(8)