Skip to content

Commit a60f127

Browse files
authored
Merge pull request rasbt#1026 from fatihsen20/fixed-test-branch
Fixed incorrect test codes.
2 parents 8ebfd31 + e283a20 commit a60f127

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

.github/workflows/python-package-conda.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414

1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Set up Python 3.8
17+
- name: Set up Python 3.9
1818
uses: actions/setup-python@v2
1919
with:
20-
python-version: 3.8
20+
python-version: 3.9
2121
- name: Add conda to system path
2222
run: |
2323
# $CONDA is an environment variable pointing to the root of the miniconda directory
@@ -27,7 +27,9 @@ jobs:
2727
conda env update --file environment.yml --name base
2828
- name: Test with pytest
2929
run: |
30+
conda update conda -y -q
3031
conda config --add channels conda-forge
32+
conda update conda -y -q
3133
conda install scikit-learn=1.0.2 pandas=1.3.5 -y -q
3234
conda install tensorflow joblib pytest -y -q
3335
conda install imageio scikit-image -y -q

mlxtend/frequent_patterns/tests/test_fpbase.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ def test_with_dataframe(df):
104104
test_with_dataframe(sdf)
105105

106106
def test_sparsedataframe_notzero_column(self):
107-
dfs = self.df.astype(pd.SparseDtype("int", np.nan))
107+
dfs = self.df.astype(pd.SparseDtype("int", 0))
108108

109109
dfs.columns = [i for i in range(len(dfs.columns))]
110110
self.fpalgo(dfs)
111111

112-
dfs = self.df.astype(pd.SparseDtype("int", np.nan))
112+
dfs = self.df.astype(pd.SparseDtype("int", 0))
113113

114114
dfs.columns = [i + 1 for i in range(len(dfs.columns))]
115115
assert_raises(
@@ -334,5 +334,10 @@ def compare_dataframes(df1, df2):
334334
rows1 = sorted(zip(itemsets1, df1["support"]))
335335
rows2 = sorted(zip(itemsets2, df2["support"]))
336336

337-
for r1, r2 in zip(rows1, rows2):
338-
assert_array_equal(r1, r2)
337+
for row1, row2 in zip(rows1, rows2):
338+
if row1[0] != row2[0]:
339+
msg = f"Expected different frequent itemsets\nx:{row1[0]}\ny:{row2[0]}"
340+
raise AssertionError(msg)
341+
elif row1[1] != row2[1]:
342+
msg = f"Expected different support\nx:{row1[1]}\ny:{row2[1]}"
343+
raise AssertionError(msg)

mlxtend/frequent_patterns/tests/test_hmine.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
FPTestEx1All,
1414
FPTestEx2All,
1515
FPTestEx3All,
16+
compare_dataframes,
1617
)
1718

1819
from mlxtend.frequent_patterns import apriori, fpgrowth, hmine
@@ -176,23 +177,9 @@ def test_compare_correct(self):
176177
for algo in algorithms.keys():
177178
self.setUp()
178179
res_df = algo(self.df, min_support=0.6)
179-
compare_df(res_df, expect)
180+
compare_dataframes(res_df, expect)
180181
algorithms[algo] = res_df
181182

182-
compare_df(algorithms[hmine], algorithms[fpgrowth])
183-
compare_df(algorithms[hmine], algorithms[apriori])
184-
compare_df(algorithms[fpgrowth], algorithms[apriori])
185-
186-
187-
def compare_df(df1, df2):
188-
itemsets1 = [sorted(list(i)) for i in df1["itemsets"]]
189-
itemsets2 = [sorted(list(i)) for i in df2["itemsets"]]
190-
rows1 = sorted(zip(itemsets1, df1["support"]))
191-
rows2 = sorted(zip(itemsets2, df2["support"]))
192-
for row1, row2 in zip(rows1, rows2):
193-
if row1[0] != row2[0]:
194-
msg = f"Expected different frequent itemsets\nx:{row1[0]}\ny:{row2[0]}"
195-
raise AssertionError(msg)
196-
elif row1[1] != row2[1]:
197-
msg = f"Expected different support\nx:{row1[1]}\ny:{row2[1]}"
198-
raise AssertionError(msg)
183+
compare_dataframes(algorithms[hmine], algorithms[fpgrowth])
184+
compare_dataframes(algorithms[hmine], algorithms[apriori])
185+
compare_dataframes(algorithms[fpgrowth], algorithms[apriori])

0 commit comments

Comments
 (0)