8000 FIX: legend handler warning too liberal by jklymak · Pull Request #23762 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: legend handler warning too liberal #23762

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

Merged
merged 1 commit into from
Aug 28, 2022

Conversation

jklymak
Copy link
Member
@jklymak jklymak commented Aug 27, 2022

PR Summary

Closes #23761

The check is not supposed to warn if an artist has no label or a '_no_legend_' label. However we actually add labels to lots of artists, and we don't deal with labels with leading underscores anyway, so just skip anything with a leading underscore.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Aug 27, 2022
@jklymak jklymak added this to the v3.6.0 milestone Aug 27, 2022
# this should _not_ warn:
f, ax = plt.subplots()
ax.pcolormesh(np.random.uniform(0, 1, (10, 10)))
ax.get_legend_handles_labels()
Copy link

Choose a reason for hiding this comment

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

Do you need to be recording the warnings on this line?

Copy link
Member

Choose a reason for hiding this comment

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

The PR is correct, see https://stackoverflow.com/a/45671804

Copy link
@mwaskom mwaskom Aug 28, 2022

Choose a reason for hiding this comment

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

@timhoffm I think you're commenting on an outdated review, the previous version had no assertions at all.

@@ -1140,7 +1140,7 @@ def _get_legend_handles(axs, legend_handler_map=None):
label = handle.get_label()
if label != '_nolegend_' and has_handler(handler_map, handle):
yield handle
elif (label not in ['_nolegend_', ''] and
elif (label != '' and label[0] != '_' and
Copy link
Member

Choose a reason for hiding this comment

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

It may make sense to create a function _is_active_label(label) or something. For comparsion, see line 1160 below where the same condition is written completely different.

But for 3.6 this is probably OK.

Copy link

Choose a reason for hiding this comment

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

Could you simplify this by writing not label.startwith('_')?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied the code below, which is indeed identical... (had to check if an empty string was indeed False)

@jklymak jklymak force-pushed the fix-legend-warning branch from 17482b7 to 7805ac8 Compare August 28, 2022 15:44
@tacaswell
Copy link
Member

anyone can merged on green.

@tacaswell tacaswell merged commit 07af522 into matplotlib:main Aug 28, 2022
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Aug 28, 2022
@jklymak jklymak deleted the fix-legend-warning branch August 28, 2022 19:42
jklymak added a commit that referenced this pull request Aug 28, 2022
…762-on-v3.6.x

Backport PR #23762 on branch v3.6.x (FIX: legend handler warning too liberal)
@mwaskom
Copy link
mwaskom commented Sep 5, 2022

I'm curious why this didn't end up in the 3.6.0rc1 release? (https://github.com/matplotlib/matplotlib/blob/v3.6.0rc1/lib/matplotlib/legend.py#L1143)

@QuLogic
Copy link
Member
QuLogic commented Sep 6, 2022

Because 3.6.0rc1 came out before this was even opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: False positive legend handler warnings in 3.6.0.rc1
6 participants
0