Skip to content

Commit 3e4b06f

Browse files
docstrings & tests
1 parent 0a4f140 commit 3e4b06f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/feelpp/benchmarking/report/transformationFactory.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ def calculate(self,df):
1313
""" abstract method for transforming a dataframe depending on the strategy"""
1414
raise NotImplementedError("Not to be called directly.")
1515

16-
def chooseColumn(self,value,df):
16+
@staticmethod
17+
def chooseColumn(value,df):
18+
""" Chooses a column from a list of possible columns splitted by '|' from a dataframe, returns the first occurence in the dataframe.
19+
If no column is found, returns None
20+
If the value is null (0, False, None, ...), returns None
21+
Args:
22+
value (str): The string containing the possible columns, splitted by '|'. e.g. "column1|column2|column3"
23+
df (pd.DataFrame): The dataframe where the columns are searched
24+
Returns:
25+
str: The first column found in the dataframe, or None
26+
"""
1727
if not value:
1828
return value
1929

@@ -22,6 +32,8 @@ def chooseColumn(self,value,df):
2232
if column in df.columns:
2333
return column
2434

35+
return None
36+
2537
def updateDimensions(self,df):
2638
dimensions = {}
2739
for k,v in self.dimensions.items():

tests/report/test_transformationFactory.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ def test_speedupStrategy(self):
105105
ignore_columns = ["optimal","half-optimal"]
106106
assert np.isclose(calculated_df.loc[:,[col for col in calculated_df.columns if col not in ignore_columns]],pivot.loc[pivot.index.min(),:] / pivot).all()
107107

108+
109+
@pytest.mark.parametrize(("param_names","expected"),[
110+
("param1","param1"),
111+
("param1|non_existent","param1"),
112+
("non_existent|param2","param2"),
113+
("non_existent|param2|param3","param2"),
114+
("non_existent",None),
115+
(0,0), (None,None), (False,None),
116+
])
117+
def test_chooseColumn(self,param_names,expected):
118+
df = pd.DataFrame(columns=["param1","param2","param3","param4"])
119+
assert PerformanceStrategy.chooseColumn(param_names,df) == expected
120+
121+
122+
108123
class TestComplexStrategies:
109124
plot_config = PlotConfigMocker(
110125
xaxis=AxisMocker(parameter="xaxis",label="x"),

0 commit comments

Comments
 (0)