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

Fix type hints #255

Merged
merged 34 commits into from
Sep 5, 2023
Merged

Fix type hints #255

merged 34 commits into from
Sep 5, 2023

Conversation

ecomodeller
Copy link
Member

@ecomodeller ecomodeller commented Aug 29, 2023

which in some cases, means removing the type hints or muting it with # type : ignore.

@ecomodeller
Copy link
Member Author

modelskill.comparison module ✅

$ mypy modelskill/comparison/
Success: no issues found in 6 source files

@ecomodeller ecomodeller changed the title Fix some types Fix type hints Aug 31, 2023
@ecomodeller
Copy link
Member Author

$ mypy modelskill/
Success: no issues found in 29 source files

Which translates to no unknown issues, there are still plenty of lines with a #type: ignore, but at least they are clearly marked.

This PR allows us to use type hints with more confidence, since future changes can be verified with mypy in absence of a compiler to check static type information.

@ecomodeller ecomodeller marked this pull request as ready for review August 31, 2023 14:19
Copy link
Member

@jsmariegaard jsmariegaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the tests are failing but I went through the changes anyway - here are my comments

@@ -20,7 +20,7 @@ def scatter(
self,
*,
model=None,
bins: Union[int, float, List[int], List[float]] = 20,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these removed - matplotlib allows to give edges as a list - (actually str also works) https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were no tests with bins as a list of values. And when I tried it failed to produce a scatter plot☹️

The type hints should reflect working functionality (== tested).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniel-caichac-DHI can you help here - are the bins as a list of edges needed?

Copy link
Collaborator

@daniel-caichac-DHI daniel-caichac-DHI Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to have automatic bins but sometimes someone might want to reproduce an old plot or a plot with given bins (eg, bins that are not equidistant, logarithmic bins (for whatever reason?)
I'll try to see if if works with bins= list of values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess also when you want consistent plots with the same bins across many plots?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TRUE

def scatter(
self,
*,
model=None,
bins: Union[int, float, List[int], List[float]] = 20,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above - and actually "float" is not allowed?? https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix this in a separate PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by: Union[str, List[str]] = None,
metrics: list = None,
by: Optional[Union[str, List[str]]] = None,
metrics: Optional[list] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allow Sequence?

# TODO does this work as intended? Mutable default values, e.g. dict, list, are usually not recommended
register_option(
key="plot.rcParams", defval={}, validator=settings.is_dict
) # still have to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...to what?


if not isinstance(quantiles, (int, Sequence)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed this - but what if quantiles is float or str?

Copy link
Member

@jsmariegaard jsmariegaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@ecomodeller ecomodeller merged commit 8ce01d9 into main Sep 5, 2023
@ecomodeller ecomodeller deleted the mypy_items branch September 5, 2023 05:53
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.

3 participants