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]))
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] }))
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] }))
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] }))
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] }))
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)
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)
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)
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]}))
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]}))
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]}))
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]}))
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]))
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)
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]))
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
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