8000 Deprecate non-string values as legend labels by timhoffm · Pull Request #16771 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deprecate non-string values as legend labels #16771

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

Closed
wants to merge 1 commit into from

Conversation

timhoffm
Copy link
Member

PR Summary

Closes #16567.

@timhoffm timhoffm added this to the v3.3.0 milestone Mar 14, 2020
if not isinstance(label, str):
cbook.warn_deprecated(
"3.3",
message="Passing non-string objects as legend "
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a note suggesting that they probably wanted to pass in two lists?

Copy link
Member Author
@timhoffm timhoffm Mar 15, 2020

Choose a reason for hiding this comment

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

I'd rather not. This check is now implemented in Legend with signature Legend(parent, handles, labels, ..). So the "two lists" does not apply anymore. Otherwise I'd have to make the check in mlegend._parse_legend_args(). But then the parameter in Legend is not checked explicitly - was not before, but I think it should anyway. Furthermore, you can pass labels positionally or by kwarg to legend(); while the str-check would apply to both, the proposed addition would only make sense for the former.

On the other hand, IMHO it's clear enough to respond on a call legend(lines) with the message Passing non-string objects as legend labels is deprecated. It's rather obvious from this that we interpret the only parameter as labels.

Copy link
Member

Choose a reason for hiding this comment

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

I suspect that we are still going to get some confused users, but this is certainly clearer than it currently is!

@timhoffm timhoffm force-pushed the legend-labels-str branch from 9b7d171 to 1e1804e Compare March 15, 2020 09:50
@anntzer
Copy link
Contributor
anntzer commented Mar 21, 2020

There are a lot of places where we accept any object and cast them to strings (e.g. titles, xlabels, etc.) Do we want to move all of them to only accept strings for consistency (I would probably support that)? Alternatively, if we want to get rid of the (very real) confusion of users passing artists to legend(), do we just want to deprecate passing Artists to legend() (which is almost certainly a bug), rather than deprecate all non-strs?

@timhoffm
Copy link
Member Author
timhoffm commented Mar 21, 2020

Alternatively, if we want to get rid of the (very real) confusion of users passing artists to legend(), do we just want to deprecate passing Artists to legend() (which is almost certainly a bug), rather than deprecate all non-strs?

Gone with that solution (see #16864). We can defer the decision if we want to have a strict str-checking all over the library.

@timhoffm
Copy link
Member Author
timhoffm commented Apr 1, 2020

Closing in favor of #16864.

@timhoffm timhoffm closed this Apr 1, 2020
@timhoffm timhoffm deleted the legend-labels-str branch April 1, 2020 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Let legend get the handles from the provided objects if not specified explicitly.
3 participants
0