Skip to content

Commit

Permalink
[ENH] Make pip installable (#6)
Browse files Browse the repository at this point in the history
* adding pip

* add tests

* fix test bug

* fix example

* change test name
  • Loading branch information
hadifawaz1999 authored Nov 4, 2024
1 parent 21c013d commit ecf3401
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 57 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload Python Package to PyPI when a Release is Created

on:
release:
types: [created]

jobs:
pypi-publish:
name: Publish release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/multi_comp_matrix
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
- name: Build package
run: |
python -m pip install build
python -m build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
44 changes: 44 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: PR pytest

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "multi_comp_matrix/**"
- ".github/workflows/**"
- "pyproject.toml"

jobs:
test-mcm:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-22.04, macOS-14, windows-2022 ]
python-version: [ "3.10" ]

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
command: python -m pip install .[dev]

- name: Show dependencies
run: python -m pip list

- name: Run tests
run: python -m pytest -n logical
9 changes: 9 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
recursive-include multi_comp_matrix *.py
include LICENSE
include MANIFEST.in
include pyproject.toml
include README.md
include *.csv
include *.pdf
include *.png
include *.tex
Binary file modified heatline_horizontal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified heatline_vertical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified heatmap.pdf
Binary file not shown.
7 changes: 5 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import pandas as pd

from MCM import MCM
from multi_comp_matrix import MCM

if __name__ == "__main__":
path_res = "./results_example.csv"
output_dir = "./"
output_dir = "../"

df_results = pd.read_csv(path_res)

MCM.compare(
df_results=df_results,
output_dir=output_dir,
pdf_savename="heatmap",
png_savename="heatmap",
)

MCM.compare(
df_results=df_results,
output_dir=output_dir,
excluded_col_comparates=["clf1", "clf3"],
png_savename="heatline_vertical",
include_ProbaWinTieLoss=True
)

MCM.compare(
df_results=df_results,
output_dir=output_dir,
excluded_row_comparates=["clf1", "clf3"],
png_savename="heatline_horizontal",
tex_savename="heatline_horizontal",
Expand Down
111 changes: 56 additions & 55 deletions MCM/MCM.py → multi_comp_matrix/MCM.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def get_analysis(
re_order_comparates(df_results=df_results, analysis=analysis)

if save_as_json:
print(save_file)
with open(save_file, "w") as fjson:
json.dump(analysis, fjson, cls=NpEncoder)

Expand Down Expand Up @@ -759,71 +760,67 @@ def draw(
plt.savefig(
os.path.join(output_dir + f"{pdf_savename}.pdf"), bbox_inches="tight"
)
plt.cla()
plt.clf()
plt.close()
elif png_savename is not None:

if png_savename is not None:
plt.savefig(
os.path.join(output_dir + f"{png_savename}.png"), bbox_inches="tight"
)
plt.cla()
plt.clf()

latex_string += (
f"\\begin{{tabular}}{{{'c' * (len(latex_table[0]) + 1)}}}\n" # +1 for labels
)
for latex_row in latex_table:
latex_string += " & ".join(latex_row) + " \\\\[1ex]" + "\n"

if colorbar_orientation == "horizontal":
latex_string += "\\end{tabular}\\\\\n"
else:
latex_string += "\\end{tabular}\n"
if tex_savename is not None:
latex_string += (
f"\\begin{{tabular}}{{{'c' * (len(latex_table[0]) + 1)}}}\n" # +1 for labels
)
for latex_row in latex_table:
latex_string += " & ".join(latex_row) + " \\\\[1ex]" + "\n"

latex_colorbar_0 = "\\begin{tikzpicture}[baseline=(current bounding box.center)]\\begin{axis}[hide axis,scale only axis,"
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]])})}},"
latex_colorbar_2 = (
f"colorbar horizontal,point meta min={_vmin:.02f},point meta max={_vmax:.02f},"
)
latex_colorbar_3 = "colorbar/width=1.0em"
latex_colorbar_4 = "}] \\addplot[draw=none] {0};\\end{axis}\\end{tikzpicture}"
if colorbar_orientation == "horizontal":
latex_string += "\\end{tabular}\\\\\n"
else:
latex_string += "\\end{tabular}\n"

if colorbar_orientation == "horizontal":
latex_string += (
latex_colorbar_0
+ "width=0sp,height=0sp,colorbar horizontal,colorbar style={width=0.25\linewidth,"
+ latex_colorbar_1
+ latex_colorbar_2
+ latex_colorbar_3
+ ",scaled x ticks=false,xticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
+ f"xlabel={{{_colorbar_value}}},"
+ latex_colorbar_4
latex_colorbar_0 = "\\begin{tikzpicture}[baseline=(current bounding box.center)]\\begin{axis}[hide axis,scale only axis,"
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]])})}},"
latex_colorbar_2 = (
f"colorbar horizontal,point meta min={_vmin:.02f},point meta max={_vmax:.02f},"
)
else:
latex_colorbar_3 = "colorbar/width=1.0em"
latex_colorbar_4 = "}] \\addplot[draw=none] {0};\\end{axis}\\end{tikzpicture}"

if colorbar_orientation == "horizontal":
latex_string += (
latex_colorbar_0
+ "width=0sp,height=0sp,colorbar horizontal,colorbar style={width=0.25\linewidth,"
+ latex_colorbar_1
+ latex_colorbar_2
+ latex_colorbar_3
+ ",scaled x ticks=false,xticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
+ f"xlabel={{{_colorbar_value}}},"
+ latex_colorbar_4
)
else:
latex_string += (
latex_colorbar_0
+ "width=1pt,colorbar right,colorbar style={height=0.25\linewidth,"
+ latex_colorbar_1
+ latex_colorbar_2
+ latex_colorbar_3
+ ",scaled y ticks=false,ylabel style={rotate=180},yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
+ f"ylabel={{{_colorbar_value}}},"
+ latex_colorbar_4
)

latex_string += "\\end{center}\n"
latex_string += (
latex_colorbar_0
+ "width=1pt,colorbar right,colorbar style={height=0.25\linewidth,"
+ latex_colorbar_1
+ latex_colorbar_2
+ latex_colorbar_3
+ ",scaled y ticks=false,ylabel style={rotate=180},yticklabel style={/pgf/number format/fixed,/pgf/number format/precision=3},"
+ f"ylabel={{{_colorbar_value}}},"
+ latex_colorbar_4
"\\caption{[...] \\textbf{"
+ f"{p_value_text}".replace("\n", " ")
+ "} [...]}\n"
)
latex_string += "\\end{table}\n"
latex_string += "\\end{document}\n"

latex_string += "\\end{center}\n"
latex_string += (
"\\caption{[...] \\textbf{"
+ f"{p_value_text}".replace("\n", " ")
+ "} [...]}\n"
)
latex_string += "\\end{table}\n"
latex_string += "\\end{document}\n"

latex_string = latex_string.replace(">", "$>$")
latex_string = latex_string.replace("<", "$<$")

if tex_savename is not None:
latex_string = latex_string.replace(">", "$>$")
latex_string = latex_string.replace("<", "$<$")

with open(
f"{output_dir}/{tex_savename}.tex", "w", encoding="utf8", newline="\n"
) as file:
Expand All @@ -837,3 +834,7 @@ def draw(

if tex_savename is None and pdf_savename is None and png_savename is None:
plt.show()

plt.cla()
plt.clf()
plt.close()
File renamed without changes.
Empty file.
41 changes: 41 additions & 0 deletions multi_comp_matrix/tests/test_mcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from multi_comp_matrix.MCM import compare
import pandas as pd
import tempfile
import time
import pytest

@pytest.mark.parametrize("save_type", ["pdf", "png", "tex"])
def test_all_type_saving(save_type):
"""Test each of the save types."""
data = {
'clf1': [1, 2, 3, 4],
'clf2': [4.0, 6.0, 2.0, 1.0],
'clf3': [10.5, 20.5, 30.5, 40.5]
}
df = pd.DataFrame(data)
with tempfile.TemporaryDirectory() as tmp:
if save_type == "pdf":
curr_time = str(time.time_ns())

compare(df_results=df, output_dir=tmp, pdf_savename=curr_time+"test_pdf")
compare(df_results=df, output_dir=tmp, pdf_savename=curr_time+"test_vertical_pdf",
excluded_col_comparates=["clf1", "clf3"],)
compare(df_results=df, output_dir=tmp, pdf_savename=curr_time+"test_horizontal_pdf",
excluded_row_comparates=["clf1", "clf3"],)
elif save_type == "png":
curr_time = str(time.time_ns())

compare(df_results=df, output_dir=tmp, png_savename=curr_time+"test_png")
compare(df_results=df, output_dir=tmp, png_savename=curr_time+"test_vertical_png",
excluded_col_comparates=["clf1", "clf3"],)
compare(df_results=df, output_dir=tmp, png_savename=curr_time+"test_horizontal_png",
excluded_row_comparates=["clf1", "clf3"],)
elif save_type == "tex":
curr_time = str(time.time_ns())

compare(df_results=df, output_dir=tmp, tex_savename=curr_time+"test_tex")
compare(df_results=df, output_dir=tmp, tex_savename=curr_time+"test_vertical_tex",
excluded_col_comparates=["clf1", "clf3"],)
compare(df_results=df, output_dir=tmp, tex_savename=curr_time+"test_horizontal_tex",
excluded_row_comparates=["clf1", "clf3"],)

File renamed without changes.
77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[build-system]
requires = ["setuptools>61", "wheel", "toml", "build"]
build-backend = "setuptools.build_meta"

[project]
name = "multi_comp_matrix"
version = "0.0.1"
description = " Multi Comparison Matrix: A long term approach to benchmark evaluations "
readme = { file = "README.md", content-type = "text/markdown" }
authors = [
{name = "Ali Ismail-Fawaz", email = "[email protected]"},
{name = "Maxime Devanne", email = "[email protected]"},
{name = "Stefano Berretti", email = "[email protected]"},
{name = "Jonathan Weber", email = "[email protected]"},
{name = "Germain Forestier", email = "[email protected]"}
]
maintainers = [
{name = "Ali Ismail-Fawaz", email = "[email protected]"}
]
requires-python = ">=3.10"
license = {text = "GPL-3.0-only"}

keywords = [
"data-science",
"machine-learning",
"data-mining",
"time-series",
"time-series-analysis",
"time-series-classification",
"time-series-regression",
"time-series-machine-learning",
"benchmarking",
"benchmarking-machine-learning"
]

classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12"
]

dependencies = [
"numpy==1.24.4",
"pandas==2.0.3",
"matplotlib==3.7.4",
"scipy==1.10.0",
"baycomp==1.0",
"tqdm==4.66.1"
]

[project.optional-dependencies]
dev = [
"black",
"flake8",
"mypy",
"pytest",
"pytest-cov",
"pytest-xdist",
"pytest-timeout",
"pytest-rerunfailures",
"pre-commit"
]

[tool.setuptools]
packages = ["multi_comp_matrix"]

[tool.setuptools.package-data]
multi_comp_matrix = [
"*.png",
"*.csv",
"*.pdf",
"*.tex",
]

0 comments on commit ecf3401

Please sign in to comment.