コード例 #1
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_count_remove_filters(seed, df, alloc_id, count,
                                             constraint_df, constraint_units,
                                             constraint_expr, scaled_test):
    target = 2
    filters = '{} < 3'.format(count)

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    filters=filters,
                                    count=count)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    filters=filters,
                                    constraint_expr=constraint_expr,
                                    count=count)

    assert result.query(filters)[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['b', 'c', 'b', 'c'],
            count: [2, 3, 4, 5]
        },
                     index=[1, 2, 3, 4]))
コード例 #2
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_add_filters(seed, df, alloc_id, count, constraint_df,
                                    constraint_units, constraint_expr,
                                    scaled_test):
    target = 3
    filters = '{} < 2'.format(count)

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    filters=filters)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    filters=filters,
                                    constraint_expr=constraint_expr)

    assert len(result.query(filters)) == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c'],
            count: [1, 2, 3, 4, 5, 1, 1]
        }))
コード例 #3
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_count_add_no_stuff(seed, df, alloc_id, count,
                                           constraint_df, constraint_units,
                                           constraint_expr, scaled_test):
    target = 30
    stuff = False

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    count=count,
                                    stuff=stuff)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr,
                                    count=count,
                                    stuff=stuff)

    assert result[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c', 'c', 'c', None],
            count: [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]
        }))
コード例 #4
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_count_remove(seed, df, alloc_id, count, constraint_df,
                                     constraint_units, constraint_expr,
                                     scaled_test):
    target = 10

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    count=count)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr,
                                    count=count)

    assert result[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['a', 'b', 'c', 'b'],
            count: [1, 2, 3, 4]
        }))
コード例 #5
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_add_stuff(seed, df, alloc_id, count, constraint_df,
                                  constraint_units, constraint_expr,
                                  scaled_test):
    target = 10
    stuff = True

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    stuff=stuff)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr,
                                    stuff=stuff)

    assert len(result) == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c', 'c', 'c', 'a'],
            count: [1, 2, 3, 4, 5, 5, 1, 4, 4, 4]
        }))
コード例 #6
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_count_noop(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = df[count].sum()

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units, count=count)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            constraint_expr=constraint_expr, count=count)

    assert result[count].sum() == target
    pdt.assert_frame_equal(result, df)
コード例 #7
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_noop(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 5

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            constraint_expr=constraint_expr)

    assert len(result) == target
    pdt.assert_frame_equal(result, df)
コード例 #8
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_noop(seed, df, alloc_id, count, constraint_df,
                             constraint_units, constraint_expr, scaled_test):
    target = 5

    if not scaled_test:
        result = syn.synthesize_one(df, target, alloc_id, constraint_df,
                                    constraint_units)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr)

    assert len(result) == target
    pdt.assert_frame_equal(result, df)
コード例 #9
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_count_add(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 18

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units, count=count)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            constraint_expr=constraint_expr, count=count)

    assert result[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame(
            {alloc_id: ['a', 'b', 'c', 'b', 'c', 'b'],
             count: [1, 2, 3, 4, 5, 3]}))
コード例 #10
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_add(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 8

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            constraint_expr=constraint_expr)

    assert len(result) == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame(
            {alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c', 'c'],
             count: [1, 2, 3, 4, 5, 5, 1, 4]}))
コード例 #11
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_count_add_filters(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 18
    filters = '{} > 3'.format(count)

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units,
            filters=filters, count=count)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            filters=filters, constraint_expr=constraint_expr, count=count)

    assert result.query(filters)[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame(
            {alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c'],
             count: [1, 2, 3, 4, 5, 5, 4]}))
コード例 #12
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_count_add_no_stuff(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 30
    stuff = False

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units,
            count=count, stuff=stuff)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            constraint_expr=constraint_expr, count=count, stuff=stuff)

    assert result[count].sum() == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame(
            {alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c', 'c', 'c', None],
             count: [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]}))
コード例 #13
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_remove_filters(
        seed, df, alloc_id, count, constraint_df, constraint_units,
        constraint_expr, scaled_test):
    target = 1
    filters = '{} > 3'.format(count)

    if not scaled_test:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df, constraint_units,
            filters=filters)
    else:
        result = syn.synthesize_one(
            df, target, alloc_id, constraint_df,
            filters=filters, constraint_expr=constraint_expr)

    assert len(result.query(filters)) == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame(
            {alloc_id: ['a', 'b', 'c', 'c'],
             count: [1, 2, 3, 5]},
            index=[0, 1, 2, 4]))
コード例 #14
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_count_noop(seed, df, alloc_id, count, constraint_df,
                                   constraint_units, constraint_expr,
                                   scaled_test):
    target = df[count].sum()

    if not scaled_test:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_units,
                                    count=count)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr,
                                    count=count)

    assert result[count].sum() == target
    pdt.assert_frame_equal(result, df)
コード例 #15
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_remove(seed, df, alloc_id, count, constraint_df,
                               constraint_units, constraint_expr, scaled_test):
    target = 3

    if not scaled_test:
        result = syn.synthesize_one(df, target, alloc_id, constraint_df,
                                    constraint_units)
    else:
        result = syn.synthesize_one(df,
                                    target,
                                    alloc_id,
                                    constraint_df,
                                    constraint_expr=constraint_expr)

    assert len(result) == target
    pdt.assert_frame_equal(
        result,
        pd.DataFrame({
            alloc_id: ['b', 'c', 'b'],
            count: [2, 3, 4]
        },
                     index=[1, 2, 3]))
コード例 #16
0
ファイル: test_synthesis.py プロジェクト: UDST/spandex
def test_synthesize_one_27bug(
        alloc_id, count, constraint_df, constraint_units):
    # this triggers a bug where things aren't adding up when counting
    # values in the count column and filtering on the count column
    df = pd.DataFrame(
        {alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c'],
         count: [1, 2, 3, 4, 5, 5, 1]})
    target = 27
    filters = '{} > 3'.format(count)

    result = syn.synthesize_one(
        df, target, alloc_id, constraint_df, constraint_units,
        filters=filters, count=count, stuff=False)

    assert result.query(filters)[count].sum() == target
コード例 #17
0
ファイル: test_synthesis.py プロジェクト: terratenney/spandex
def test_synthesize_one_27bug(alloc_id, count, constraint_df,
                              constraint_units):
    # this triggers a bug where things aren't adding up when counting
    # values in the count column and filtering on the count column
    df = pd.DataFrame({
        alloc_id: ['a', 'b', 'c', 'b', 'c', 'b', 'c'],
        count: [1, 2, 3, 4, 5, 5, 1]
    })
    target = 27
    filters = '{} > 3'.format(count)

    result = syn.synthesize_one(df,
                                target,
                                alloc_id,
                                constraint_df,
                                constraint_units,
                                filters=filters,
                                count=count,
                                stuff=False)

    assert result.query(filters)[count].sum() == target