Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Bump actions/setup-python from 4 to 5 and fix tests #405

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
shell: bash

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

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/clean-skops-user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
- name: Install Requirements
run: pip install huggingface_hub
- name: run cleanup
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-model-card-creator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/persistence-performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install requirements
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
with:
ref: ${{ github.event.inputs.version }}

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'

Expand Down
2 changes: 1 addition & 1 deletion scripts/clean_skops.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
MAX_AGE = 7 # in days

# This is the token for the skops user. TODO remove eventually, see issue #47
token = "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"
token = "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"
client = HfApi(token=token)
user = client.whoami()["name"]
answer = input(
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[flake8]
max-line-length = 99
enable-extensions = C, G

[tool:pytest]
doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS
9 changes: 1 addition & 8 deletions skops/card/_model_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,7 @@ class Card:
>>> model_card.add(**{"Model description/Model name": "This model is called Bob"})
Card(
model=LogisticRegression(random_state=0, solver='liblinear'),
metadata.license=mit,
Model description=This is the best model,
Model description/Training Procedure/Hyperparameters=TableSection(15x2),
Model description/Training Procedure/...</pre></div></div></div></div></div>,
Model description/Evaluation Results=TableSection(2x2),
Model description/Confusion Matrix=Pl...confusion_matrix.png),
Model description/Model name=This model is called Bob,
A new section=Please rate my model,
...
)
>>> # save the card to a README.md file
>>> model_card.save(tmp_path / "README.md")
Expand Down
48 changes: 21 additions & 27 deletions skops/card/tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ def test_default(self, model_card):
# don't compare whole text, as it's quite long and non-deterministic
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

def test_no_overflow(self, model_card):
result = model_card.select(
Expand Down Expand Up @@ -223,18 +221,14 @@ def test_model_diagram_str(self):
result = model_card.select(other_section_name).format()
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

def test_other_section(self, model_card):
model_card.add_model_plot(section="Other section")
result = model_card.select("Other section").content
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

def test_with_description(self, model_card):
model_card.add_model_plot(description="Awesome diagram below")
Expand All @@ -255,9 +249,7 @@ def test_custom_template_no_section_uses_default(self, template):
# don't compare whole text, as it's quite long and non-deterministic
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

@pytest.mark.parametrize("template", CUSTOM_TEMPLATES)
def test_custom_template_init_str_works(self, template):
Expand All @@ -268,9 +260,7 @@ def test_custom_template_init_str_works(self, template):
result = model_card.select(section_name).format()
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

def test_default_template_and_model_diagram_true(self, model_card):
# setting model_diagram=True should not change anything vs auto with the
Expand All @@ -283,9 +273,7 @@ def test_default_template_and_model_diagram_true(self, model_card):
# don't compare whole text, as it's quite long and non-deterministic
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

@pytest.mark.parametrize("template", CUSTOM_TEMPLATES)
def test_custom_template_and_model_diagram_true_uses_default(
Expand All @@ -301,9 +289,7 @@ def test_custom_template_and_model_diagram_true_uses_default(
# don't compare whole text, as it's quite long and non-deterministic
assert result.startswith("<style>#sk-")
assert "<style>" in result
assert result.endswith(
"<pre>LinearRegression()</pre></div></div></div></div></div>"
)
assert "LinearRegression()" in result

def test_add_twice(self, model_card):
# it's possible to add the section twice, even if it doesn't make a lot
Expand Down Expand Up @@ -1336,7 +1322,7 @@ def expected_lines(self):
Card(
model=LinearRegression(fit_intercept=False),
Model description/Training Procedure/Hyperparameters=TableSection(4x2),
Model description/Training Procedure/...</pre></div></div></div></div></div>,
Model description/Training Procedure/...</div>,
Model Card Authors=Jane Doe,
Figures/ROC=PlotSection(ROC.png),
Figures/Confusion matrix=PlotSection(confusion_matrix.jpg),
Expand All @@ -1352,7 +1338,9 @@ def expected_lines(self):
def test_card_repr(self, card: Card, meth, expected_lines):
result = meth(card)
expected = "\n".join(expected_lines)
assert result == expected
expected = re.escape(expected)
expected = expected.replace(r"\.\.\.", ".*")
assert re.match(expected, result)

@pytest.mark.parametrize("meth", [repr, str])
def test_card_repr_empty_card(self, meth):
Expand All @@ -1378,9 +1366,11 @@ def test_very_long_lines_are_shortened(self, card: Card, meth, expected_lines):
)
expected_lines.insert(-1, extra_line)
expected = "\n".join(expected_lines)
expected = re.escape(expected)
expected = expected.replace(r"\.\.\.", ".*")

result = meth(card)
assert result == expected
assert re.match(expected, result)

@pytest.mark.parametrize("meth", [repr, str])
def test_without_model_attribute(self, card: Card, meth, expected_lines):
Expand All @@ -1389,9 +1379,11 @@ def test_without_model_attribute(self, card: Card, meth, expected_lines):
# remove line 1 from expected results, which corresponds to the model
del expected_lines[1]
expected = "\n".join(expected_lines)
expected = re.escape(expected)
expected = expected.replace(r"\.\.\.", ".*")

result = meth(card)
assert result == expected
assert re.match(expected, result)

@pytest.mark.parametrize("meth", [repr, str])
def test_with_metadata(self, card: Card, meth, expected_lines):
Expand All @@ -1415,9 +1407,11 @@ def test_with_metadata(self, card: Card, meth, expected_lines):
" metadata.widget=[{...}],",
]
expected = "\n".join(expected_lines[:2] + extra_lines + expected_lines[2:])

expected = re.escape(expected)
expected = expected.replace(r"\.\.\.", ".*")
result = meth(card)
assert result == expected

assert re.match(expected, result)


class TestCardModelAttributeIsPath:
Expand Down
2 changes: 1 addition & 1 deletion skops/hub_utils/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This is the token for the skops user on the hub, used for the CI.
HF_HUB_TOKEN = "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"
HF_HUB_TOKEN = "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"