FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Suppresses failed test case by excepting TypeError from _initialize_x_y by TianzeMYou · Pull Request #24698 · matplotlib/matplotlib · GitHub

Repository navigation

Suppresses failed test case by excepting TypeError from _initialize_x_y - #24698

Closed
TianzeMYou wants to merge 1 commit into
matplotlib:mainfrom
TianzeMYou:uniform-field-contour-colorbar
Closed

TianzeMYou wants to merge 1 commit into
matplotlib:mainfrom
TianzeMYou:uniform-field-contour-colorbar

Conversation

TianzeMYou commented Dec 12, 2022 •
edited
Loading

Copy link
Copy Markdown

PR Summary

The original code for reproduction of this issue #23817 is

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
cs = ax.contour([[1, 1], [1, 1]])
fig.colorbar(cs, ax=ax)
plt.show()

However, this seems to yield the following TypeError
TypeError: Input z must be 2D, not 1D

The same TypeError also occurs if we change

cs = ax.contour([[1, 1], [1, 1]])

to

cs = ax.contour([[1, 2], [3, 4]])

This TypeError is resulted from lib/matplotlib/contour.py, line 1526, in _initialize_x_y, which makes me think that rather than a colorbar problem, the root of this issue lies in how contour works. What is the expected behavior of the original code for reproduction? If we aren't supposed to call Fontour on input like above in the first place, how is Colorbar supposed to behave and why does the the API warning even matter?

I was able to suppress the failed test case with the following change to @quinnah's test case from #24656

def test_contour_uniformfield_colorbar():
    # Smoke test for issue
    fig, ax = plt.subplots()
    with pytest.warns(Warning) as record:
        cs = ax.contour([[2, 2], [2, 2]])
    assert len(record) == 1
    try:
        fig.colorbar(cs, ax=ax)
    except:
        pass

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

TianzeMYou marked this pull request as draft December 12, 2022 02:47

github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

y = y / (self._boundaries[self._inside][-1] -
self._boundaries[self._inside][0])

# original

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please do not keep the original code around. Because the code is in git and there are a number of UIs (inculding this website) for viewing the diffs it is much clearer to simply remove the old code and replace it with the new code. If we kept the full history of Matplotib in-line like this it would very quickly become impossible to read!

cs = ax.contour([[2, 2], [2, 2]])
assert len(record) == 1
try:
fig.colorbar(cs, ax=ax)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is this in a try-except?

# self._boundaries[self._inside][0])

# change
if (self._boundaries[self._inside][-1]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

does this need an else branch?

Copy link
Copy Markdown
Member

👋🏻 Hi @TianzeMYou - gentle ping that you have a pending review on this PR, are you still interested in working on it? If you need help, please let us know. Cheers!

timhoffm commented Feb 2, 2025

Copy link
Copy Markdown
Member

The issue has been solved through another fix.

timhoffm closed this Feb 2, 2025
melissawm moved this from Waiting for author to Done in First Time Contributors Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL