-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
FIX handle aliases in displays when used as default and provided by user #30023
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 handle aliases in displays when used as default and provided by user #30023
Conversation
@glemaitre here the fix for #30015 . I'll wait for review before continuing. |
Thanks. We will need an entry in the changelog for sure. This should solve the CI. You can add it in |
I added the fix for Note: In assert display.line_.get_color() == "black"
assert_allclose(display.scatter_.get_edgecolor(), [[1.0, 0.0, 0.0, 0.8]]) This is supposed to test the default parameters, but since |
I add a quick look at the different displays and I think we will have issue in the following:
In general, it boils down to the same issue due to the aliases:
So I'm thinking that we can make a utility tool in def validate_style_kwargs(default_style_kwargs, user_style_kwargs):
... The job will be to check that the user does not pass two aliases (e.g. Then in each function, we only have to call the utility whenever we want to pass it to the plotting function from matplotlib. In terms of test, we therefore only need to check our small utility function. |
I agree, I'll do that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good. Could you also check the remaining classes for the different kwargs
.
[ | ||
None, | ||
{"linewidth": 1, "color": "red", "linestyle": "-", "label": "DummyEstimator"}, | ||
{"linewidth": 1, "c": "red", "ls": "-", "label": "DummyEstimator"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe lw
here instead of linewidth
Yes |
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
chance_level_line_kw
in display classes
|
Also, I'm not sure in which section of the changelog I should add the changes? Most of them are in
|
On the top of the changelog with have a section called "Changes impacting many modules". I think we can add the entry in this section because as you mentioned, we are touching classes from several modules. |
I'll do a review. I might push a couple of fixes just to make the CI happy first. |
I've just made the changes @glemaitre What is missing for the CI to pass? I use the pre-commit hook on my side but it still seems to have linting problems. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the last change is done, everything looks good to me.
Thanks @JosephBARBIERDARNAL.
We will need to get a second review to get this one in. Let me ping maybe @lucyleeow or @Charlie-XIAO
Co-authored-by: Guillaume Lemaitre <guillaume@probabl.ai>
Perfect, thanks for the prompt reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JosephBARBIERDARNAL this PR looks mostly good to me! Just a few questions/comments:
Matplotlib style kwargs. | ||
""" | ||
|
||
invalid_to_valid_kw = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May I know where this mapping came from? I searched in the matplotlib source code where they used their define_aliases
decorator, and there seems to be many more that we missed here (though maybe not all of them are related here).
https://github.com/search?q=repo%3Amatplotlib%2Fmatplotlib+define_aliases&type=code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I made it myself, more or less arbitrarily. But since matplotlib has a clearly defined list of aliases, maybe let's just put the entire list instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed. We could even import it because we expect to have matplotlib installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a quick check, and I'm not sure how to import it in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I could not find a non-private way of getting them. So I would define the list such that in account for the keys/values of the matplotlib artist that we are using.
FYI, our function is close to this function (https://github.com/matplotlib/matplotlib/blob/v3.9.2/lib/matplotlib/cbook.py#L1795-L1848) when it comes to matplotlib itself. No need to try using it thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I've added all the aliases, except for those used for 3D plotting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @JosephBARBIERDARNAL
Co-authored-by: Yao Xiao <108576690+Charlie-XIAO@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Charlie-XIAO do you want to have another look?
Matplotlib style kwargs. | ||
""" | ||
|
||
invalid_to_valid_kw = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @JosephBARBIERDARNAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @JosephBARBIERDARNAL! There's just a small typo:
Co-authored-by: Yao Xiao <108576690+Charlie-XIAO@users.noreply.github.com>
We just change the way that we add entry into the changelog. Let me make the change and push it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the fragment in the changelog. Enabling the auto-merge then.
Thanks @JosephBARBIERDARNAL. Nice contribution.
Thanks! This is my very first merged PR, and it's been a really good experience. |
Reference Issue
closes #30015
What does this implement/fix?
Bug summary
When passing additional keyword arguments to the random classifier's line via the
chance_level_kw
argument, some arguments raise an error even though they are validmatplotlib.pyplot.plot()
arguments. The error occurs with thec
andls
arguments.The reason is that in
scikit-learn/sklearn/metrics/_plot/roc_curve.py
, the following code exists:Matplotlib raises an error when both
color
andc
, orlinestyle
andls
are specified (this happens with other arguments too, but these are not relevant here since scikit-learn does not set values for them).Solution TLDR
If the user supplies
ls
orc
,linestyle
andcolor
are overwritten with user inputs, andls
andc
are removed fromchance_level_kw
.I've added a test for these specific cases.
Any other comments?
At the moment, it only fixes the
RocCurveDisplay
class. I need to investigate what other classes have the same reproducible bug.