Skip to content

Change dictionary to list of tuples to permit duplicate keys #19666

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

Conversation

PhilipSchiff
Copy link
Contributor

@PhilipSchiff PhilipSchiff commented Mar 8, 2021

PR Summary

As described in #19607, when multiple curves are given the same label, only the first one of each redundant label can be edited in the PyQT backend. This is because the curves and their corresponding labels have been saved in a dictionary. It's possible that a user may have a use case for giving multiple curves the same label, so they should be able to edit them separately as well.

To accommodate this, we modified the dictionary which was saving the labeled curves, replacing it with a list of tuples. The list of tuples is sorted in the same way.

I am not sure how to add the tests for this; so far I just tested it manually creating an instance of NavigationToolbar2QT and giving it redundantly named curves, and verify that they can be edited independently.
There is a test at lib/matplotlib/tests/test_backend_qt.py::test_figureoptions, but all it does is call a mock which will eventually call figureoptions.figure_edit, just creating it without checking the number of curves available to edit, seems insufficient.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a while, please feel free to ping @matplotlib/developers or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@tacaswell tacaswell added this to the v3.5.0 milestone Mar 8, 2021
@tacaswell
Copy link
Member

Have not reviewed this, but am notionally in favor of it 👍

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Testing is really not too easy because figure_edit is monolithic. You could mock/patch _formlayout.fedit and check that it gets the correct datalist. It would be nice, but I'm not 100% insisting on adding a test here.

Comment on lines 62 to 63
if type(label) == tuple:
label = label[0]
Copy link
Member

Choose a reason for hiding this comment

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

This makes the function somewhat awkward. In such a case, you should at least document what label can be.

But checking the code, it turns out that cmp_key() is only used another time for mappabledict. It suffers from the same duplicate label problem and should be changed to a tuple list as well. This will then make the type distinction unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment, I will do it.

@QuLogic QuLogic merged commit a738d78 into matplotlib:master Apr 1, 2021
@QuLogic
Copy link
Member

QuLogic commented Apr 1, 2021

Thanks @PhilipSchiff! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

@PhilipSchiff
Copy link
Contributor Author

Thanks @PhilipSchiff! Congratulations on your first PR to Matplotlib We hope to hear from you again.

Thank you, and thanks Tim for the guidance. I hope to continue as well.

@PhilipSchiff PhilipSchiff deleted the bug_19607_curves_with_same_label_not_appear branch April 4, 2021 02:59
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.

5 participants