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

MAINT Small refactor: figure_paths -> extra_sections #89

Merged

Conversation

BenjaminBossan
Copy link
Collaborator

Functionally, nothing changed, this is just a renaming and a little
cleanup.

The reason is that this attribute can be used for more than just
figures, so a more generic name is a better fit. The name
extra_sections was chosen to mirror the template_sections.

Apart from renaming and adjusting some comments based on that, there
was a small change in which the items of the dict are accessed, making it
more efficient, and merging to f-strings into one.

Functionally, nothing changed, this is just a renaming and a little
cleanup.

The reason is that this attribute can be used for more than just
figures, so a more generic name is a better fit. The name
"extra_sections" was chosen to mirror the "template_sections".

Apart from renaming and adjusting some comments based on that, there was
a small change in which the items of the dict are accessed, making it
more efficient, and merging to f-strings into one.
@BenjaminBossan
Copy link
Collaborator Author

Ready for review @skops-dev/maintainers

@adrinjalali adrinjalali merged commit b17249e into skops-dev:main Aug 10, 2022
BenjaminBossan added a commit to BenjaminBossan/skops that referenced this pull request Aug 10, 2022
Solves skops-dev#87

This feature adds a new method to the Card class called add_table. It
adds a generic table to the end of the model card by creating a new
section (similar to plots).

Any generic table of type dict[str, list[Any]] is supported, as well as
DataFrames. However, the main use case is for adding CV results, as e.g.
created by GridSearchCV.

Implementation

I hope you can stomach the type-y implementation Adrin ;)

I wanted to make the extra sections more generic in PR skops-dev#89 as a
preparation for this PR (thus avoiding a big PR with refactor + new
feature). However, the changes in skops-dev#89 were not sufficient (I guess
that's the danger of splitting the work).

The problem was that the formatting of adding the plots in the save
method was very specific to plots, as a markdown link would be added.
This, of course, does not work for tables.

My solution is that _extra_sections now takes ExtraSection objects as
values instead of strings. These objects only need to implement the
format method (so technically, str would still be okay). So for a
plot, the PlotSection class has a format method that returns a markdown
link. And for tables, the TableSection class has a format method that
uses tabulate to return a table as string.

This approach should hopefully be flexible enough for us to later add
new section types if needed.

At first glance, the implementation might look overly complex. However,
I think it's better than having a bunch of if...else inside of save that
formats each possible type differently. But please LMK if you have a
better idea, I'm open to suggestions.

Examples

Here is the hyperparameter table generated by plot_model_card.py:

https://huggingface.co/skops/hf_hub_example-b959cadc-ffb3-4f07-856b-2d05d2d8f8e0#hyperparameter-search-results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants