def test_cleanduplicates_multi_col(self): """ Test for evaluation that doesn't have duplicates when comparing more than one column """ df = pd.DataFrame([ { "a": 1, "b": 1, "c": 5 }, { "a": 1, "b": 2, "c": 4 }, { "a": 3, "b": 3, "c": 3 }, { "a": 4, "b": 4, "c": 2 }, { "a": 5, "b": 5, "c": 1 }, ]) eval1 = Evaluation(df) pipeline = [CleanDuplicates(["a", "b"])] result2 = eval1.process(pipeline).get_df() assert_frame_equal(result2, df, check_like=True)
def test_cleanduplicates_one_col(self): """ Test for evaluation that has duplicate in one column """ df = pd.DataFrame([ { "a": 1, "b": 1, "c": 5 }, { "a": 1, "b": 2, "c": 4 }, { "a": 3, "b": 3, "c": 3 }, { "a": 4, "b": 4, "c": 2 }, { "a": 5, "b": 5, "c": 1 }, ]) eval1 = Evaluation(df) pipeline = [CleanDuplicates(["a"])] result = eval1.process(pipeline).get_df() expected = df.drop(1) assert_frame_equal(result, expected, check_like=True)
def test_normalizearound_negated(self): """ Test whether all values are normalized in the correct direction based on the negation. """ arrays = [ ["blinky", "blinky", "blinky", "ibex", "ibex"], ["yosys", "yosys", "vivado", "yosys", "vivado"], ] index = pd.MultiIndex.from_arrays(arrays, names=("project", "synthesis_tool")) df = pd.DataFrame(data=[ { "group": "b", "value": 0 }, { "group": "b", "value": 50 }, { "group": "b", "value": 100 }, { "group": "a", "value": 0 }, { "group": "a", "value": 10 }, ], index=index) eval1 = Evaluation(df, eval_id=10) normalize_direction = {"value": Direction.MAXIMIZE} pipeline = [ NormalizeAround(normalize_direction, group_by="project", idx_name="synthesis_tool", idx_value="vivado") ] result = eval1.process(pipeline) expected = pd.DataFrame(data=[ { "group": "b", "value": 1 }, { "group": "b", "value": 0.75 }, { "group": "b", "value": 0.5 }, { "group": "a", "value": 1 }, { "group": "a", "value": 0.5 }, ], index=index) assert_frame_equal(result.get_df(), expected) assert result.get_eval_id() == 10
def test_sortindex(self): """ Test whether the dataframe is sorted by index """ df = pd.DataFrame(data=[ { "group": "a", "value": 10 }, { "group": "a", "value": 5 }, { "group": "a", "value": 3 }, { "group": "b", "value": 100 }, { "group": "b", "value": 31 }, ], index=pd.Index([ 5, 4, 3, 2, 1, ], name="idx")) eval1 = Evaluation(df, eval_id=10) pipeline = [SortIndex(["idx"])] result = eval1.process(pipeline) expected = pd.DataFrame(data=[ { "group": "b", "value": 31 }, { "group": "b", "value": 100 }, { "group": "a", "value": 3 }, { "group": "a", "value": 5 }, { "group": "a", "value": 10 }, ], index=pd.Index([ 1, 2, 3, 4, 5, ], name="idx")) assert_frame_equal(result.get_df(), expected) assert result.get_eval_id() == 10
def test_expandcolumn(self): """ Test whether the column is expanded """ df = pd.DataFrame([ { "group": "a", "value": 10 }, { "group": "a", "value": 5 }, { "group": "a", "value": 3 }, { "group": "b", "value": 100 }, { "group": "b", "value": 31 }, ]) eval1 = Evaluation(df, eval_id=10) mapping = { "a": ("a", "x"), "b": ("b", "y"), } pipeline = [ExpandColumn("group", ["group1", "group2"], mapping)] result = eval1.process(pipeline) expected = pd.DataFrame([ { "group": "a", "group1": "a", "group2": "x", "value": 10 }, { "group": "a", "group1": "a", "group2": "x", "value": 5 }, { "group": "a", "group1": "a", "group2": "x", "value": 3 }, { "group": "b", "group1": "b", "group2": "y", "value": 100 }, { "group": "b", "group1": "b", "group2": "y", "value": 31 }, ]) assert_frame_equal(result.get_df(), expected, check_like=True) assert result.get_eval_id() == 10
def test_addnormalizedcolumn_direction(self): """ Test whether normalized column direction parameter works """ df = pd.DataFrame([ { "group": "a", "value": 10 }, { "group": "a", "value": 5 }, { "group": "a", "value": 3 }, { "group": "b", "value": 100 }, { "group": "b", "value": 31 }, ]) eval1 = Evaluation(df, eval_id=10) # direction is -1 => normalize around minimum pipeline = [ AddNormalizedColumn("group", "value", "normalized", Direction.MINIMIZE) ] result = eval1.process(pipeline) expected = pd.DataFrame([ { "group": "a", "value": 10, "normalized": 10 / 3 }, { "group": "a", "value": 5, "normalized": 5 / 3 }, { "group": "a", "value": 3, "normalized": 1.0 }, { "group": "b", "value": 100, "normalized": 100 / 31 }, { "group": "b", "value": 31, "normalized": 1.0 }, ]) assert_frame_equal(result.get_df(), expected) assert result.get_eval_id() == 10
def test_comparetofirst_suffix(self): """ Test if CompareToFirst works with different suffix """ df = pd.DataFrame([ { "a": 1, "b": 5 }, { "a": 2, "b": 4 }, { "a": 3, "b": 3 }, { "a": 4, "b": 2 }, { "a": 5, "b": 1 }, ]) eval1 = Evaluation(df, eval_id=20) direction = {"a": Direction.MAXIMIZE, "b": Direction.MAXIMIZE} pipeline = [CompareToFirst(direction, suffix=".diff")] eval1 = eval1.process(pipeline) expected_df = pd.DataFrame([ { "a": 1, "a.diff": 1.0 / 1, "b": 5, "b.diff": 5.0 / 5 }, { "a": 2, "a.diff": 2.0 / 1, "b": 4, "b.diff": 4.0 / 5 }, { "a": 3, "a.diff": 3.0 / 1, "b": 3, "b.diff": 3.0 / 5 }, { "a": 4, "a.diff": 4.0 / 1, "b": 2, "b.diff": 2.0 / 5 }, { "a": 5, "a.diff": 5.0 / 1, "b": 1, "b.diff": 1.0 / 5 }, ]) assert_frame_equal(eval1.get_df(), expected_df) assert eval1.get_eval_id() == 20