Skip to content

Raises ValueError on unequal lengths of labels and handles input #24063

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 5 commits into from

Conversation

grgkaran03
Copy link
Contributor

@grgkaran03 grgkaran03 commented Oct 1, 2022

…_args

PR Summary

Verifying that the inputs are of a consistent length in _parse_legend_args.
Number of elements in handles and labels should be equal, addressing the issue #24050 .

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).

@grgkaran03
Copy link
Contributor Author

@QuLogic, please review the changes...
Also, how do I overcome these failing tests?

@oscargus
Copy link
Member

oscargus commented Oct 1, 2022

The failing tests are not related to your PR. However, your PR would need a test that checks that the exception is raised. This should probably go into https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/tests/test_legend.py

Here is a similar test to see how to check for an exception:

def test_legend_positional_handles_only(self):
lines = plt.plot(range(10))
with pytest.raises(TypeError, match='but found an Artist'):
# a single arg is interpreted as labels
# it's a common error to just pass handles
plt.legend(lines)

(Also, note that #24061 solves the same issue.)

@jklymak
Copy link
Member

jklymak commented Oct 1, 2022

I'll close this as a duplicate. We can reopen if the other PR does not go through. Feel free to contribute to the ongoing PR

@jklymak jklymak closed this Oct 1, 2022
@grgkaran03
Copy link
Contributor Author

@jklymak I tried adding a test for raising a ValueError, do open this if the other one does not go through 👍

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.

3 participants