Skip to content

Commit ecf3401

Browse files
[ENH] Make pip installable (#6)
* adding pip * add tests * fix test bug * fix example * change test name
1 parent 21c013d commit ecf3401

File tree

13 files changed

+263
-57
lines changed

13 files changed

+263
-57
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Upload Python Package to PyPI when a Release is Created
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
pypi-publish:
9+
name: Publish release to PyPI
10+
runs-on: ubuntu-latest
11+
environment:
12+
name: pypi
13+
url: https://pypi.org/p/multi_comp_matrix
14+
permissions:
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.10"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install setuptools wheel
26+
- name: Build package
27+
run: |
28+
python -m pip install build
29+
python -m build
30+
- name: Publish package distributions to PyPI
31+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/pytest.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: PR pytest
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
paths:
11+
- "multi_comp_matrix/**"
12+
- ".github/workflows/**"
13+
- "pyproject.toml"
14+
15+
jobs:
16+
test-mcm:
17+
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
os: [ ubuntu-22.04, macOS-14, windows-2022 ]
22+
python-version: [ "3.10" ]
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v3
27+
28+
- name: Setup Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Install dependencies
34+
uses: nick-fields/retry@v3
35+
with:
36+
timeout_minutes: 30
37+
max_attempts: 3
38+
command: python -m pip install .[dev]
39+
40+
- name: Show dependencies
41+
run: python -m pip list
42+
43+
- name: Run tests
44+
run: python -m pytest -n logical

MANIFEST.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
recursive-include multi_comp_matrix *.py
2+
include LICENSE
3+
include MANIFEST.in
4+
include pyproject.toml
5+
include README.md
6+
include *.csv
7+
include *.pdf
8+
include *.png
9+
include *.tex

heatline_horizontal.png

-547 Bytes
Loading

heatline_vertical.png

-1.83 KB
Loading

heatmap.pdf

-637 Bytes
Binary file not shown.

main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import pandas as pd
22

3-
from MCM import MCM
3+
from multi_comp_matrix import MCM
44

55
if __name__ == "__main__":
66
path_res = "./results_example.csv"
7-
output_dir = "./"
7+
output_dir = "../"
88

99
df_results = pd.read_csv(path_res)
1010

1111
MCM.compare(
1212
df_results=df_results,
13+
output_dir=output_dir,
1314
pdf_savename="heatmap",
1415
png_savename="heatmap",
1516
)
1617

1718
MCM.compare(
1819
df_results=df_results,
20+
output_dir=output_dir,
1921
excluded_col_comparates=["clf1", "clf3"],
2022
png_savename="heatline_vertical",
2123
include_ProbaWinTieLoss=True
2224
)
2325

2426
MCM.compare(
2527
df_results=df_results,
28+
output_dir=output_dir,
2629
excluded_row_comparates=["clf1", "clf3"],
2730
png_savename="heatline_horizontal",
2831
tex_savename="heatline_horizontal",

MCM/MCM.py renamed to multi_comp_matrix/MCM.py

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def get_analysis(
335335
re_order_comparates(df_results=df_results, analysis=analysis)
336336

337337
if save_as_json:
338+
print(save_file)
338339
with open(save_file, "w") as fjson:
339340
json.dump(analysis, fjson, cls=NpEncoder)
340341

@@ -759,71 +760,67 @@ def draw(
759760
plt.savefig(
760761
os.path.join(output_dir + f"{pdf_savename}.pdf"), bbox_inches="tight"
761762
)
762-
plt.cla()
763-
plt.clf()
764-
plt.close()
765-
elif png_savename is not None:
763+
764+
if png_savename is not None:
766765
plt.savefig(
767766
os.path.join(output_dir + f"{png_savename}.png"), bbox_inches="tight"
768767
)
769-
plt.cla()
770-
plt.clf()
771-
772-
latex_string += (
773-
f"\\begin{{tabular}}{{{'c' * (len(latex_table[0]) + 1)}}}\n" # +1 for labels
774-
)
775-
for latex_row in latex_table:
776-
latex_string += " & ".join(latex_row) + " \\\\[1ex]" + "\n"
777768

778-
if colorbar_orientation == "horizontal":
779-
latex_string += "\\end{tabular}\\\\\n"
780-
else:
781-
latex_string += "\\end{tabular}\n"
769+
if tex_savename is not None:
770+
latex_string += (
771+
f"\\begin{{tabular}}{{{'c' * (len(latex_table[0]) + 1)}}}\n" # +1 for labels
772+
)
773+
for latex_row in latex_table:
774+
latex_string += " & ".join(latex_row) + " \\\\[1ex]" + "\n"
782775

783-
latex_colorbar_0 = "\\begin{tikzpicture}[baseline=(current bounding box.center)]\\begin{axis}[hide axis,scale only axis,"
784-
latex_colorbar_1 = f"colormap={{cm}}{{rgb255(1)=({','.join([str(int(_ * 255)) for _ in cm(cm_norm(min_value))[:-1]])}) rgb255(2)=(220,220,220) rgb255(3)=({','.join([str(int(_ * 255)) for _ in cm(cm_norm(max_value))[:-1]])})}},"
785-
latex_colorbar_2 = (
786-
f"colorbar horizontal,point meta min={_vmin:.02f},point meta max={_vmax:.02f},"
787-
)
788-
latex_colorbar_3 = "colorbar/width=1.0em"
789-
latex_colorbar_4 = "}] \\addplot[draw=none] {0};\\end{axis}\\end{tikzpicture}"
776+
if colorbar_orientation == "horizontal":
777+
latex_string += "\\end{tabular}\\\\\n"
778+
else:
779+
latex_string += "\\end{tabular}\n"
790780

791-
if colorbar_orientation == "horizontal":
792-
latex_string += (
793-
latex_colorbar_0
794-
+ "width=0sp,height=0sp,colorbar horizontal,colorbar style={width=0.25\linewidth,"
795-
+ latex_colorbar_1
796-
+ latex_colorbar_2
797-
+ latex_colorbar_3
798-
+ ",scaled x ticks=false,xticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
799-
+ f"xlabel={{{_colorbar_value}}},"
800-
+ latex_colorbar_4
781+
latex_colorbar_0 = "\\begin{tikzpicture}[baseline=(current bounding box.center)]\\begin{axis}[hide axis,scale only axis,"
782+
latex_colorbar_1 = f"colormap={{cm}}{{rgb255(1)=({','.join([str(int(_ * 255)) for _ in cm(cm_norm(min_value))[:-1]])}) rgb255(2)=(220,220,220) rgb255(3)=({','.join([str(int(_ * 255)) for _ in cm(cm_norm(max_value))[:-1]])})}},"
783+
latex_colorbar_2 = (
784+
f"colorbar horizontal,point meta min={_vmin:.02f},point meta max={_vmax:.02f},"
801785
)
802-
else:
786+
latex_colorbar_3 = "colorbar/width=1.0em"
787+
latex_colorbar_4 = "}] \\addplot[draw=none] {0};\\end{axis}\\end{tikzpicture}"
788+
789+
if colorbar_orientation == "horizontal":
790+
latex_string += (
791+
latex_colorbar_0
792+
+ "width=0sp,height=0sp,colorbar horizontal,colorbar style={width=0.25\linewidth,"
793+
+ latex_colorbar_1
794+
+ latex_colorbar_2
795+
+ latex_colorbar_3
796+
+ ",scaled x ticks=false,xticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
797+
+ f"xlabel={{{_colorbar_value}}},"
798+
+ latex_colorbar_4
799+
)
800+
else:
801+
latex_string += (
802+
latex_colorbar_0
803+
+ "width=1pt,colorbar right,colorbar style={height=0.25\linewidth,"
804+
+ latex_colorbar_1
805+
+ latex_colorbar_2
806+
+ latex_colorbar_3
807+
+ ",scaled y ticks=false,ylabel style={rotate=180},yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
808+
+ f"ylabel={{{_colorbar_value}}},"
809+
+ latex_colorbar_4
810+
)
811+
812+
latex_string += "\\end{center}\n"
803813
latex_string += (
804-
latex_colorbar_0
805-
+ "width=1pt,colorbar right,colorbar style={height=0.25\linewidth,"
806-
+ latex_colorbar_1
807-
+ latex_colorbar_2
808-
+ latex_colorbar_3
809-
+ ",scaled y ticks=false,ylabel style={rotate=180},yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
810-
+ f"ylabel={{{_colorbar_value}}},"
811-
+ latex_colorbar_4
814+
"\\caption{[...] \\textbf{"
815+
+ f"{p_value_text}".replace("\n", " ")
816+
+ "} [...]}\n"
812817
)
818+
latex_string += "\\end{table}\n"
819+
latex_string += "\\end{document}\n"
813820

814-
latex_string += "\\end{center}\n"
815-
latex_string += (
816-
"\\caption{[...] \\textbf{"
817-
+ f"{p_value_text}".replace("\n", " ")
818-
+ "} [...]}\n"
819-
)
820-
latex_string += "\\end{table}\n"
821-
latex_string += "\\end{document}\n"
822-
823-
latex_string = latex_string.replace(">", "$>$")
824-
latex_string = latex_string.replace("<", "$<$")
825-
826-
if tex_savename is not None:
821+
latex_string = latex_string.replace(">", "$>$")
822+
latex_string = latex_string.replace("<", "$<$")
823+
827824
with open(
828825
f"{output_dir}/{tex_savename}.tex", "w", encoding="utf8", newline="\n"
829826
) as file:
@@ -837,3 +834,7 @@ def draw(
837834

838835
if tex_savename is None and pdf_savename is None and png_savename is None:
839836
plt.show()
837+
838+
plt.cla()
839+
plt.clf()
840+
plt.close()

multi_comp_matrix/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)